LPC1769 PWM out to L298

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1769 PWM out to L298

757 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NineBall on Tue Dec 06 21:10:46 MST 2011
I am trying to control DC motor RPM rate by toggling the enable pin of a L298 motor driver with the PWM output from my LPC1769. I am using CMSIS 1.3 and the LPC17xx CMSIS Driver Library. My code is based from the single edge PWM example in the driver library and works fine for dimming an LED at MR0=256 and MR1 for any value between 0 and 255. I did not change the settings in the CMSIS library so my PCLK_PWM1 is running at 25MHz. So far, I have been unsuccessful in getting the motor to run at anything other than full speed. I am using an MR0 of 25000 to reach a PWM frequency of 1kHz as that worked in a tutorial I found on PyroElectro.

[COLOR=#005032][COLOR=#005032]PWM_TIMERCFG_Type [/COLOR][/COLOR]PWMCfgDat;
[COLOR=#005032][COLOR=#005032]PWM_MATCHCFG_Type[/COLOR][/COLOR] PWMMatchCfgDat;
 
[COLOR=#3f7f5f][COLOR=#3f7f5f]/* Initialize PWM peripheral in timer mode, prescale value = 1 (absolute value - tick value) */[/COLOR][/COLOR]
PWMCfgDat.[COLOR=#0000c0][COLOR=#0000c0]PrescaleOption[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]PWM_TIMER_PRESCALE_TICKVAL[/COLOR][/COLOR][/I];
PWMCfgDat.[COLOR=#0000c0][COLOR=#0000c0]PrescaleValue[/COLOR][/COLOR] = 1;
PWM_Init(LPC_PWM1, [I][COLOR=#0000c0][COLOR=#0000c0]PWM_MODE_TIMER[/COLOR][/COLOR][/I], ([B][COLOR=#7f0055][COLOR=#7f0055]void[/COLOR][/COLOR][/B] *) &PWMCfgDat);
 
[COLOR=#3f7f5f][COLOR=#3f7f5f]/* Set PWM frequency @ 1kHz */[/COLOR][/COLOR]
PWM_MatchUpdate(LPC_PWM1, 0, 25000, [I][COLOR=#0000c0][COLOR=#0000c0]PWM_MATCH_UPDATE_NOW[/COLOR][/COLOR][/I]);
PWMMatchCfgDat.[COLOR=#0000c0][COLOR=#0000c0]IntOnMatch[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]DISABLE[/COLOR][/COLOR][/I];
PWMMatchCfgDat.[COLOR=#0000c0][COLOR=#0000c0]MatchChannel[/COLOR][/COLOR] = 0;
PWMMatchCfgDat.[COLOR=#0000c0][COLOR=#0000c0]ResetOnMatch[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]ENABLE[/COLOR][/COLOR][/I];
PWMMatchCfgDat.[COLOR=#0000c0][COLOR=#0000c0]StopOnMatch[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]DISABLE[/COLOR][/COLOR][/I];
PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);
 
[COLOR=#3f7f5f][COLOR=#3f7f5f]/* Set match value for PWM channel 1 = 1/4 rate*/[/COLOR][/COLOR]
PWM_MatchUpdate(LPC_PWM1, 1, 6250, [I][COLOR=#0000c0][COLOR=#0000c0]PWM_MATCH_UPDATE_NOW[/COLOR][/COLOR][/I]);
PWMMatchCfgDat.[COLOR=#0000c0][COLOR=#0000c0]IntOnMatch[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]DISABLE[/COLOR][/COLOR][/I];
PWMMatchCfgDat.[COLOR=#0000c0][COLOR=#0000c0]MatchChannel[/COLOR][/COLOR] = 1;
PWMMatchCfgDat.[COLOR=#0000c0][COLOR=#0000c0]ResetOnMatch[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]DISABLE[/COLOR][/COLOR][/I];
PWMMatchCfgDat.[COLOR=#0000c0][COLOR=#0000c0]StopOnMatch[/COLOR][/COLOR] = [I][COLOR=#0000c0][COLOR=#0000c0]DISABLE[/COLOR][/COLOR][/I];
PWM_ConfigMatch(LPC_PWM1, &PWMMatchCfgDat);
 
[COLOR=#3f7f5f][COLOR=#3f7f5f]/* Enable PWM Channel Output */[/COLOR][/COLOR]
PWM_ChannelCmd(LPC_PWM1, 1, [I][COLOR=#0000c0][COLOR=#0000c0]ENABLE[/COLOR][/COLOR][/I]);
PWM_ResetCounter(LPC_PWM1);
PWM_CounterCmd(LPC_PWM1, [I][COLOR=#0000c0][COLOR=#0000c0]ENABLE[/COLOR][/COLOR][/I]);
PWM_Cmd(LPC_PWM1, [I][COLOR=#0000c0][COLOR=#0000c0]ENABLE[/COLOR][/COLOR][/I]);


[LEFT]P2.0 has been set earlier in the code as PWM1.1 and is attached to ENA and ENB on the L298 (which has been wired according to the example bidirectional DC motor control schematic in the L298 datasheet) with Inputs1/4 driven high and 2/4 driven low for forward operation. I currently am not sure if my PWM code is bad or if there is something I missed about driving the motor controller itself. Any help is appreciated.[/LEFT]
0 Kudos
4 Replies

581 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by abie555 on Fri May 11 18:55:31 MST 2012
Hi. May I know what kind of bidirectional dc motor you are using for the project? Servor or stepper motor? By the way, I noticed that you connect P2.0 which generates an output signal of a certain duty cycle to the Enable A and B of the L298 driver. Does this mean that your motor will run and stop in tandem with the pulse generated by P2.0. Thanks!:)
0 Kudos

581 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NineBall on Tue Dec 13 18:56:19 MST 2011
If I owned one I would tell you. But as I said in post #2, switching to EXT_POWX fixed my problem. And yes, I have the diodes on the outputs as I said I was following the schematic. Also, I'm pulsing the ENA pin and have IN1 and IN2 tied opposite of each other with a GPIO out and an NPN transistor. The 1kHz frequency causes the motor to hum so I will be trying 25kHz later once my son is in bed.
0 Kudos

581 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Polux rsv on Tue Dec 13 09:00:10 MST 2011
And what the oscilloscope is saying ?  :rolleyes:

Did you fit external diodes as suggested on schematics ?

And you should use one of the IN pin for PWM, not EN which will let the motor spin freely.
The second IN pin will be the direction signal. But be carefull with polarities:
IN1=0, IN2=25%PWM, your motor will spin in direction 1, at 25% of full speed.
IN1=1, IN2=25%PWM, your motor will spin in direction 2, at [B]75%[/B] of full speed.
That's why when IN1=1, you should apply 100-X of PWM, in order to have your motor spining at X% of full speed.

Angelo
0 Kudos

581 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by NineBall on Mon Dec 12 22:20:59 MST 2011
Apparently, what I missed was that I was using VIO_3V3X instead of EXT_POWX to power my board which I guess was yielding enough power to the LED but not the motor. From the table in the LPCXpresso Getting Started guide I thought I was using the right input for an external 3V3 power rail but the real world says otherwise.
0 Kudos