assign VOLATILE V2
This commit is contained in:
31
ccs/pwm.c
Normal file
31
ccs/pwm.c
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
#include "pwm.h"
|
||||
|
||||
void pwm_init_for_motors(uint16_t period) {
|
||||
P2->DIR |= 0xc0;
|
||||
P2->SEL0 |= 0xc0;
|
||||
P2->SEL1 &= ~0xc0;
|
||||
|
||||
// 전체 주기 설정
|
||||
TIMER_A0->CCTL[0] = 0x0080;
|
||||
TIMER_A0->CCR[0] = period;
|
||||
TIMER_A0->EX0 = 0x00000;
|
||||
// 세부 주기 및 출력 설정
|
||||
TIMER_A0->CCTL[3] = 0x0040;
|
||||
TIMER_A0->CCR[3] = 0; // set duty left
|
||||
TIMER_A0->CCTL[4] = 0x0040;
|
||||
TIMER_A0->CCR[4] = 0; // set duty right
|
||||
// 모드
|
||||
TIMER_A0->CTL = 0x02f0;
|
||||
// SMCLK 12MHz, divide by 8, up-down mode
|
||||
}
|
||||
|
||||
void pwm_set_duty_right(uint16_t duty) {
|
||||
if (duty > TIMER_A0->CCR[0]) duty = TIMER_A0->CCR[0];
|
||||
TIMER_A0->CCR[3] = duty;
|
||||
}
|
||||
|
||||
void pwm_set_duty_left(uint16_t duty) {
|
||||
if (duty > TIMER_A0->CCR[0]) duty = TIMER_A0->CCR[0];
|
||||
TIMER_A0->CCR[4] = duty;
|
||||
}
|
||||
Reference in New Issue
Block a user