PDA

View Full Version : Accurate ticks generation



Thardin
- 22nd May 2010, 21:20
Hello everyone
I am new to picbasic pro and and have a question about the following code.
I am using this code to drive a stepper motor in a clock. I'm trying to pulse it 26.67 times a second which will pulse the stepper 1600 a min.
if I use 38 in the pause routine I end up with 26.204 and the clock runs slow and 39 gives me 26.915 and the clock is fast.

I sure there is a simple way to get the 26.67 but I'm not sure of how to do it.
Any suggestions would be greatly appreciated.

output portb.1
output portb.0
input portb.2
output portb.7
output portb.6

high 1 'set direction
high 6 'microstep
high 7 '" "

mainloop:
High 0 'pulse train on pin 0 26.204 cycles a second
Pause 19
Low 0
Pause 19

if portb.2 = 0 then ' check button
goto sub1 ' if down go to sub1
endif



Goto mainloop


sub1: low 6 'full step
low 7 '" "
High 0 'pulse train on pin 0 to speed up motor to set
pause 1 'time
low 0
pause 1

if portb.2 = 0 then ' check if button is still down
goto sub1 ' if not go to mainloop
endif

pause 1000
goto mainloop

end

Thardin
- 23rd May 2010, 00:15
I just found the PAUSEUS command, so it should be easy enough to work out the math now

Thanks

Acetronics2
- 23rd May 2010, 10:45
Hi, Thardin

Did you had a look here, for " ticks" generation ???

http://www.picbasic.co.uk/forum/content.php?r=160

Alain

Thardin
- 24th May 2010, 01:36
Thanks Alain
I got my clock working but the information you suggested is very interesting.

Todd