2020-10-12 07:31 AM
#define HRTIM_BASE_ADD (uint32_t)0x40016800
#define HRTIM_FLTINR1_ADD ((uint32_t*)(HRTIM_BASE_ADD+0x3D0))
#define HRTIM_FLTINR2_ADD ((uint32_t*)(HRTIM_BASE_ADD+0x3D4))
#define HRTIM_FLTFR_ADD ((uint32_t*)(HRTIM_BASE_ADD+ 0x368))
void ahb_timer_init(void) {
LL_GPIO_InitTypeDef GPIO_InitStruct = { 0 };
/* Peripheral clock enable */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_HRTIM1);
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOC);
LL_HRTIM_ConfigDLLCalibration(HRTIM1, LL_HRTIM_DLLCALIBRATION_MODE_CONTINUOUS, LL_HRTIM_DLLCALIBRATION_RATE_3);
/**HRTIM1 GPIO Configuration
PA12 ------> HRTIM1_FLT1
PC10 ------> HRTIM1_FLT6
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_12;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_13;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = LL_GPIO_PIN_10;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_13;
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
//......
//......
//FLT1 = FLT input pin
LL_HRTIM_FLT_SetPrescaler(HRTIM1, LL_HRTIM_FLT_PRESCALER_DIV1);
LL_HRTIM_FLT_SetSrc(HRTIM1, LL_HRTIM_FAULT_1, LL_HRTIM_FLT_SRC_DIGITALINPUT);
LL_HRTIM_FLT_SetPolarity(HRTIM1, LL_HRTIM_FAULT_1, LL_HRTIM_FLT_POLARITY_LOW);
LL_HRTIM_FLT_SetFilter(HRTIM1, LL_HRTIM_FAULT_1, LL_HRTIM_FLT_FILTER_NONE);
LL_HRTIM_FLT_SetBlankingSrc(HRTIM1, LL_HRTIM_FAULT_1, LL_HRTIM_FLT_BLANKING_RSTALIGNED);
LL_HRTIM_FLT_SetCounterThreshold(HRTIM1, LL_HRTIM_FAULT_1, 0);
LL_HRTIM_FLT_SetResetMode(HRTIM1, LL_HRTIM_FAULT_1, LL_HRTIM_FLT_COUNTERRST_UNCONDITIONAL);
LL_HRTIM_FLT_EnableBlanking(HRTIM1, LL_HRTIM_FAULT_1);
LL_HRTIM_FLT_Enable(HRTIM1, LL_HRTIM_FAULT_1);
//FLT6 = FLT input pin
LL_HRTIM_FLT_SetBlankingSrc(HRTIM1, LL_HRTIM_FAULT_6, LL_HRTIM_FLT_BLANKING_RSTALIGNED);
LL_HRTIM_FLT_SetCounterThreshold(HRTIM1, LL_HRTIM_FAULT_6, 0);
LL_HRTIM_FLT_SetResetMode(HRTIM1, LL_HRTIM_FAULT_6, LL_HRTIM_FLT_COUNTERRST_UNCONDITIONAL);
LL_HRTIM_FLT_EnableBlanking(HRTIM1, LL_HRTIM_FAULT_6);
// LL_HRTIM_FLT_SetSrc(HRTIM1, LL_HRTIM_FAULT_6, LL_HRTIM_FLT_SRC_DIGITALINPUT);
*HRTIM_FLTINR2_ADD &= ~0x400; //bit10 FLT2 SRC[0] set 0
*HRTIM_FLTINR2_ADD &= ~0x200000; //bit21 FLT2 SRC[0] set 0
LL_HRTIM_FLT_SetPolarity(HRTIM1, LL_HRTIM_FAULT_6, LL_HRTIM_FLT_POLARITY_LOW);
LL_HRTIM_FLT_SetFilter(HRTIM1, LL_HRTIM_FAULT_6, LL_HRTIM_FLT_FILTER_NONE);
LL_HRTIM_FLT_Enable(HRTIM1, LL_HRTIM_FAULT_6);
LL_HRTIM_TIM_EnableFault(HRTIM1, LL_HRTIM_TIMER_F, LL_HRTIM_FAULT_1|LL_HRTIM_FAULT_6);
//......
//......
LL_HRTIM_OUT_SetFaultState(HRTIM1, LL_HRTIM_OUTPUT_TF1, LL_HRTIM_OUT_FAULTSTATE_INACTIVE);
LL_HRTIM_OUT_SetFaultState(HRTIM1, LL_HRTIM_OUTPUT_TF2, LL_HRTIM_OUT_FAULTSTATE_INACTIVE);
//......
//......
LL_HRTIM_TIM_CounterEnable(HRTIM1, LL_HRTIM_TIMER_F);
LL_HRTIM_EnableOutput(HRTIM1, LL_HRTIM_OUTPUT_TF1);
LL_HRTIM_EnableOutput(HRTIM1, LL_HRTIM_OUTPUT_TF2);
LL_HRTIM_EnableIT_FLT1(HRTIM1);
LL_HRTIM_EnableIT_FLT6(HRTIM1);
}
/**
* @brief This function handles HRTIM fault global interrupt.
*/
void HRTIM1_FLT_IRQHandler(void)
{
if (LL_HRTIM_IsActiveFlag_FLT6(HRTIM1)) {
LED4_on();
LL_HRTIM_ClearFlag_FLT6(HRTIM1);
}
if (LL_HRTIM_IsActiveFlag_FLT1(HRTIM1)) {
LED1_on();
LL_HRTIM_ClearFlag_FLT1(HRTIM1);
}
}
HRTIM Fault 1 and 6 both intern pull up, Low active. Fault 1 works normal, Fault 5 not working properly. If the pin of fault 6 is low (fault active) before mcu power on, then after power on, led 4 is on, and the pwm signal is off. If the pin of fault 6 is high (fault diactive) before mcu power on, then after power on, led 4 is off, and the pwm signal is on. BUT, after power on, set the pegel of 6 from high to low (diactive to active) can not shut down the pwm, and the led 4 is always off. The interrupt is also not be called. it seems that fault 6 works normally only at the moment of power-on.