Fai
New Member
hi, I,m fai
Does anyone ever use PWM on Nuvoton NUC100 series..? I,m familiar with AVR and I want migration to ARM series, and I try ARM Cortex M0 from nuvoton. I'm confuse, how to setting for duty cycle,. I,m using Coocox and I make initialization system using Co Smart, i try change CMR and CNR value but not change on output. I get refference from NUC100 Series Driver Reference Guide but I'm still do not understand. Below my code.
#include "NUC1xx.h"
#include "DrvSYS.h"
#include "DrvGPIO.h"
#include "DrvPWM.h"
/*************************************************************
* SYS Initialization Code Template
**************************************************************/
void SYSCtl_Init()
{
/* Unlock protected registers */
DrvSYS_UnlockProtectedReg();
/* Select the osc clock source */
DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);
/* Select the HCLK source */
DrvSYS_SelectHCLKSource(0);
/* Set the HCLK clock divider */
DrvSYS_SetClockDivider(E_SYS_HCLK_DIV, 0);
/* Select the clock source */
DrvSYS_SelectSysTickSource(0);
DrvSYS_LockProtectedReg();
}
void PWM_Init()
{
S_DRVPWM_TIME_DATA_T sPt_2;
uint8_t u8Timer_2;
/* Enable PWM clock */
DrvPWM_Open();
/* Set PWM2 Pin */
outpw(&SYS->GPAMFP, inpw(&SYS->GPAMFP) | (0x1<<14));
outpw(&SYS->ALTMFP, inpw(&SYS->ALTMFP) & ~(0x1<<11));
/* Enable PWM clock */
DrvPWM_SelectClockSource(DRVPWM_TIMER2, DRVPWM_EXT_12M);
/* PWM2 Timer property */
sPt_2.u8Mode = DRVPWM_AUTO_RELOAD_MODE;
sPt_2.u32Frequency = 0;
sPt_2.u8PreScale = 0;
sPt_2.u8ClockSelector = DRVPWM_CLOCK_DIV_1;
sPt_2.u8HighPulseRatio = 0;
sPt_2.i32Inverter = FALSE;
sPt_2.u32Duty = 0;
u8Timer_2 = DRVPWM_TIMER2;
/* Set PWM Timer2 Configuration */
DrvPWM_SetTimerClk(DRVPWM_TIMER2, &sPt_2);
/* Enable in/out for PWM Timer2 */
DrvPWM_SetTimerIO(DRVPWM_TIMER2, 1);
/* Enable the PWM Timer 2 */
DrvPWM_Enable(DRVPWM_TIMER2, 1);
}
int main(void)
{
SYSCtl_Init();
PWM_Init()
PWMA->CNR2=0xFF;
PWMA->CMR2=0x01;
while(1)
{
}
Does anyone ever use PWM on Nuvoton NUC100 series..? I,m familiar with AVR and I want migration to ARM series, and I try ARM Cortex M0 from nuvoton. I'm confuse, how to setting for duty cycle,. I,m using Coocox and I make initialization system using Co Smart, i try change CMR and CNR value but not change on output. I get refference from NUC100 Series Driver Reference Guide but I'm still do not understand. Below my code.
#include "NUC1xx.h"
#include "DrvSYS.h"
#include "DrvGPIO.h"
#include "DrvPWM.h"
/*************************************************************
* SYS Initialization Code Template
**************************************************************/
void SYSCtl_Init()
{
/* Unlock protected registers */
DrvSYS_UnlockProtectedReg();
/* Select the osc clock source */
DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1);
/* Select the HCLK source */
DrvSYS_SelectHCLKSource(0);
/* Set the HCLK clock divider */
DrvSYS_SetClockDivider(E_SYS_HCLK_DIV, 0);
/* Select the clock source */
DrvSYS_SelectSysTickSource(0);
DrvSYS_LockProtectedReg();
}
void PWM_Init()
{
S_DRVPWM_TIME_DATA_T sPt_2;
uint8_t u8Timer_2;
/* Enable PWM clock */
DrvPWM_Open();
/* Set PWM2 Pin */
outpw(&SYS->GPAMFP, inpw(&SYS->GPAMFP) | (0x1<<14));
outpw(&SYS->ALTMFP, inpw(&SYS->ALTMFP) & ~(0x1<<11));
/* Enable PWM clock */
DrvPWM_SelectClockSource(DRVPWM_TIMER2, DRVPWM_EXT_12M);
/* PWM2 Timer property */
sPt_2.u8Mode = DRVPWM_AUTO_RELOAD_MODE;
sPt_2.u32Frequency = 0;
sPt_2.u8PreScale = 0;
sPt_2.u8ClockSelector = DRVPWM_CLOCK_DIV_1;
sPt_2.u8HighPulseRatio = 0;
sPt_2.i32Inverter = FALSE;
sPt_2.u32Duty = 0;
u8Timer_2 = DRVPWM_TIMER2;
/* Set PWM Timer2 Configuration */
DrvPWM_SetTimerClk(DRVPWM_TIMER2, &sPt_2);
/* Enable in/out for PWM Timer2 */
DrvPWM_SetTimerIO(DRVPWM_TIMER2, 1);
/* Enable the PWM Timer 2 */
DrvPWM_Enable(DRVPWM_TIMER2, 1);
}
int main(void)
{
SYSCtl_Init();
PWM_Init()
PWMA->CNR2=0xFF;
PWMA->CMR2=0x01;
while(1)
{
}