Page MenuHomec4science

pwm.c
No OneTemporary

File Metadata

Created
Sun, Dec 1, 00:38
#include "pwm.h"
#include <gpio.h>
void pwm_init(pwm_t * pwm, pwm_device_t device){
switch(device){
case PWM_1_1 :
pwm->DC = &(P1DC1);
pwm->TPER = &(P1TPER);
pwm->TCON = &(P1TCON);
pwm->CON1 = &(PWM1CON1);
pwm->pin = 0;
break;
case PWM_1_2 :
pwm->DC = &(P1DC2);
pwm->TPER = &(P1TPER);
pwm->TCON = &(P1TCON);
pwm->CON1 = &(PWM1CON1);
pwm->pin = 1;
break;
case PWM_1_3 :
pwm->DC = &(P1DC3);
pwm->TPER = &(P1TPER);
pwm->TCON = &(P1TCON);
pwm->CON1 = &(PWM1CON1);
pwm->pin = 2;
break;
case PWM_2_1 :
pwm->DC = &(P2DC1);
pwm->TPER = &(P2TPER);
pwm->TCON = &(P2TCON);
pwm->CON1 = &(PWM2CON1);
pwm->pin = 0;
break;
default :
pwm->DC = 0;
pwm->TCON = 0;
pwm->CON1 = 0;
pwm->TPER = 0;
pwm->pin = 0;
break;
}
//enable the channel globally
atomic_or(pwm->TCON , 1 << 15);
//initialize the pin as an output !!!
atomic_or(pwm->CON1, ( 1 << (pwm->pin + 4)) | (1 << (pwm->pin + 8)));
}

Event Timeline