Author Topic: More than one clock output from the PIC  (Read 2957 times)

0 Members and 1 Guest are viewing this topic.

Offline TechnicianTopic starter

  • Newbie
  • Posts: 3
  • Country: hr
More than one clock output from the PIC
« on: February 26, 2013, 10:52:53 am »
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
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: More than one clock output from the PIC
« Reply #1 on: February 26, 2013, 11:06:57 am »
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>1023
n = n-1023
Else n + 220

as a rough outlier,
 

Offline TechnicianTopic starter

  • Newbie
  • Posts: 3
  • Country: hr
Re: More than one clock output from the PIC
« Reply #2 on: February 26, 2013, 11:17:34 am »
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>1023
n = n-1023
Else n + 220

as a rough outlier,

Thanks 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





 

Offline SebG

  • Regular Contributor
  • *
  • Posts: 66
  • Country: ca
  • Currently looking for an EE Job
Re: More than one clock output from the PIC
« Reply #3 on: March 13, 2013, 10:15:02 pm »
Hi
You 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.
« Last Edit: March 13, 2013, 10:20:08 pm by SebG »
Sebastian
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf