donrecardo
Senior Member
Hi
I need to measure how far my model train has travelled each time it goes out for a run.
I know that every 55 turns of the wheels equals 1/100th of a mile travelled so I planned on using a slotted opto detector with schmidt output ( I had one in my parts box) to sit over a disk attached to an axle giving me one output per revolution of the axle .
I tried this code in the simulator
It seemed to work fine on the simulator but then I found out that the slotted opto detector doesnt sit at 0v and go up to 5v on output, its reversed , it sits at 5v and when triggered goes low.
I didnt think that should be a problem and just changed the setint to
%00000100, 00000000 ,expecting it to interrupt when pin 2 goes low and I changed intwait: to look for 0 rather than 1 but for some reason that didnt work
what am I doing wrong ? and is interupt the best way to go in this instance ?
Incase speed may be an issue as to choosing wether or not to use interrupt , the trigger from the opto detector will never be more than 15Hz and most times would be around 6 Hz
Regards
Don
I need to measure how far my model train has travelled each time it goes out for a run.
I know that every 55 turns of the wheels equals 1/100th of a mile travelled so I planned on using a slotted opto detector with schmidt output ( I had one in my parts box) to sit over a disk attached to an axle giving me one output per revolution of the axle .
I tried this code in the simulator
Code:
b0=0 ' initializes the variable holding revolutions made
b1=0 ' initializes the variable which eventually will be the output display
setint %00000100, %00000100 'Interrupt when input 2 goes high , ( detector gets triggered)
idle: 'A loop to sit in waiting for the interrupt
goto idle
interrupt:
b0 = b0 + 1 'Wheel has turned once so add one to the counter
if b0 = 55 then ' has it turned 55 times ? ( train travelled 1/100th of a mile)
goto display 'if so add one to the output display
endif
intwait: ' a routine so that if the train just happens to stop with the
' disk blocking the detector it wont keep on incrementing b0
'input 2 must go low before another increment of b0 can occur
if pin2 = 1 then intwait ' loop if disk has not yet cleared detector
setint %00000100, %00000100
return
display:
b1=b1+1 ' here while using the debug screen I use b1 as the diplay of
' 1/100ths of a mile completed . the finished job will use an
' electromagnetic counter
b0=0 ' get b0 ready to start counting another set of 55
setint %00000100, %00000100
goto intwait ' Same as before , to stop repeat if disk has parked blocking detector
I didnt think that should be a problem and just changed the setint to
%00000100, 00000000 ,expecting it to interrupt when pin 2 goes low and I changed intwait: to look for 0 rather than 1 but for some reason that didnt work
what am I doing wrong ? and is interupt the best way to go in this instance ?
Incase speed may be an issue as to choosing wether or not to use interrupt , the trigger from the opto detector will never be more than 15Hz and most times would be around 6 Hz
Regards
Don
Last edited: