Ejemplo n.º 1
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
    /*System clock configuration*/
    SystemInit();
    /* CPIO configuration */
    GPIO_Setting();

    /* Timer mode configuration for PWM3*/
    PrescalerValue = (SystemCoreClock / 1000000) / 10; // Prescale is 2 for 10MHz
    TimerModeStructure.PWM_CHn_PR = PrescalerValue - 1;
    TimerModeStructure.PWM_CHn_MR = 80000;
    TimerModeStructure.PWM_CHn_LR = 100000; // 80% duty cycle
    TimerModeStructure.PWM_CHn_UDMR = PWM_CHn_UDMR_UpCount;
    TimerModeStructure.PWM_CHn_PDMR = PWM_CHn_PDMR_Periodic;
    
    PWM_TimerModeInit(PWM_CH3, &TimerModeStructure);
    
    /* Timer mode configuration for PWM4*/
    TimerModeStructure.PWM_CHn_PR = PrescalerValue - 1;
    TimerModeStructure.PWM_CHn_MR = 30000;
    TimerModeStructure.PWM_CHn_LR = 100000; // 30% duty cycle
    TimerModeStructure.PWM_CHn_UDMR = PWM_CHn_UDMR_UpCount;
    TimerModeStructure.PWM_CHn_PDMR = PWM_CHn_PDMR_Periodic;
    
    PWM_TimerModeInit(PWM_CH4, &TimerModeStructure);
    
    /* Timer mode configuration for PWM5*/
    TimerModeStructure.PWM_CHn_PR = PrescalerValue - 1;
    TimerModeStructure.PWM_CHn_MR = 4294900000UL;
    TimerModeStructure.PWM_CHn_LR =  4294800000UL;
    TimerModeStructure.PWM_CHn_UDMR = PWM_CHn_UDMR_DownCount;
    TimerModeStructure.PWM_CHn_PDMR = PWM_CHn_PDMR_Oneshot;
    
    PWM_TimerModeInit(PWM_CH5, &TimerModeStructure);
    

    /* PWM output enable */
    PWM_CtrlPWMOutputEnable(PWM_CH3);
    PWM_CtrlPWMOutputEnable(PWM_CH4);
    PWM_CtrlPWMOutputEnable(PWM_CH5);

    /* PWM start */
    PWM_CHn_Start(PWM_CH3);
    PWM_CHn_Start(PWM_CH4);
    PWM_CHn_Start(PWM_CH5);

    while(1);
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: Wiznet/W7500
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
    /*System clock configuration*/
    SystemInit();
//    *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock setting 48MHz
    
    /* CLK OUT Set */
//    PAD_AFConfig(PAD_PA,GPIO_Pin_2, PAD_AF2); // PAD Config - CLKOUT used 3nd Function
    /* NVIC configuration */
    NVIC_Configuration();

    /* CPIO configuration */
    GPIO_Setting();

    /* Timer mode configuration */
    PrescalerValue = ((SystemFrequency / 1000000) / 10); // Prescale is 2 for 10MHz
    TimerModeStructure.PWM_CHn_PR = PrescalerValue - 1;
    TimerModeStructure.PWM_CHn_MR = 600000;
    TimerModeStructure.PWM_CHn_LR = 1200000;
    TimerModeStructure.PWM_CHn_UDMR = PWM_CHn_UDMR_UpCount;
    TimerModeStructure.PWM_CHn_PDMR = PWM_CHn_PDMR_Periodic;
    
    PWM_TimerModeInit(PWM_CH0, &TimerModeStructure); 

    /* PWM interrupt configuration */
    PWM_IntConfig(PWM_CH0, ENABLE);
    PWM_CHn_IntConfig(PWM_CH0, PWM_CHn_IER_MIE | PWM_CHn_IER_OIE, ENABLE);

    /* PWM channel 0 start */
    PWM_CHn_Start(PWM_CH0);

    while(1);
}
Ejemplo n.º 3
0
void us_ticker_init(void)
{
    if (us_ticker_inited) return;
    us_ticker_inited = 1;

    SystemCoreClockUpdate();
    TimerInitType.PWM_CHn_PR = (GetSystemClock() / 1000000) -1;
    TimerInitType.PWM_CHn_LR = 0xFFFFFFFF;
    TimerInitType.PWM_CHn_PDMR = 1;

    PWM_TimerModeInit(TIMER_1, &TimerInitType);
    PWM_CHn_Start(TIMER_1);
}
Ejemplo n.º 4
0
void pwmout_period_us(pwmout_t* obj, int us)
{
    PWM_CHn_Stop(obj->PWM_CHx);
    // Update the SystemCoreClock variable
    SystemCoreClockUpdate();

    obj->period = (us * 2) - 1;
    obj->pulse = us / 2;
    
    obj->PrescalerValue = (SystemCoreClock / 1000000) / 2;
    TimerModeStructure.PWM_CHn_PR = obj->PrescalerValue - 1;
    TimerModeStructure.PWM_CHn_MR = obj->pulse;
    TimerModeStructure.PWM_CHn_LR = obj->period; 
    TimerModeStructure.PWM_CHn_UDMR = PWM_CHn_UDMR_UpCount;
    TimerModeStructure.PWM_CHn_PDMR = PWM_CHn_PDMR_Periodic;
    
    PWM_TimerModeInit(obj->PWM_CHx, &TimerModeStructure);
    PWM_CtrlPWMOutputEnable(obj->PWM_CHx);
}
Ejemplo n.º 5
0
void pwmout_write(pwmout_t* obj, float value)
{
    if (value < (float)0.0) {
        value = 0.0;
    } else if (value > (float)1.0) {
        value = 1.0;
    }

    obj->pulse = (uint32_t)((float)obj->period * value);
    
    PWM_CHn_Stop(obj->PWM_CHx);

    TimerModeStructure.PWM_CHn_PR = obj->PrescalerValue - 1;
    TimerModeStructure.PWM_CHn_MR = obj->pulse;
    TimerModeStructure.PWM_CHn_LR = obj->period; 
    TimerModeStructure.PWM_CHn_UDMR = PWM_CHn_UDMR_UpCount;
    TimerModeStructure.PWM_CHn_PDMR = PWM_CHn_PDMR_Periodic;
    
    PWM_TimerModeInit(obj->PWM_CHx, &TimerModeStructure);
    
    PWM_CHn_Start(obj->PWM_CHx);
}
Ejemplo n.º 6
0
void rtc_init(void) {
    PWM_TimerModeInitTypeDef TimerModeStructure;
    *(volatile uint32_t *)(0x410010e0) = 0x03;

    /* Timer mode configuration */    
    TimerModeStructure.PWM_CHn_PR = 7;
    TimerModeStructure.PWM_CHn_MR = 1;
    TimerModeStructure.PWM_CHn_LR = 0xF4240;
    TimerModeStructure.PWM_CHn_UDMR = PWM_CHn_UDMR_UpCount;
    TimerModeStructure.PWM_CHn_PDMR = PWM_CHn_PDMR_Periodic;
    
    PWM_TimerModeInit(PWM_CH3, &TimerModeStructure); 
    
    /* PWM interrupt configuration */
    PWM_IntConfig(PWM_CH3, ENABLE);
    PWM_CHn_IntConfig(PWM_CH3, PWM_CHn_IER_OIE, ENABLE);
    
    /* PWM channel 0 start */
    PWM_CHn_Start(PWM_CH3);
    NVIC_SetVector(PWM3_IRQn, (uint32_t)PWM3_Handler);
    NVIC_EnableIRQ(PWM3_IRQn);		
    rtc_enabled = 1;
}