On 9/15/2015 6:39 AM, Marius Alksnys wrote:
> I want more granularity at higher PWM frequencies like 20 kHz. When using
> only P term and small P value, I could notice PWM steps by turning the
> motor by hand.
Yes, the hardware PWM channels would work better than the PRU for
motor control, particularly closed-loop servo control. The PRU PWM
logic was intended primarily for low frequency heater control on a 3D
printer.
AFAIK, no one has yet written a hardware PWM driver for HAL, but the
existing eQEP driver should provide a decent starting point.
> I have not made a complete investigation why, but with PRU PWM I get
> glitches sometimes. In standstill sometimes motor receives a spike large
> enough to move the motor out of position and PIDs trying to compensate it
> later on. I just noticed that some PRU periods work better than others.
Hmm...there might be a corner case in the PRU code causing these
spikes. The question is if it's coming from the HAL system, or from
the PRU code itself. As Michael mentioned, you can use halscope to
monitor the PWM commanded value to see if the spike is being sent to
the PWM sub-system (if so, you've got some other problem with your HAL
setup or PID values). If not, it's probably a corner-case glitch in
the PRU code I never noticed (since it wouldn't affect a heating
element much). My first guess would be the output stays high for one
full PWM period...if you've got a decent 'scope you should be able to
trigger on pulse length and verify if this is actually what's happening.
> Knowing the limits of PRU PWM would be strong base to decide ehrpwm.
What frequency are you wanting to use for PWM. You mention 20 KHz,
above, which means maybe 50-100 steps for a traditional PWM
implementation using the PRU (500-1000 nS PRU period, which should
work if you're _only_ doing PWM with the PRU). A better option might
be to use delta-sigma modulation, but that's likely only viable if
you're converting the PWM to an analog signal prior to the motor drive
H-bridge. The delta-sigma output frequency would be too high (100 KHz
at the default "slow" 10 uS PRU period) to drive most FET bridges
directly without burning a *LOT* of energy in the transition region.
If you want to try delta-sigma modulation, the PRU code has been
written, but I didn't update the HAL side driver for it when I did a
major rewrite a while back. It should be pretty easy to get running
again if you think it will help.
--
Charles Steinkuehler
cha...@steinkuehler.net