Code Error

-Gary

New Member
A few years ago I made this solenoid engine. The operation uses a Hall effect sensor to fire a transistor (TIP 105) to switch on the solenoid current. It stays on for about 30 degrees of flywheel rotation and shuts off the transistor. Max speed @ 9vdc is about 180-200 rpm. Here is a link to the video of it:

https://www.youtube.com/watch?v=RPFceY0Ifqc

I want to use 08 Proto board with a 08M2+ chip to control the time the solenoid is activated. It is wired up but my program needs some work. Here is my code:
Code:
'Solenoid Engine

'** Directives
#picaxe 08m2		'08m2 Chip
#com 3			'Com Port
#no_data		'No data Download

input C.1		'Input from Hall Sensor
output C.2		'Output to Transistor
setint %00000001,%00000010,C

main:
low C.1
pause 15
goto main

interrupt:
if pinC.1 = 1 then interrupt
	high C.2
	pause 250
	low C.2
setint %00000001,%00000010,C
return
Here is the schematic that I have:
Solenoid.jpg

Running this program, the transistor is switched on by the Hall effect sensor which pulls the solenoid rod in. But it never turns off the transistor. I suspect the error is how the interrupt is coded but I am not sure where to change it. I read the Manual and looked for examples to compare but the erreo still exists. Can anyone point me in a different direction to try? Thanks for any help!
 

hippy

Technical Support
Staff member
Is there a misalingment in your setint ... ?

Code:
;          bit 0    bit 1
;       :::::::|  ::::::|:
setint %00000001,%00000010,C
 

westaust55

Moderator
Also, you want C.1 as an input but the first line in the main loop
LOW C.1
Changes the input to an output.
It is never returned to being an input so never activates again.

If fact could result in damage to the PICAXE chip if the C.1 pin is made low and the actual incoming signal is high.
Potentially being saved by a high impedance/resistance in the input circuit.

Should that be
LOW C.2
And put before the Main: label?

Finally looking at your diagram
1. it has the notations and wiring for C.1 as the output and C.2 as the input?
Again at odds with the code.
2. The serial input pin is left floating (physical leg 2 on the IC). That needs to be held low before the PICAXE will run the program properly. Best if not having a full programming circuit is a 10k resistor to 0 Volts.
 
Last edited:

-Gary

New Member
Many thanks westaust55!
I certainly made a mess of that programming attempt :(
I checked my chip with some LED's and got lucky as it is ok. No damage this time. The chip is on a 08 Proto board so all the needed connections are there.
All the changes in code are made to match the wiring diagram. I now see how I need the LOW C.2 before the Main: label

Well, here is my current code:
Code:
'Solenoid Engine

'** Directives
#picaxe 08m2		'08m2 Chip
#com 3			'Com Port
#no_data			'No data Download

output C.1			'Output to Transistor
input C.2			'Signal from Hall Sensor

setint %00000001,%00000010,C
low C.2

main:
pause 15
goto main

interrupt:
if pinC.2 = 1 then interrupt
	high C.1
	pause 250		'adjust for solenoid timing
	low C.1
setint %00000001,%00000010,C
return
I must look at what I have tomorrow as there is no code in the Main:
I will work on it some more.

Also thanks hippy! There is some work needed on the interrupt code. I will read some more.
 

westaust55

Moderator
You will likely need to pulse the solenoid a few times initially to get the motor turning unless you start by hand spinning.
Otherwise there is no rotation for the sensor to pick up and keep giving "kicks".

Having nothing in the main loop is okay for this project.
 
Top