DDDvvv
- 19th January 2010, 17:28
hi everyone,
i have the pic18fxx31 datasheet all printed out and bound into a book, and i read it every spare time i can get.
so the other day, i was looking at the power control module (page 181) and started thinking about how to drive a stepper with it. i looked closely at the pwm output override section, (page 202), and an idea hit me. use the OVDCOND register to determine which pwm output pins turn on, irrespective of the duty cycle. in short, on/off control of any pwm pin, AND 14-bit duty cycle control of any pwm output pin AT THE SAME TIME.
i tried it with this simple code and it works on a stepper and leds, in my QL200 dev board
main
ADCIN 0, DUTY_ADJ ;read value on pot
DUTY = DUTY_ADJ*64 ;bring up 8 bit adc value to 14 bit duty value
PDC0L = Duty.LowByte ;load duty value into duty registers
PDC0H = Duty.HighByte ;
PDC1L = DUTY.LOWBYTE ;
PDC1H = DUTY.HIGHBYTE ;
PDC2L = Duty.LowByte ;
PDC2H = Duty.HighByte ;
PDC3L = DUTY.LOWBYTE ;
PDC3H = DUTY.HIGHBYTE ;
OVDCOND = %10000000 ;use override control to switch pwm pins
PAUSE 10 ;pause
OVDCOND = %00100000 ;
PAUSE 10 ;
OVDCOND = %00001000 ;
PAUSE 10 ;
OVDCOND = %00000010 ;
pause 10 ;
goto main ;loop
stepper power is controlled by the value of the duty cycle. in this example, all the duty registers have the same value (from the adcin 0),but its possible to have different duty cycles.
for the 18f4431, you get four individual duty cycle control, thus perfect compatibility with a stepper motor. im highly interested in motor control for cnc applications. i would really appreciate all the help i can get, to implement into this idea:
ramping up/down ideas
current limiting by varying the duty cycle
current feedback
any other stepper optimization technology/ideas
thanks for reading.
i have the pic18fxx31 datasheet all printed out and bound into a book, and i read it every spare time i can get.
so the other day, i was looking at the power control module (page 181) and started thinking about how to drive a stepper with it. i looked closely at the pwm output override section, (page 202), and an idea hit me. use the OVDCOND register to determine which pwm output pins turn on, irrespective of the duty cycle. in short, on/off control of any pwm pin, AND 14-bit duty cycle control of any pwm output pin AT THE SAME TIME.
i tried it with this simple code and it works on a stepper and leds, in my QL200 dev board
main
ADCIN 0, DUTY_ADJ ;read value on pot
DUTY = DUTY_ADJ*64 ;bring up 8 bit adc value to 14 bit duty value
PDC0L = Duty.LowByte ;load duty value into duty registers
PDC0H = Duty.HighByte ;
PDC1L = DUTY.LOWBYTE ;
PDC1H = DUTY.HIGHBYTE ;
PDC2L = Duty.LowByte ;
PDC2H = Duty.HighByte ;
PDC3L = DUTY.LOWBYTE ;
PDC3H = DUTY.HIGHBYTE ;
OVDCOND = %10000000 ;use override control to switch pwm pins
PAUSE 10 ;pause
OVDCOND = %00100000 ;
PAUSE 10 ;
OVDCOND = %00001000 ;
PAUSE 10 ;
OVDCOND = %00000010 ;
pause 10 ;
goto main ;loop
stepper power is controlled by the value of the duty cycle. in this example, all the duty registers have the same value (from the adcin 0),but its possible to have different duty cycles.
for the 18f4431, you get four individual duty cycle control, thus perfect compatibility with a stepper motor. im highly interested in motor control for cnc applications. i would really appreciate all the help i can get, to implement into this idea:
ramping up/down ideas
current limiting by varying the duty cycle
current feedback
any other stepper optimization technology/ideas
thanks for reading.