malfunction of programme

timm

New Member
My programme works in simulation but does not when downloaded onto a picaxe 18m2. The wiring connections are all checked and double checked. The programme turns a 12v motor on and off depending on number of revs determined by magnet passing reed switch. A fairly simple on of code works but once I add a "let b0=b0+1" it does not seem to respond to that bit of the code (but the simulation works). Could the chip be faulty? Thanks for any help.
 

Technoman

Senior Member
Please give more informations like the piece of code an the circuit diagram. Otherwise, it's like looking into a crystal ball.
 

premelec

Senior Member
Not likely chip faulty... please post schematic and code... sometimes there is a reset glitch from motor turn ons; so try putting code at start of program that will let you know if a restart has happened..
 

timm

New Member
Not likely chip faulty... please post schematic and code... sometimes there is a reset glitch from motor turn ons; so try putting code at start of program that will let you know if a restart has happened..
Thanks here is the code and circuit attached:
symbol encdr = pinC.0 ;b0 (reed switch)
symbol motor = B.1

init: let b0 = 0

main: high B.1
pause 2000 (to allow magnet to move away from reed switch when motor starts)
goto add

add: let b0 = b0 + 1
if b0 < 10 then add
low B.1
 

Attachments

hippy

Technical Support
Staff member
Thanks here is the code...
It seems some of the code may be missing as it never reads the 'encdr ' reed switch input.

The code starts, the motor is set high, two seconds later it quickly increments b0 to 10, and then sets the motor low.
 

stan74

Senior Member
main: high B.1
pause 2000 (to allow magnet to move away from reed switch when motor starts)
goto add???? next line is add anyway

add: let b0 = b0 + 1
if b0 < 10 then add ?? goto add? this just incs b0 until it's 10. why?
low B.1
 

westaust55

Moderator
Your code as posted will perform one pass.
The motor will start and after 2 seconds the variable be be incremented 10 times which will take about 2.5 milliseconds.
Then the output for motor is stopped. And the program is finished.

Can you explain precisely, as a series of steps,what you are wishing to achieve and folks here can help you achieve working code.
 

timm

New Member
Thank you for your help.

Your comment about the variable incrementing is interesting I had assumed that it would only increment once on each input from the reed switch.

I have 3 magnets on the output shaft of the geared motor (5rpm) equally spaced at 120deg. When 12v is turned on I want the shaft to turn 1/3rd of a turn. The b0<10 I had in the code was just for trial purposes so the 10 needs to be replaced with a suitable number. As the motor will stop with a magnet adjacent to the reed switch I put the pause in to allow it to move past the switch before C.0 started counting. Basically I want the motor to turn until the next magnet initiates the reed switch.
 

hippy

Technical Support
Staff member
It seems you might want something like ...

Code:
symbol encdr = pinC.0 ; reed switch
symbol motor = B.1

main:  high B.1
       pause 2000

check: if encdr = 1 then check

       low B.1
This will start the motor, let the magnet move away from the reed switch, then stop it when the next magnet activates the switch.

You might need to change 'encdr = 1' to 'encdr = 0'.
 

westaust55

Moderator
You will need to perform a test of pin C.0 to detect the when the reed switch is closed.

For example:

Code:
Add:
    If pinC.0 = 0 then add ; loop until the input is high
    B0 = b0 + 1
Isitlow: 
    If pinC.0 = 1 then isitlow ; wait until input changes state
    If b0 < 10 then add ; loop until 10 pulses detected
    Low B.1
Next you need to consider what is to happen once the motor has stopped.
What will cause it to restart?
 

timm

New Member
Sorry I have been away. Thanks Hippy I put in your code and it performed as wanted i.e. turned until the next magnet activated the reed switch and then stopped. I am initiating the start with a standard 24hr timer from the mains switching a relay to turn on the 12v supply from a battery. I am quite confused as I modified my golf trolley to provide distance control by counting the passes of a magnet on the axle passing a reed switch using the b0=b0+1 and it seems to work perfectly much to everyone's astonishment on the course when they see the trolley trundling along with no one in attendance.
 
Top