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
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);
}