More than one clock output from the PIC - Page 1
Forum section: electronics / general

author: Technician
author_rank: Newbie
timestamp: February 26, 2013, 10:52:53 am
content: Hello !I need to send clock signal (in this case at least two clock signals) from a PIC to L297 stepper motor driver. Now, with one motor driven at a time there is no problem, but I will probably need more than that. Clock send to L297, as you know, determines speed of the stepper, e.g. number of steps in time. Problem is that I would need more than one clock signal from the PIC, different frequencies, of course.Currently, I am using 16F877 but I am not sure that I can do it with this controller. Any recommendation would be helpful.Tahnk you,Tomislav

author: Rerouter
author_rank: Super Contributor
timestamp: February 26, 2013, 11:06:57 am
content: are you actually using a clock signal, or simply having your pic produce step pulses? if just pulses, then you could simply set up both ports into a while loop say 1024 cycles, and add a little basic math so each triggers after a certain increment of cycles e.g. 220, 440, 660, 880, 75, 295, similar to the improved arduino pwm method, (should be quite easy to directly translate into pic C)IF n>1023n = n-1023Else n + 220as a rough outlier,

author: Technician
author_rank: Newbie
timestamp: February 26, 2013, 11:17:34 am
content: Quote from: Rerouter on February 26, 2013, 11:06:57 amThanks for reply.Actually, I am generating clock which is then send to L297 decoder. L297 then translates clock signal, direction signal and half/full step signal (later three are one bit signals). Clock determines how fast are decoded step signals delivered to the driver stage. So, yes I am sending clock (more than one of them). L297 has built in chopper so it is excellent for stepper pulse generating and getting maximum from the stepper.Tomislav

author: SebG
author_rank: Regular Contributor
timestamp: March 13, 2013, 10:15:02 pm
content: HiYou can setup a Timer to generate an interrupt periodically. For example you can setup Timer 2 to generate an interrupt say every 1ms or 0.1 ms (or any value of your choosing) by setting it's pre- and post-scalers and PR2 register (PR2 is compared to the Timer2 and generates an interrupt both are equal). Each time an interrupt occurs you can increment a register for each clock that you want. Then you compare it to a frequency you want to toggle your output and if a match occurs (still within the interrupt) you toggle an output pin and reset your register (the one that is periodically incremented). While out of the interrupt service routine you can dynamically adjust the desired frequency you want.The only down side is that the period of your desired frequency will be a multiple of the 2*period of the interrupt event.For example, if you interrupt occurs every 1ms (that toggles your output) then the period of your frequency will be in 2ms steps (1 period is low and high so 2 toggles)So your maximum frequency is 1/2ms = 500Hz and minimum frequency using 8-bit register to keep track of the number of interrupts events is 1/(2ms * 255) = 1.96Hz. If say you want a frequency of 100Hz then you need the interrupt to be generated 5 times, ie 100Hz = 1 / (0.002 * N) where N = 5.