PDA

View Full Version : how can i toggle an output as long as an input pin is pulsing at a lower rate?



EDWARD
- 3rd June 2005, 09:43
I am tring to run a chunk of code over and over as long as the portb.0 input pin is toggling from low to high. here my code i need to continuosly cycle as long as portb.0 is toggling at least 1 per 100 miliseconds, but i cant have a 100 ms pause in th cycling chunk f code below.

"while portb.0 is toggling atleast 1/100ms then"<-main idea, not actual code

for x = 1 to 10 + D '<----here
PULSOUT portc.2,50 '
next '

pause T '<----to here

"wend" <- not actual code


i need something similar to the COUNT command but doesnt pause while taking its readings

this is the same pcb ive been working on. i have a solenoid on portc.2. it has to be controlled a really strange way but it works just fine 100% good. you can think the the 3 line, FOR..NEXT statement as the equivilent of HIGH portc.2. then there is the pause command which holds portc.2 low for a specified amount of time. the solenoid is turning on and off repeatedly. i need this 4 line chunk of code to run while portb.0 is going low to high to low to high..etc. this wouldnt be so hard if the input was faster then the out put, in my mind at least.

Dave
- 3rd June 2005, 12:17
EDWARD, This is one way to do what you need too:

loop:
if portb.0 <> state then 'reset counter whenever state changes
state = portb.0
cntr = 0
endif
cntr = cntr + 1
if cntr < 2000 then 'set for number of pass thru your output loop

for x = 1 to 10 + D '<----here
PULSOUT portc.2,50 '
next '

pause T '<----to here

else
'do something else
endif

goto loop

HTH,
Dave Purola,
N8NTA