I’m working on [a project where I want to use the PWM1 of my LPC1769 to control a motor’s speed (via a L298N driver). With various settings I can get an LED to dim, so I know my code works in general, but I cannot get the motor to rotate at different RPMs. On the L298N side, I am driving IN1/2 high/low (forward), OUT1/2 to my DC motor, CSA to ground and pulsing ENA. I have also tried leaving ENA high and pulsing IN1 instead but it made no difference.
Firmware wise, I am using CMSIS 1.3 and the LPC17xx CMSIS driver library. From the settings in the CMSIS code (which I did not bother to adjust), PCLK_PWM1 is running at 25MHz. I have enabled PWM1 and set MR0 to match at 25,000 (ticks) running in timer mode with no prescale, which as I understand it, should then be operating at 1kHz frequency. For the sake of testing, I have set MR1 to match at 6,250 (ticks) which should yield a 25% duty cycle (in reality this will be set based on an ADC input).
As I said, these hardware and software settings are not controlling the speed of the motor so I am not understanding something correctly about either the L298N or the LPC1769 PWM but I am not sure what that is. Any help is very appreciated.](http://forum.sparkfun.com/viewtopic.php?f=14&t=24804)
Wow, head first indeed (regarding your project).
I get the impression you’re using the Cana-kit L298 Driver sold here on SparkFun. I didn’t think much of their documentation. A schematic would sure be nice.
Anyway, best to start with the basics. Does a voltmeter across the motor terminals show the DC voltage changing as you adjust the duty cycle?
Sorry for the late reply. As I noted in my other thread, I got everything working using the other VIN pin on my LPCXpresso board. Using a duty cycle of 20% with a PWM frequency of 1kHz yields me a working motor. My problem is now the whine produced at 1kHz. I plan on trying higher frequencies to see if they work better for maintaining my duty cycle but reducing the whine.
I did not try measuring my voltage yet but it’s something to keep in mind I suppose. Should I expect it to drop with a lower duty cycle? I would not have thought so but I’m also not an EE.
As for the motor driver hardware: I am not using the Cana-Kit but simply connecting the L298N through the Sparkfun breakout board to my breadboard and using the schematic in the L298N datasheet.
Glad you’re getting some results. (Somehow I missed the second page of the other thread.)
My understanding (which might not be perfect) is that the DC motor basically responds to the DC voltage across the coils. That DC voltage, to a first approximation, is the supply voltage multiplied by the duty cycle. So the motor should run faster with a higher duty cycle.
There is a trade-off between undesirable effects that occur at low frequency:
- discontinuous winding current
- audible noise (aggravated by discontinuous winding current)
and undesirable effects that happen at high frequency - mainly switching losses in the driver.