已回答假定已回答

如何设置PWM,在示波器观察PWM0_AH/AL信号

lurberic 在 2015-1-29 詢問的問題
最後回覆由harry.wei於2015-2-2提供

使用ADSP-408F评估板,设置PWM,系统时钟为100MHz,PWM 的频率为10KHz,@@@@@但是在示波器只能看到PWM_SYNC信号,而PPWM0_AH/AL,PWM0_BH/BL,PWM0_CH/CL,没有脉冲,下面是程序,请帮助查看一下,那里有问题呢?

void SetupPWM(void){

/*****************************************************************************

  Function: SetupPWM

 

 

  Parameters: None

 

  Returns: None

 

  Notes: Setup of 3 phase PWM timer

 

 

*****************************************************************************/ 

  static ADI_PWM_RESULT result;

  uint32_t temp = 0;

       

  result = adi_pwm_Open(PWM_DEV, &PwmMemory, ADI_PWM_MEMORY_SIZE, &hPWM, PwmCallback, NULL); // Open driver

 

  temp = (uint32_t)(fsysclk / (2u * F_SW));            // Calculate switching period as number of sys clocks (up-down counter)  

  result = adi_pwm_SetReferencePeriod(hPWM, temp); 

 

  temp = (uint32_t)((fsysclk * DEAD_TIME) / 2u);       // Calculate dead time period as number of sys clocks (up-down counter)

  result = adi_pwm_SetDeadtime(hPWM, temp);

 

  temp = (uint32_t)(fsysclk * SYNC_PULSE_WIDTH);       // Calculate sync pulse width as number of sys clocks (up-down counter)  

  result = adi_pwm_SetSyncWidth(hPWM, temp); 

  result = adi_pwm_ExtSyncEnable(hPWM, false, false);          // Internal sync used

  result = adi_pwm_SetIntSyncTimerMode(hPWM, ADI_PWM_TIMER0);  // Use timer 0 to generate sync.

 

  result = adi_pwm_SetPulseMode(hPWM, ADI_PWM_CHANNEL_A, ADI_PWM_HIGH_SIDE, ADI_PWM_PULSE_SYMMETRICAL); // Use symmetrical PWM on all channels

  result = adi_pwm_SetPulseMode(hPWM, ADI_PWM_CHANNEL_A, ADI_PWM_LOW_SIDE,  ADI_PWM_PULSE_SYMMETRICAL);

  result = adi_pwm_SetPulseMode(hPWM, ADI_PWM_CHANNEL_B, ADI_PWM_HIGH_SIDE, ADI_PWM_PULSE_SYMMETRICAL);

  result = adi_pwm_SetPulseMode(hPWM, ADI_PWM_CHANNEL_B, ADI_PWM_LOW_SIDE,  ADI_PWM_PULSE_SYMMETRICAL);

  result = adi_pwm_SetPulseMode(hPWM, ADI_PWM_CHANNEL_C, ADI_PWM_HIGH_SIDE, ADI_PWM_PULSE_SYMMETRICAL);

  result = adi_pwm_SetPulseMode(hPWM, ADI_PWM_CHANNEL_C, ADI_PWM_LOW_SIDE,  ADI_PWM_PULSE_SYMMETRICAL);

 

  result = adi_pwm_SetTimerMode(hPWM, ADI_PWM_CHANNEL_A, false);   // Use Timer 0 as reference for all channels

  result = adi_pwm_SetTimerMode(hPWM, ADI_PWM_CHANNEL_B, false);

  result = adi_pwm_SetTimerMode(hPWM, ADI_PWM_CHANNEL_C, false);

 

  result = adi_pwm_SetLowSideMode(hPWM, ADI_PWM_CHANNEL_A, false); // LS is inverse of HS on all channels - no need to update LS dutys

  result = adi_pwm_SetLowSideMode(hPWM, ADI_PWM_CHANNEL_B, false);

  result = adi_pwm_SetLowSideMode(hPWM, ADI_PWM_CHANNEL_C, false);

 

 

  result = adi_pwm_SetOutputPolarity(hPWM, ADI_PWM_CHANNEL_A, ADI_PWM_HIGH_SIDE, false);   // Set all outputs to active low

  result = adi_pwm_SetOutputPolarity(hPWM, ADI_PWM_CHANNEL_A, ADI_PWM_LOW_SIDE,  false);

  result = adi_pwm_SetOutputPolarity(hPWM, ADI_PWM_CHANNEL_B, ADI_PWM_HIGH_SIDE, false);

  result = adi_pwm_SetOutputPolarity(hPWM, ADI_PWM_CHANNEL_B, ADI_PWM_LOW_SIDE,  false);

  result = adi_pwm_SetOutputPolarity(hPWM, ADI_PWM_CHANNEL_C, ADI_PWM_HIGH_SIDE, false);

  result = adi_pwm_SetOutputPolarity(hPWM, ADI_PWM_CHANNEL_C, ADI_PWM_LOW_SIDE,  false);

 

  result = adi_pwm_SetTripEnable(hPWM, ADI_PWM_CHANNEL_A, ADI_PWM_TRIP0_SRC, true);    // Enable Trip0 and trip on all channels

  result = adi_pwm_SetTripEnable(hPWM, ADI_PWM_CHANNEL_B, ADI_PWM_TRIP0_SRC, true);

  result = adi_pwm_SetTripEnable(hPWM, ADI_PWM_CHANNEL_C, ADI_PWM_TRIP0_SRC, true);

  result = adi_pwm_SetTripEnable(hPWM, ADI_PWM_CHANNEL_A, ADI_PWM_TRIP1_SRC, true);    // Enable Trip1 and trip on all channels

  result = adi_pwm_SetTripEnable(hPWM, ADI_PWM_CHANNEL_B, ADI_PWM_TRIP1_SRC, true);

  result = adi_pwm_SetTripEnable(hPWM, ADI_PWM_CHANNEL_C, ADI_PWM_TRIP1_SRC, true);

 

  result = adi_pwm_SetTripMode(hPWM, ADI_PWM_CHANNEL_A, ADI_PWM_TRIP0_SRC, false);     // Stop PWM and report fault at trip. Do not restart

  result = adi_pwm_SetTripMode(hPWM, ADI_PWM_CHANNEL_B, ADI_PWM_TRIP0_SRC, false);

  result = adi_pwm_SetTripMode(hPWM, ADI_PWM_CHANNEL_C, ADI_PWM_TRIP0_SRC, false); 

  result = adi_pwm_SetTripMode(hPWM, ADI_PWM_CHANNEL_A, ADI_PWM_TRIP1_SRC, false);

  result = adi_pwm_SetTripMode(hPWM, ADI_PWM_CHANNEL_B, ADI_PWM_TRIP1_SRC, false);

  result = adi_pwm_SetTripMode(hPWM, ADI_PWM_CHANNEL_C, ADI_PWM_TRIP1_SRC, false);

 

  result = adi_pwm_InterruptEnable(hPWM, ADI_PWM_INTERRUPT_TIMER0, true);              // Enable sync irq

  result = adi_pwm_InterruptEnable(hPWM, ADI_PWM_INTERRUPT_TRIP0, true);               // Enable trip0 irq 

  result = adi_pwm_InterruptEnable(hPWM, ADI_PWM_INTERRUPT_TRIP1, true);               // Enable trip1 irq

 

  result = adi_pwm_OutputEnable(hPWM, ADI_PWM_CHANNEL_A, ADI_PWM_HIGH_SIDE, true);    // Enable output pins

  result = adi_pwm_OutputEnable(hPWM, ADI_PWM_CHANNEL_A, ADI_PWM_LOW_SIDE,  true);

  result = adi_pwm_OutputEnable(hPWM, ADI_PWM_CHANNEL_B, ADI_PWM_HIGH_SIDE, true);

  result = adi_pwm_OutputEnable(hPWM, ADI_PWM_CHANNEL_B, ADI_PWM_LOW_SIDE,  true);

  result = adi_pwm_OutputEnable(hPWM, ADI_PWM_CHANNEL_C, ADI_PWM_HIGH_SIDE, true);

  result = adi_pwm_OutputEnable(hPWM, ADI_PWM_CHANNEL_C, ADI_PWM_LOW_SIDE,  true);

  @@

  result = adi_pwm_Enable(hPWM, true);                                                 // Enable PWM

}

 

下面是v021有关PWM的配置,结果什么都没有看到,不知为什么?

void SetupPWM(void){

/*****************************************************************************

  Function: SetupPWM

 

  Parameters: None

 

  Returns: None

 

  Notes: Setup of 3 phase PWM timer

 

*****************************************************************************/

  uint32_t temp = 0;

 

  temp = (uint32_t)(fsysclk / (2u * F_SW));            // Calculate switching period as number of sys clocks (up-down counter)  

  *pREG_PWM0_TM0 = (uint16_t)temp;

 

  temp = (uint32_t)((fsysclk * DEAD_TIME) / 2u);       // Calculate dead time period as number of sys clocks (up-down counter)

  *pREG_PWM0_DT = (uint16_t)temp;

 

  temp = (uint32_t)(fsysclk * SYNC_PULSE_WIDTH);       // Calculate sync pulse width as number of sys clocks (up-down counter)  

  *pREG_PWM0_SYNC_WID = (uint16_t)temp;

 

  *pREG_PWM0_CTL |= (ENUM_PWM_CTL_INTSYNC_0 | ENUM_PWM_CTL_INTSYNC | ENUM_PWM_CTL_EMURUN_DIS);

  

  *pREG_PWM0_ACTL |= (ENUM_PWM_SYM_LO | ENUM_PWM_SYM_HI | ENUM_PWM_XOVR_DIS);

  *pREG_PWM0_BCTL |= (ENUM_PWM_SYM_LO | ENUM_PWM_SYM_HI | ENUM_PWM_XOVR_DIS);

  *pREG_PWM0_CCTL |= (ENUM_PWM_SYM_LO | ENUM_PWM_SYM_HI | ENUM_PWM_XOVR_DIS);

 

  *pREG_PWM0_CHANCFG |= (ENUM_PWM_CHANCFG_REFTMRA_0 | ENUM_PWM_CHANCFG_LOA_INVHI | ENUM_PWM_CHANCFG_AH_ACTLO | ENUM_PWM_CHANCFG_CHOPAH_DIS | ENUM_PWM_CHANCFG_HPAH_DIS |

                         ENUM_PWM_CHANCFG_AL_ACTLO | ENUM_PWM_CHANCFG_CHOPAL_DIS);

 

  *pREG_PWM0_CHANCFG |= (ENUM_PWM_CHANCFG_REFTMRB_0 | ENUM_PWM_CHANCFG_LOB_INV | ENUM_PWM_CHANCFG_BH_ACTLO | ENUM_PWM_CHANCFG_CHOPBH_DIS | ENUM_PWM_CHANCFG_HPBH_DIS |

                         ENUM_PWM_CHANCFG_BL_ACTLO | ENUM_PWM_CHANCFG_CHOPBL_DIS);

 

  *pREG_PWM0_CHANCFG |= (ENUM_PWM_CHANCFG_REFTMRC_0 | ENUM_PWM_CHANCFG_LOC_INVHI | ENUM_PWM_CHANCFG_CH_ACTLO | ENUM_PWM_CHANCFG_CHOPCH_DIS | ENUM_PWM_CHANCFG_HPCH_DIS |

                         ENUM_PWM_CHANCFG_CL_ACTLO | ENUM_PWM_CHANCFG_CHOPCL_DIS);

 

  *pREG_PWM0_TRIPCFG |= (ENUM_PWM_TRIPCFG_TRIP0A_EN |ENUM_PWM_TRIPCFG_TRIP1A_EN | ENUM_PWM_TRIPCFG_TRIP0A_FLT | ENUM_PWM_TRIPCFG_TRIP1A_FLT) |

                        (ENUM_PWM_TRIPCFG_TRIP0B_EN |ENUM_PWM_TRIPCFG_TRIP1B_EN | ENUM_PWM_TRIPCFG_TRIP0B_FLT | ENUM_PWM_TRIPCFG_TRIP1B_FLT) |

                        (ENUM_PWM_TRIPCFG_TRIP0C_EN |ENUM_PWM_TRIPCFG_TRIP1C_EN | ENUM_PWM_TRIPCFG_TRIP0C_FLT | ENUM_PWM_TRIPCFG_TRIP1C_FLT);

 

  *pREG_PWM0_IMSK |= (ENUM_PWM_IMSK_TRIP0_UMSK | ENUM_PWM_IMSK_TRIP1_UMSK | ENUM_PWM_IMSK_PER0_UMSK);

 

  adi_int_InstallHandler((IRQn_Type)INTR_PWM0_TRIP, PWM0_TRIP_ISR, 0, true);

  NVIC_SetPriority((IRQn_Type)INTR_PWM0_TRIP, 1); 

  NVIC_EnableIRQ((IRQn_Type)INTR_TIMER0_TMR1);

 

  adi_int_InstallHandler((IRQn_Type)INTR_PWM0_SYNC, PWM0_SYNC_ISR, 0, true);

  NVIC_SetPriority((IRQn_Type)INTR_PWM0_SYNC, 0); 

  NVIC_EnableIRQ((IRQn_Type)INTR_PWM0_SYNC);

 

  *pREG_PWM0_ACTL |= (ENUM_PWM_HI_EN | ENUM_PWM_LO_EN);

  *pREG_PWM0_BCTL |= (ENUM_PWM_HI_EN | ENUM_PWM_LO_EN);

  *pREG_PWM0_CCTL |= (ENUM_PWM_HI_EN | ENUM_PWM_LO_EN);

 

  *pREG_PWM0_CTL |= ENUM_PWM_CTL_PWM_EN;

}

結果