hal_pwm.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "hal_pwm.h"
  2. //PE2--TIMA_3_PWM5 PE3--TIMA_3_PWM6
  3. void time_pwm_out(void)
  4. {
  5. stc_tmra_init_t stcTmraInit;
  6. stc_tmra_pwm_init_t stcPwmInit;
  7. /* 1. Enable TimerA peripheral clock. */
  8. FCG_Fcg2PeriphClockCmd(FCG2_PERIPH_TMRA_3, ENABLE);
  9. /* 2. Set a default initialization value for stcTmraInit. */
  10. (void)TMRA_StructInit(&stcTmraInit);
  11. /* 3. Modifies the initialization values depends on the application. */
  12. stcTmraInit.sw_count.u16CountMode = TMRA_MD1;
  13. stcTmraInit.sw_count.u16CountDir = TMRA_DIR1;
  14. stcTmraInit.u32PeriodValue = TMRA_PERIOD_VAL1;
  15. (void)TMRA_Init(TMRA_UNIT1, &stcTmraInit);
  16. /* 4. Set the comparison reference value. */
  17. (void)TMRA_PWM_StructInit(&stcPwmInit);
  18. stcPwmInit.u32CompareValue = TMRA_PWM_CMP_VAL1;
  19. GPIO_SetFunc(TMRA_PWM_PORT1, TMRA_PWM_PIN1, TMRA_PWM_PIN_FUNC1);
  20. (void)TMRA_PWM_Init(TMRA_UNIT1, TMRA_PWM_CH1, &stcPwmInit);
  21. TMRA_PWM_OutputCmd(TMRA_UNIT1, TMRA_PWM_CH1, ENABLE);
  22. /* 3. Modifies the initialization values depends on the application. */
  23. stcTmraInit.sw_count.u16CountMode = TMRA_MD2;
  24. stcTmraInit.sw_count.u16CountDir = TMRA_DIR2;
  25. stcTmraInit.u32PeriodValue = TMRA_PERIOD_VAL2;
  26. (void)TMRA_Init(TMRA_UNIT2, &stcTmraInit);
  27. /* 4. Set the comparison reference value. */
  28. (void)TMRA_PWM_StructInit(&stcPwmInit);
  29. stcPwmInit.u32CompareValue = TMRA_PWM_CMP_VAL2;
  30. GPIO_SetFunc(TMRA_PWM_PORT2, TMRA_PWM_PIN2, TMRA_PWM_PIN_FUNC2);
  31. (void)TMRA_PWM_Init(TMRA_UNIT2, TMRA_PWM_CH2, &stcPwmInit);
  32. TMRA_PWM_OutputCmd(TMRA_UNIT2, TMRA_PWM_CH2, ENABLE);
  33. TMRA_Start(TMRA_UNIT1);
  34. }