Unit 3 PWM DCMotor
Unit 3 PWM DCMotor
RV College of world
Engineering
Course Code:CS344AI
IOT and Embedded Computing
What is PWM..
Pulse Width
Ton - (On time)
PWM Registers..
PWMTCR - PWM Timer Control Register
.
RV College of
Engineering Go, change the world
RV College of
Engineering Go, change the world
void PWM_Init(void)
{
//P0.1 pin has second alternate function as PWM3 channel, so using PINSEL0 register
// Select P0.1 as PWM output , bits D2 & D3 are for P0.1
PINSEL0 |= 0x00000008;
//load the value to MR0 to fix the pulse rate
PWMMR0 = 2000; // any other value, I could have taken
//Configure PWM channel 3 as single edge type and enable the channel
//bit D3 to select single edge(make it 0), bit D11 is for enabling PWM3 channel(make it 1)
PWMPCR = 0x00000800;
// enable PWM unit of LPC2148 and start the timer
PWMTCR = 0x00000009; // bit D3 = 1 (enable PWM), bit D0=1 (start the timer)
}
RV College of
Engineering Go, change the world
H Bridge arrangement
To Drive DC Motor
RV College of
Engineering Go, change the world
#include <lpc214x.h>
void runDCMotor(int direction, int dutycycle) ;
int main()
{
IO0DIR |= 1U << 28; //set P0.28 as output pin
PINSEL0 |= 2 << 18; //select P0.9 as PWM6 (option 2)
runDCMotor(2,10); // run at 10% duty cycle
while(1); // do other jobs
}
RV College of
Engineering Go, change the world