EFM32G210 EVM - PWM테스트 (RGB LED 제어)
EFM32는 6개의 PWM출력을 할수 있다. PWM을 이용하여 [Xmega32-EX EVM] 확장 테스트 보드에서 RGB LED 조면제어 테스트를 해 보았다.
EFM32 PWM 기능
- Up-count PWM
- Up/down-count PWM
- Predictable initial PWM output state (configured by SW)
- Buffered compare register to ensure glitch-free update of compare values
EFM32 PWM 출력 핀맵
EFM32는 PWM출력을 위한 2개의 타이머가 있고 각각 3채널, 6개의 PWM을 출력할 수 있다.
EFM32G210F128 Timer 블록도
3채널 PWM 출력 테스트를 위해 Xmega32-EX 확장 테스트 보드의 3색 컬러 LED를 이용하였다.
EFM32 PWM테스트 동영상
EFM32 PWM 초기화 코드
void InitPwm0(void)
{
//Enable clock for TIMER0 module
CMU_ClockEnable(cmuClock_TIMER0, true);
//Set CC0 location 4 pin (PA0) as output
GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 0);
// Set CC1 location 4 pin (PA1) as output
GPIO_PinModeSet(gpioPortA, 1, gpioModePushPull, 0);
// Set CC2 location 4 pin (PA2) as output
GPIO_PinModeSet(gpioPortA, 2, gpioModePushPull, 1);
// Route CC0 to location 3 (PD1) and enable pin
TIMER0->ROUTE |= (TIMER_ROUTE_CC0PEN | TIMER_ROUTE_CC1PEN |TIMER_ROUTE_CC2PEN | TIMER_ROUTE_LOCATION_LOC1);
/* Select CC channel parameters */
TIMER_InitCC_TypeDef timerCCInit =
{
.eventCtrl = timerEventEveryEdge,
.edge = timerEdgeBoth,
.prsSel = timerPRSSELCh0,
.cufoa = timerOutputActionNone,
.cofoa = timerOutputActionNone,
.cmoa = timerOutputActionToggle,
.mode = timerCCModePWM,
.filter = false,
.prsInput = false,
.coist = false,
.outInvert = false,
};
/* Configure CC channel 0 */
TIMER_InitCC(TIMER0, 0, &timerCCInit);
/* Configure CC channel 1 */
TIMER_InitCC(TIMER0, 1, &timerCCInit);
/* Configure CC channel 2 */
TIMER_InitCC(TIMER0, 2, &timerCCInit);
/* Set Top Value */
TIMER_TopSet(TIMER0, TOP);
TIMER_CompareBufSet(TIMER0, 0, 0x7F);
TIMER_CompareBufSet(TIMER0, 1, 0x7F);
TIMER_CompareBufSet(TIMER0, 2, 0x7F);
/* Select timer parameters */
/* With a clock of 48MHZ, a divider of 512 and a resolution of
256/8 bit the PWM period frequency is approx 366 hz */
TIMER_Init_TypeDef timerInit =
{
.enable = true,
.debugRun = true,
.prescale = timerPrescale512,
.clkSel = timerClkSelHFPerClk,
.fallAction = timerInputActionNone,
.riseAction = timerInputActionNone,
.mode = timerModeUp,
.dmaClrAct = false,
.quadModeX4 = false,
.oneShot = false,
.sync = false,
};
/* Configure timer */
TIMER_Init(TIMER0, &timerInit);
}
EFM32 PWM 테스트 소스코드
int main(void)
{
char r,g,b;
unsigned int cnt = 0;
_SystemInit();
// Ensure core frequency has been updated
SystemCoreClockUpdate();
// Setup SysTick Timer for 1 msec interrupts
if (SysTick_Config(SystemCoreClock / 1000)) while (1) ;
Led1Init();
Led1Off();
DebugInit(BAUD_115200);
DebugPrint("EFM32 PWM Test\r\m");
InitPwm0();
LED_RgbSet(r, g, b);
while(1)
{
if(msTicks>10)
{
msTicks = 0;
g= 255-r;
b= 128-g;
LED_RgbSet(r, g, b);
if(r<=1)
{
r=255;
Delay(200);
}
else r -=1;
}
}
}