![]() Long new_phase = phase + frequency // phase accumulate In this routine just does DDS: volatile long phase = 0L So have a spare timer set up to overflow frequently (lets say 10kHz or similar). That to drive DDS in an interrupt routine that is fired off frequently. If you have your PID loop output the desired velocity value then you can simply use I may have to scale the frequency on the stepper driver. If I slow down the program loop to 2hz, I can easily achieve 1hz, but then my robot controller goes unstable. Since my program loops at 200hz, the lowest PWM frequency is 100hz. ![]() I still need to figure out how to output very low PWM frequency. The tiny delay in the pulse generator function does not affect the fixed time step (0.005 sec or 200hz sample rate) control loop. So this Timer approach for PWM variable frequency works great. The highest frequency I need for driving my stepper motor is only 10khz. The delay is 10 microseconds and the stepper driver handles it nicely. Rather than shaping the pulse with ATMEL registers (out of my expertise), I did it with simple code: HIGH - DELAY - LOW - DELAY. That is true provided the duty cycle is fixed. So you would set RA or RB for the pulse width, then write RC to set the frequency. You don't need an exact 50% duty cycle for a stepper, just a pulse as small as 5us (depending on driver). The callback function generates a single pulse. I attach an interrupt function that is called at a certain frequency or period. Is there a way to setup variable frequency PWM signals with fixed 50% duty cycle in a loop without upsetting the program loop timing? Changing hardware PWM frequency in a loop is not practical. To change RPM, I need to change the period or frequency of that wave. The command is in the form of a pulse, like a PWM wave with 50% duty cycle. The problem: To drive a stepper motor I need to send a step command to a stepper driver. I use the "pwm01.h" library to setup the hardware PWM frequency and the signal just runs in the background. Typically I use standard DC motors driven by a VNH2SP30 Motor Driver and I simply change the PWM duty cycle to change RPM without upsetting the program loop timing. Just not sure how to control them in my Arduino Due under a fixed time step program loop. Been having backlash feedback issues with my banebots motors (RS454 motor with 26:1 gearbox). I'm considering using stepper motors for a balancing robot because the backlash is very low and torque is highest at low RPM.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |