lpcware

LPC1769 PWM out to L298

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
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]

Outcomes