打印

求助:GD32E503的SHRTIMER故障输入保护求助

[复制链接]
1006|12
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
yuanlj1053|  楼主 | 2023-10-27 16:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如题,使用了超高分辨率定时器(SHRTIMER)来做逆变控制,箱使用定时器的故障输入功能,驱动波形有输出,但是保护功能没有实现,请问有没有大佬能帮忙看看定时器设置源代码哪里有问题。
void shrtimer_config(void)
{
/* -----------------------------------------------------------------------
    fSHRTIMER_CK:180MHz, from CK_SYS
    waveform period: 22500/(180M/4)=500us
    ST0_CH1_O: set request at Slave_TIMER0 period event, reset request at Slave_TIMER0 compare 0 event
  ----------------------------------------------------------------------- */
    shrtimer_baseinit_parameter_struct baseinit_para;
    shrtimer_timerinit_parameter_struct timerinit_para;
    shrtimer_timercfg_parameter_struct timercfg_para;
    shrtimer_comparecfg_parameter_struct comparecfg_para;
    shrtimer_channel_outputcfg_parameter_struct outcfg_para;
        shrtimer_deadtimecfg_parameter_struct deadtimecfg_para;   
       
    /* periodic DLL calibration */
    shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_16384_PERIOD);//配置和启动DLL校准
    while(RESET == shrtimer_common_flag_get(SHRTIMER0, SHRTIMER_FLAG_DLLCAL));//获取SHRTIMER通用标志  SHRTIMER_FLAG_DLLCAL=DLL 校准完成中断标志

       
    /* Slave_TIMER0 time base clock config  */
    shrtimer_baseinit_struct_para_init(&baseinit_para);//初始化结构体变量
    baseinit_para.period = 22500;//周期值 500uS 2KHz
    baseinit_para.prescaler = SHRTIMER_PRESCALER_DIV4;//预分频值
    baseinit_para.repetitioncounter = 0;//重复计数值
    baseinit_para.counter_mode = SHRTIMER_COUNTER_MODE_CONTINOUS;//计数器运行模式
       
        /**************定时器配置*************/
        shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_MASTER_TIMER, &baseinit_para);//
        shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &baseinit_para);//初始化Master_TIMER/Slave_TIMER时基
    shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, &baseinit_para);//
        shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &baseinit_para);//
       
        shrtimer_timerinit_struct_para_init(&timerinit_para);//初始化shrtimer_timerinit_parameter_struct结构体变量
   
        /*************MASTER_TIMER*************/
    timerinit_para.cnt_bunch = SHRTIMER_TIMERBUNCHNMODE_MAINTAINCLOCK;
    timerinit_para.dac_trigger = SHRTIMER_DAC_TRIGGER_NONE;
    timerinit_para.half_mode = SHRTIMER_HALFMODE_DISABLED;
    timerinit_para.repetition_update = SHRTIMER_UPDATEONREPETITION_DISABLED;
    timerinit_para.reset_sync = SHRTIMER_SYNCRESET_DISABLED;
    timerinit_para.shadow = SHRTIMER_SHADOW_DISABLED;
    timerinit_para.start_sync = SHRTIMER_SYNISTART_DISABLED;
    timerinit_para.update_selection = SHRTIMER_MT_ST_UPDATE_SELECTION_INDEPENDENT;
        shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_MASTER_TIMER, &timerinit_para);
       
    /*************SLAVE_TIMER*************/
    timerinit_para.cnt_bunch = SHRTIMER_TIMERBUNCHNMODE_MAINTAINCLOCK;
    timerinit_para.dac_trigger = SHRTIMER_DAC_TRIGGER_NONE;
    timerinit_para.half_mode = SHRTIMER_HALFMODE_DISABLED; //互补模式使能SHRTIMER_HALFMODE_ENABLED
    timerinit_para.repetition_update = SHRTIMER_UPDATEONREPETITION_DISABLED;
    timerinit_para.reset_sync = SHRTIMER_SYNCRESET_DISABLED;
    timerinit_para.shadow = SHRTIMER_SHADOW_DISABLED;
    timerinit_para.start_sync = SHRTIMER_SYNISTART_DISABLED;
    timerinit_para.update_selection = SHRTIMER_MT_ST_UPDATE_SELECTION_INDEPENDENT;//更新事件源选择
        shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &timerinit_para);
    shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, &timerinit_para);
        shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &timerinit_para);
       
        /*************配置Slave_TIMER的波形*************/
        //====SHRTIMER_MASTER_TIMER==================================
        shrtimer_timercfg_struct_para_init(&timercfg_para);
       
    timercfg_para.balanced_mode = SHRTIMER_STXBALANCEDMODE_DISABLED;//SHRTIMER_STXBALANCEDMODE_DISABLED;//使能或禁能均衡模式   
    timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_NONE;  //计数器复位源
    timercfg_para.deadtime_enable = SHRTIMER_STXDEADTIME_DISABLED;//使能或禁能死区功能
    timercfg_para.delayed_idle = SHRTIMER_STXDELAYED_IDLE_DISABLED;//延时空闲模式
    timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_NONE;//SHRTIMER_STXFAULTENABLE_NONE;//使能或禁能Slave_TIMER故障输入通道
    timercfg_para.fault_protect = SHRTIMER_STXFAULT_PROTECT_READWRITE;//SHRTIMER_STXFAULT_PROTECT_READWRITE;//使能或禁能故障保护功能
    timercfg_para.reset_update = SHRTIMER_STXUPDATEONRESET_DISABLED;//计数器复位产生更新事件
    timercfg_para.update_source = SHRTIMER_STXUPDATETRIGGER_NONE;//更新事件由其他定时器更新事件产生
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_MASTER_TIMER, &timercfg_para);
    //==========SHRTIMER_SLAVE_TIMER0=============
    timercfg_para.balanced_mode = SHRTIMER_STXBALANCEDMODE_DISABLED;//SHRTIMER_STXBALANCEDMODE_DISABLED;//使能或禁能均衡模式
    timercfg_para.deadtime_enable = SHRTIMER_STXDEADTIME_ENABLED; //死区使能
    timercfg_para.delayed_idle = SHRTIMER_STXDELAYED_IDLE_DISABLED;
    //timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_FAULT0;//SHRTIMER_STXFAULTENABLE_NONE;
    timercfg_para.fault_protect = SHRTIMER_STXFAULT_PROTECT_READONLY;//SHRTIMER_STXFAULT_PROTECT_READWRITE;
    timercfg_para.reset_update = SHRTIMER_STXUPDATEONRESET_DISABLED;
    timercfg_para.update_source = SHRTIMER_STXUPDATETRIGGER_NONE;
       
        timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_FAULT0;//使能或禁能Slave_TIMER故障输入通道;
    timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_MASTER_CMP0;  //这里设置从定时器起始计数点
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &timercfg_para);
   
        timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_FAULT1;//使能或禁能Slave_TIMER故障输入通道;
    timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_MASTER_CMP1;  //这里设置从定时器起始计数点
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, &timercfg_para);
  
    timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_FAULT2;//使能或禁能Slave_TIMER故障输入通道;
    timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_MASTER_CMP2;  //这里设置从定时器起始计数点
        shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &timercfg_para);

    //===配置主定时器的比较寄存器值======================
    shrtimer_mastertimer_compare_value_config(SHRTIMER0, SHRTIMER_COMPARE0, 80);  // CMP0 配置主定时器的比较寄存器值
    shrtimer_mastertimer_compare_value_config(SHRTIMER0, SHRTIMER_COMPARE1, 80);  // CMP1 配置主定时器的比较寄存器值
        shrtimer_mastertimer_compare_value_config(SHRTIMER0, SHRTIMER_COMPARE2, 80);  // CMP2 配置主定时器的比较寄存器值
        //死区配置//
        shrtimer_deadtimercfg_struct_para_init(&deadtimecfg_para);
    deadtimecfg_para.fallingsign_protect = SHRTIMER_DEADTIME_FALLINGSIGN_PROTECT_DISABLE;
    deadtimecfg_para.falling_protect = SHRTIMER_DEADTIME_FALLING_PROTECT_DISABLE;
    deadtimecfg_para.falling_sign = SHRTIMER_DEADTIME_FALLINGSIGN_POSITIVE;
    deadtimecfg_para.falling_value = 0x0080;//0x0020
    deadtimecfg_para.prescaler = SHRTIMER_DEADTIME_PRESCALER_MUL8;
    deadtimecfg_para.risingsign_protect = SHRTIMER_DEADTIME_RISINGSIGN_PROTECT_DISABLE;
    deadtimecfg_para.rising_protect = SHRTIMER_DEADTIME_RISING_PROTECT_DISABLE;
    deadtimecfg_para.rising_sign = SHRTIMER_DEADTIME_RISINGSIGN_POSITIVE;
    deadtimecfg_para.rising_value = 0x0080;
    shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &deadtimecfg_para);
        shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, &deadtimecfg_para);
        shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &deadtimecfg_para);
   
       
    shrtimer_comparecfg_struct_para_init(&comparecfg_para);
    comparecfg_para.compare_value = 100;//设置SLAVE_TIMER1/2的PWM比较值,没有实质作用,可以不定义。
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_COMPARE0, &comparecfg_para);
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, SHRTIMER_COMPARE0, &comparecfg_para);
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_COMPARE0, &comparecfg_para);
       
        /**************通道配置*************/
       
        shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
    outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;//使能或禁能载波模式
    outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;//在突发模式进入IDLE状态前是否插入死区时间
    outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_HIGHZ;//故障时通道输出状态;//故障时通道输出状态
    outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;//通道是否受突发模式控制
    outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;//通道输出的空闲状态
    outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;//通道输出极性
    outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_PER;//产生通道输出复位请求的事件
    outcfg_para.set_request = SHRTIMER_CHANNEL_SET_CMP0;    //产生通道输出置位请求的事件         
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_ST1_CH0, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_ST1_CH1, &outcfg_para);

    shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
    outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;
    outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;
    outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_HIGHZ;//故障时通道输出状态;//故障时通道输出状态
    outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;
    outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;
    outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;
    outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_PER;//产生通道输出复位请求的事件
    outcfg_para.set_request = SHRTIMER_CHANNEL_SET_CMP0;   //产生通道输出置位请求的事件         
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, SHRTIMER_ST1_CH0, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, SHRTIMER_ST1_CH1, &outcfg_para);

    shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
    outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;
    outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;
    outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_HIGHZ;//故障时通道输出状态;//故障时通道输出状态
    outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;
    outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;
    outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;
    outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_PER;//产生通道输出复位请求的事件
    outcfg_para.set_request = SHRTIMER_CHANNEL_SET_CMP0;//产生通道输出置位请求的事件
        shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_ST2_CH0, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_ST2_CH1, &outcfg_para);
   
    //====================================================================
        /* configure the fault input故障输入配置 */
    shrtimer_faultcfg_parameter_struct faultcfg_para;
    faultcfg_para.control = SHRTIMER_FAULT_CHANNEL_ENABLE;//使能或禁能故障输入
    faultcfg_para.filter = 0x0;//故障输入数字滤波,0x0~0xF
    faultcfg_para.polarity = SHRTIMER_FAULT_POLARITY_HIGH;//故障输入极性 SHRTIMER_FAULT_POLARITY_LOW
    faultcfg_para.protect = SHRTIMER_FAULT_PROTECT_ENABLE;//保护故障输入配置
    faultcfg_para.source = SHRTIMER_FAULT_SOURCE_PIN;//故障输入源
    shrtimer_fault_config(SHRTIMER0, SHRTIMER_FAULT_0, &faultcfg_para);
        shrtimer_fault_config(SHRTIMER0, SHRTIMER_FAULT_1, &faultcfg_para);
        shrtimer_fault_config(SHRTIMER0, SHRTIMER_FAULT_2, &faultcfg_para);
       
        shrtimer_fault_prescaler_config(SHRTIMER0, SHRTIMER_FAULT_PRESCALER_DIV1);
       
        shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_0);//故障输入使能
    shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_1);//故障输入使能
    shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_2);//故障输入使能
       
        //=========通道使能=========================================================
       
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST0_CH0);//通道ST0_CH0使能
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST0_CH1);//通道ST0_CH1使能

    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST1_CH0);//通道ST1_CH0使能
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST1_CH1);//通道ST1_CH1使能
       
        shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST2_CH0);//通道ST2_CH0使能
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST2_CH1);//通道ST2_CH1使能
   
         //=======定时器计数使能====================================================
    shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_MT_COUNTER);//定时器计数使能
    shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST0_COUNTER);
        shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST1_COUNTER);
        shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST2_COUNTER);
       
       
}

使用特权

评论回复
沙发
yuanlj1053|  楼主 | 2023-10-27 16:48 | 只看该作者
端口初始化代码:void gpio_config(void)
{
        //====未用端口设置====
        //gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);//PA12~15
        gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_13|GPIO_PIN_14);//PA13~14
       
        gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);//PB0~5
        //gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);//PB8~10
        gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_8|GPIO_PIN_9);//PB8~9
       
        gpio_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);//PC4~7
        gpio_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11);//PC8~11
        gpio_init(GPIOC, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_12|GPIO_PIN_13);//PC12~13
        gpio_init(GPIOD, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_11|GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
    gpio_init(GPIOE, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_8|GPIO_PIN_10);
    gpio_init(GPIOE, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_11);//以后用于速度编码器通道2
        gpio_init(GPIOE, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14);
        //====LED端口设置====
        gpio_init(GPIOE, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6);
        //====Di端口设置====
        gpio_init(GPIOD, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
       
        //====DO端口设置====
        gpio_init(GPIOD, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
       

        //电源硬件看门狗唤醒端口
        gpio_init(GPIOE, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
        //====发电PWM脉冲封锁信号
        gpio_init(GPIOE, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
       
        //====刹车端口
        gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_11);
        //刹车PWM脉冲封锁信号
        gpio_init(GPIOE, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_15);
       
    //SHRTIMER_ST0CH1 高精度PWM端口
         /*Configure PA8(TIMER0_CH0) as alternate function*/
        gpio_afio_port_config(AFIO_PA8_SHRTIMER_CFG, ENABLE);
    gpio_afio_port_config(AFIO_PA9_SHRTIMER_CFG, ENABLE);
        gpio_afio_port_config(AFIO_PA10_SHRTIMER_CFG, ENABLE);
        gpio_afio_port_config(AFIO_PA11_SHRTIMER_CFG, ENABLE);
    gpio_init(GPIOA,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11);
       
        gpio_afio_port_config(AFIO_PB12_SHRTIMER_CFG, ENABLE);
    gpio_afio_port_config(AFIO_PB13_SHRTIMER_CFG, ENABLE);
        gpio_afio_port_config(AFIO_PB14_SHRTIMER_CFG, ENABLE);
        gpio_afio_port_config(AFIO_PB15_SHRTIMER_CFG, ENABLE);
        gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15);
       
        //SHRTIMER故障输入
        gpio_afio_port_config(AFIO_PA12_SHRTIMER_CFG, ENABLE);
        gpio_afio_port_config(AFIO_PA15_SHRTIMER_CFG, ENABLE);
        gpio_afio_port_config(AFIO_PB10_SHRTIMER_CFG, ENABLE);
        gpio_init(GPIOA,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_12 | GPIO_PIN_15);//STFLT0 STFLT1
        gpio_init(GPIOB,GPIO_MODE_AF_PP,GPIO_OSPEED_50MHZ,GPIO_PIN_10);//STFLT2
       
        //AD采样端口
    gpio_init(GPIOA, GPIO_MODE_AIN, GPIO_OSPEED_MAX, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7);
        gpio_init(GPIOC, GPIO_MODE_AIN, GPIO_OSPEED_MAX, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
       
        //TIMER0捕获端口
        gpio_pin_remap_config(GPIO_TIMER0_FULL_REMAP,ENABLE);//GPIO_TIMER0_FULL_REMAP GPIO_TIMER0_PARTIAL_REMAP
        gpio_init(GPIOE, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_9);//gpio_init(GPIOE, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_9);       
        //rcu_periph_clock_enable(RCU_TIMER0);     //使能TIMER0时钟
        //gpio_init(GPIOE, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, GPIO_PIN_9);//?
       
        //外设端口的使用需要查询端口引脚的主功能、复用功能和映射功能,并按照功能进行处理
        gpio_pin_remap_config(GPIO_USART2_FULL_REMAP, ENABLE);
    // connect port to USARTx_Tx //
        gpio_init(GPIOD, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_8);//IO口复用 AFIO推挽输出模式
        // connect port to USARTx_Rx //
        gpio_init(GPIOD, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_9);//IO口配置 浮空输入模式
        //====RS485 T/R端口设置
        gpio_init(GPIOD, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
       
}

使用特权

评论回复
板凳
yuanlj1053|  楼主 | 2023-10-30 16:21 | 只看该作者
请各位大佬帮忙看看,为什么shrtimer的故障输入没办法起作用?

使用特权

评论回复
地板
yuanlj1053|  楼主 | 2023-10-30 16:21 | 只看该作者
   /* configure the fault input故障输入配置 */
    shrtimer_faultcfg_parameter_struct faultcfg_para;
    faultcfg_para.control = SHRTIMER_FAULT_CHANNEL_ENABLE;//使能或禁能故障输入
    faultcfg_para.filter = 0x0;//故障输入数字滤波,0x0~0xF
    faultcfg_para.polarity = SHRTIMER_FAULT_POLARITY_HIGH;//故障输入极性 SHRTIMER_FAULT_POLARITY_LOW
    faultcfg_para.protect = SHRTIMER_FAULT_PROTECT_ENABLE;//保护故障输入配置
    faultcfg_para.source = SHRTIMER_FAULT_SOURCE_PIN;//故障输入源
    shrtimer_fault_config(SHRTIMER0, SHRTIMER_FAULT_0, &faultcfg_para);
        shrtimer_fault_config(SHRTIMER0, SHRTIMER_FAULT_1, &faultcfg_para);
        shrtimer_fault_config(SHRTIMER0, SHRTIMER_FAULT_2, &faultcfg_para);
      
        shrtimer_fault_prescaler_config(SHRTIMER0, SHRTIMER_FAULT_PRESCALER_DIV1);
      
        shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_0);//故障输入使能
    shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_1);//故障输入使能
    shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_2);//故障输入使能

使用特权

评论回复
5
laocuo1142| | 2023-10-31 15:45 | 只看该作者
首先要做的是检查硬件是否有明显的损坏或异常。对于GD32E503的SHRTIMER故障输入保护,需要检查相关的线路、连接和元件是否有烧毁、断路或短路的情况。

使用特权

评论回复
6
laocuo1142| | 2023-10-31 15:45 | 只看该作者
电源波动或电源故障可能会触发GD32E503的保护机制。确保你的设备接收到稳定、合适的电源,并且电源电压在设备的工作范围内。

使用特权

评论回复
7
laocuo1142| | 2023-10-31 15:45 | 只看该作者
如果硬件检查没有问题,那么可能是软件或编程问题。你需要检查你的程序是否有错误,可能导致设备进入保护模式。

使用特权

评论回复
8
powerantone| | 2023-10-31 15:46 | 只看该作者
查阅GD32E503的数据手册

使用特权

评论回复
9
AloneKaven| | 2023-10-31 22:33 | 只看该作者
你的电源稳定吗

使用特权

评论回复
10
yuanlj1053|  楼主 | 2023-11-1 11:31 | 只看该作者
laocuo1142 发表于 2023-10-31 15:45
如果硬件检查没有问题,那么可能是软件或编程问题。你需要检查你的程序是否有错误,可能导致设备进入保护模 ...

现在的问题是不能进入故障保护,应该是设置问题,原先SHRTIMER_MASTER_TIMER不能进入周期中断,后来发现周期中断是SHRTIMER_MT_ST_INT_REP,而不是SHRTIMER_MT_ST_INT_UPD,修改后进能进入中断。
继续debug,看看哪里设置还有问题导致故障输入保护不起作用。

使用特权

评论回复
11
yuanlj1053|  楼主 | 2023-11-1 11:33 | 只看该作者

应该比较稳定,不是进入保护,而是将FAULT引脚拉高后,没有出现保护动作。

使用特权

评论回复
12
yuanlj1053|  楼主 | 2023-11-1 16:08 | 只看该作者
本帖最后由 yuanlj1053 于 2023-11-1 16:10 编辑

找到原因了,端口设置错误,晕死,应该设置成高阻输入模式,**能帮助到大家!
//SHRTIMER故障输入
        gpio_afio_port_config(AFIO_PA12_SHRTIMER_CFG, ENABLE);
        gpio_afio_port_config(AFIO_PA15_SHRTIMER_CFG, ENABLE);
        gpio_afio_port_config(AFIO_PB10_SHRTIMER_CFG, ENABLE);
        
        gpio_init(GPIOA,GPIO_MODE_IN_FLOATING,GPIO_OSPEED_50MHZ,GPIO_PIN_12 | GPIO_PIN_15);//STFLT0 STFLT1
        gpio_init(GPIOB,GPIO_MODE_IN_FLOATING,GPIO_OSPEED_50MHZ,GPIO_PIN_10);//STFLT2


下一步就是准备加入故障输入中断,GD32E503的例程太少了,什么都得自己磨!

使用特权

评论回复
13
yuanlj1053|  楼主 | 2023-11-1 16:11 | 只看该作者
希 望能帮到有需要的人,不用蒙头乱撞:
/**
    \brief      configure the SHRTIMER peripheral
    \param[in]  none
    \param[out] none
    \retval     none
周期中断就是重复中断SHRTIMER_MT_ST_INT_REP,不是更新中断用于周期寄存器重新设置
  */


void shrtimer_config(void)
{
/* -----------------------------------------------------------------------
    fSHRTIMER_CK:180MHz, from CK_SYS
    waveform period: 22500/(180M/1)=125us
    ST0_CH1_O: set request at Slave_TIMER0 period event, reset request at Slave_TIMER0 compare 0 event
  ----------------------------------------------------------------------- */
    shrtimer_baseinit_parameter_struct baseinit_para;
    shrtimer_timerinit_parameter_struct timerinit_para;
    shrtimer_timercfg_parameter_struct timercfg_para;
    shrtimer_comparecfg_parameter_struct comparecfg_para;
    shrtimer_channel_outputcfg_parameter_struct outcfg_para;
        shrtimer_deadtimecfg_parameter_struct deadtimecfg_para;   
        
    /* periodic DLL calibration */
    shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_ONCE);//配置和启动DLL校准 最好值设置一次校准,否则会出现丢波,上下管贯通
    while(RESET == shrtimer_common_flag_get(SHRTIMER0, SHRTIMER_FLAG_DLLCAL));//获取SHRTIMER通用标志  SHRTIMER_FLAG_DLLCAL=DLL 校准完成中断标志
    //shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_ONCE);//只校准一次,否则会出现周期丢波的错误
        
    /* Slave_TIMER0 time base clock config  */
    shrtimer_baseinit_struct_para_init(&baseinit_para);//初始化结构体变量
    baseinit_para.period = 22500;//周期值 500uS 2KHz
    baseinit_para.prescaler = SHRTIMER_PRESCALER_DIV1;//预分频值
    baseinit_para.repetitioncounter = 0;//重复计数值
    baseinit_para.counter_mode = SHRTIMER_COUNTER_MODE_CONTINOUS;//计数器运行模式
        /**************定时器配置*************/
        shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_MASTER_TIMER, &baseinit_para);//
        shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &baseinit_para);//初始化Master_TIMER/Slave_TIMER时基
    shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, &baseinit_para);//
        shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &baseinit_para);//
        
        
        shrtimer_timerinit_struct_para_init(&timerinit_para);//初始化shrtimer_timerinit_parameter_struct结构体变量
        /*************MASTER_TIMER*************/
    timerinit_para.cnt_bunch = SHRTIMER_TIMERBUNCHNMODE_MAINTAINCLOCK;//突发模式下计数器时钟停止或者正常运行   
    timerinit_para.dac_trigger = SHRTIMER_DAC_TRIGGER_NONE; //DAC触发源
    timerinit_para.half_mode = SHRTIMER_HALFMODE_DISABLED;//使能或禁能半波模式
   
   ////
        timerinit_para.repetition_update = SHRTIMER_UPDATEONREPETITION_ENABLED;//SHRTIMER_UPDATEONREPETITION_DISABLED;//重复事件产生更新事件
   
        timerinit_para.reset_sync = SHRTIMER_SYNCRESET_DISABLED;//同步输入复位计数器
    timerinit_para.shadow = SHRTIMER_SHADOW_DISABLED;//使能或者禁能影子寄存器
    timerinit_para.start_sync = SHRTIMER_SYNISTART_DISABLED;//同步输入启动计数器
    timerinit_para.update_selection = SHRTIMER_STXUPDATETRIGGER_MASTER;//SHRTIMER_STXUPDATETRIGGER_NONE;//SHRTIMER_MT_ST_UPDATE_SELECTION_INDEPENDENT;//更新事件源选择
        shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_MASTER_TIMER, &timerinit_para);
        
        
    /*************SLAVE_TIMER*************/
    timerinit_para.cnt_bunch = SHRTIMER_TIMERBUNCHNMODE_MAINTAINCLOCK;
    timerinit_para.dac_trigger = SHRTIMER_DAC_TRIGGER_NONE;
    timerinit_para.half_mode = SHRTIMER_HALFMODE_DISABLED; //互补模式使能
    timerinit_para.repetition_update = SHRTIMER_UPDATEONREPETITION_DISABLED;
    timerinit_para.reset_sync = SHRTIMER_SYNCRESET_DISABLED;
    timerinit_para.shadow = SHRTIMER_SHADOW_DISABLED;
    timerinit_para.start_sync = SHRTIMER_SYNISTART_DISABLED;
    timerinit_para.update_selection = SHRTIMER_STXUPDATETRIGGER_NONE;//SHRTIMER_MT_ST_UPDATE_SELECTION_INDEPENDENT;//更新事件源选择
        
        shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &timerinit_para);
    shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, &timerinit_para);
        shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &timerinit_para);
        
        /*************配置Slave_TIMER的波形*************/
        //====SHRTIMER_MASTER_TIMER==================================
        shrtimer_timercfg_struct_para_init(&timercfg_para);
        
    timercfg_para.balanced_mode = SHRTIMER_STXBALANCEDMODE_DISABLED;//禁能均衡模式   
    /////////
        timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_UPDATE;//SHRTIMER_STXCNT_RESET_NONE;  //计数器复位源
   
        timercfg_para.deadtime_enable = SHRTIMER_STXDEADTIME_DISABLED;//使能或禁能死区功能
    timercfg_para.delayed_idle = SHRTIMER_STXDELAYED_IDLE_DISABLED;//延时空闲模式
    timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_FAULT0;//SHRTIMER_STXFAULTENABLE_NONE//SHRTIMER_STXFAULTENABLE_FAULT0;//使能或禁能Slave_TIMER故障输入通道
    timercfg_para.fault_protect = SHRTIMER_STXFAULT_PROTECT_READWRITE;//SHRTIMER_STXFAULT_PROTECT_READONLY;//使能或禁能故障保护功能
   
   //////
    timercfg_para.reset_update = SHRTIMER_STXUPDATEONRESET_ENABLED;//SHRTIMER_STXUPDATEONRESET_DISABLED;//计数器复位产生更新事件
    timercfg_para.update_source = SHRTIMER_STXUPDATETRIGGER_NONE;//更新事件由其他定时器更新事件产生
   
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_MASTER_TIMER, &timercfg_para);
   
   
    //==========SHRTIMER_SLAVE_TIMER0=============
    timercfg_para.balanced_mode = SHRTIMER_STXBALANCEDMODE_DISABLED;//使能或禁能均衡模式
    timercfg_para.deadtime_enable = SHRTIMER_STXDEADTIME_ENABLED; //死区使能
    timercfg_para.delayed_idle = SHRTIMER_STXDELAYED_IDLE_DISABLED;
    //timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_FAULT0;//SHRTIMER_STXFAULTENABLE_NONE;
    timercfg_para.fault_protect = SHRTIMER_STXFAULT_PROTECT_READWRITE;//SHRTIMER_STXFAULT_PROTECT_READONLY;//SHRTIMER_STXFAULT_PROTECT_READONLY;//
    timercfg_para.reset_update = SHRTIMER_STXUPDATEONRESET_DISABLED;
    timercfg_para.update_source = SHRTIMER_STXUPDATETRIGGER_NONE;
        
        timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_FAULT0;//使能或禁能Slave_TIMER故障输入通道;
    timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_MASTER_CMP0;  //这里设置从定时器起始计数点
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &timercfg_para);
   
        timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_FAULT1;//使能或禁能Slave_TIMER故障输入通道;
    timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_MASTER_CMP1;  //这里设置从定时器起始计数点 SHRTIMER_STXCNT_RESET_NONE
    shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, &timercfg_para);
  
    timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_FAULT2;//使能或禁能Slave_TIMER故障输入通道;
    timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_MASTER_CMP2;  //这里设置从定时器起始计数点
        shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &timercfg_para);

    //===配置主定时器的比较寄存器值======================
    shrtimer_mastertimer_compare_value_config(SHRTIMER0, SHRTIMER_COMPARE0, 80);  // CMP0 配置主定时器的比较寄存器值
    shrtimer_mastertimer_compare_value_config(SHRTIMER0, SHRTIMER_COMPARE1, 80);  // CMP1 配置主定时器的比较寄存器值
        shrtimer_mastertimer_compare_value_config(SHRTIMER0, SHRTIMER_COMPARE2, 80);  // CMP2 配置主定时器的比较寄存器值
        //死区配置//
        shrtimer_deadtimercfg_struct_para_init(&deadtimecfg_para);
    deadtimecfg_para.fallingsign_protect = SHRTIMER_DEADTIME_FALLINGSIGN_PROTECT_DISABLE;
    deadtimecfg_para.falling_protect = SHRTIMER_DEADTIME_FALLING_PROTECT_DISABLE;
    deadtimecfg_para.falling_sign = SHRTIMER_DEADTIME_FALLINGSIGN_POSITIVE;
    deadtimecfg_para.falling_value = 0x0080;//0x0020
    deadtimecfg_para.prescaler = SHRTIMER_DEADTIME_PRESCALER_MUL8;
    deadtimecfg_para.risingsign_protect = SHRTIMER_DEADTIME_RISINGSIGN_PROTECT_DISABLE;
    deadtimecfg_para.rising_protect = SHRTIMER_DEADTIME_RISING_PROTECT_DISABLE;
    deadtimecfg_para.rising_sign = SHRTIMER_DEADTIME_RISINGSIGN_POSITIVE;
    deadtimecfg_para.rising_value = 0x0080;
    shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &deadtimecfg_para);
        shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, &deadtimecfg_para);
        shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, &deadtimecfg_para);
   
        /*************设置SLAVE_TIMER0/1/2的PWM比较值,没有实质作用,可以不定义*************/
    shrtimer_comparecfg_struct_para_init(&comparecfg_para);
    comparecfg_para.compare_value = 100;
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_COMPARE0, &comparecfg_para);
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, SHRTIMER_COMPARE0, &comparecfg_para);
    shrtimer_slavetimer_waveform_compare_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_COMPARE0, &comparecfg_para);
        
        /**************通道配置*************/
        
        shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
    outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;//使能或禁能载波模式
    outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;//在突发模式进入IDLE状态前是否插入死区时间
   
    outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_HIGHZ;//SHRTIMER_CHANNEL_FAULTSTATE_HIGHZ;//故障时通道输出状态;//故障时通道输出状态
   
        outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;//通道是否受突发模式控制
    outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;//通道输出的空闲状态
    outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;//通道输出极性
    outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_PER;//产生通道输出复位请求的事件
    outcfg_para.set_request = SHRTIMER_CHANNEL_SET_CMP0;    //SHRTIMER_SLAVE_TIMER0.CMP0产生通道输出置位请求的事件 SHRTIMER_CHANNEL_SET_UPDATE        
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_ST1_CH0, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, SHRTIMER_ST1_CH1, &outcfg_para);

    shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
    outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;
    outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;
   
    outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_HIGHZ;//SHRTIMER_CHANNEL_FAULTSTATE_INACTIVE
    //INACTIVE=0  ACTIVE=1  HIGHZ
    //outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_HIGHZ;//故障时通道输出状态;//故障时通道输出状态
   
        outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;
    outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;
    outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;
    outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_PER;//产生通道输出复位请求的事件
    outcfg_para.set_request = SHRTIMER_CHANNEL_SET_CMP0;   //SHRTIMER_SLAVE_TIMER1.CMP0产生通道输出置位请求的事件         
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, SHRTIMER_ST1_CH0, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER1, SHRTIMER_ST1_CH1, &outcfg_para);

    shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
    outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;
    outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;
   
    outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_HIGHZ;//故障时通道输出状态;SHRTIMER_CHANNEL_FAULTSTATE_HIGHZ
   
    outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;
    outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;
    outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;
    outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_PER;//产生通道输出复位请求的事件
    outcfg_para.set_request = SHRTIMER_CHANNEL_SET_CMP0;//SHRTIMER_SLAVE_TIMER2.CMP0产生通道输出置位请求的事件
        shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_ST2_CH0, &outcfg_para);
    shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER2, SHRTIMER_ST2_CH1, &outcfg_para);
   
    //====================================================================
        
        /* configure the fault input故障输入配置 */
   
    shrtimer_faultcfg_parameter_struct faultcfg_para;
    shrtimer_faultcfg_struct_para_init (&faultcfg_para);
        
    faultcfg_para.control = SHRTIMER_FAULT_CHANNEL_ENABLE;//使能或禁能故障输入
    faultcfg_para.filter = 0x0;//故障输入数字滤波,0x0~0xF
    faultcfg_para.polarity = SHRTIMER_FAULT_POLARITY_HIGH;//故障输入极性 SHRTIMER_FAULT_POLARITY_LOW
    faultcfg_para.protect = SHRTIMER_FAULT_PROTECT_ENABLE;//保护故障输入配置
    faultcfg_para.source = SHRTIMER_FAULT_SOURCE_PIN;//故障输入源 hrtim
   
    shrtimer_fault_config(SHRTIMER0, SHRTIMER_FAULT_0, &faultcfg_para);
        shrtimer_fault_config(SHRTIMER0, SHRTIMER_FAULT_1, &faultcfg_para);
        shrtimer_fault_config(SHRTIMER0, SHRTIMER_FAULT_2, &faultcfg_para);
        
        shrtimer_fault_prescaler_config(SHRTIMER0, SHRTIMER_FAULT_PRESCALER_DIV1);
        
        shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_0);//故障输入使能
    shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_1);//故障输入使能
    shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_2);//故障输入使能
        
        //shrtimer_common_interrupt_enable(SHRTIMER0,SHRTIMER_INT_FLAG_FLT0);// SHRTIMER_INT_FLT0 SHRTIMER_INT_FLAG_FLT0
        //shrtimer_common_interrupt_enable(SHRTIMER0,SHRTIMER_INT_FLAG_FLT1);
        //shrtimer_common_interrupt_enable(SHRTIMER0,SHRTIMER_INT_FLAG_FLT2);
        //nvic_irq_enable(SHRTIMER_IRQ0_IRQn, 0, 4);//开启中断向量(调用处理函数名)

   
        /* clear the Master_TIMER and Slave_TIMER interrupt flag */
    shrtimer_timers_interrupt_flag_clear(SHRTIMER0, SHRTIMER_MASTER_TIMER, SHRTIMER_MT_ST_INT_REP);
        /* enable the Master_TIMER and Slave_TIMER interrupt SHRTIMER_SLAVE_TIMER0*/
        shrtimer_timers_interrupt_enable(SHRTIMER0,SHRTIMER_MASTER_TIMER , SHRTIMER_MT_ST_INT_REP);//SHRTIMER_ST_INT_CAP0
        //shrtimer_timers_interrupt_enable(SHRTIMER0,SHRTIMER_SLAVE_TIMER0 , SHRTIMER_MT_ST_INT_CMP0);//SHRTIMER_ST_INT_CAP0
        //shrtimer_timers_interrupt_enable(SHRTIMER0,SHRTIMER_SLAVE_TIMER1 , SHRTIMER_MT_ST_INT_CMP0)//SHRTIMER_MT_ST_INT_CMP0
        //shrtimer_timers_interrupt_enable(SHRTIMER0,SHRTIMER_SLAVE_TIMER2 , SHRTIMER_MT_ST_INT_CMP0)//SHRTIMER_MT_ST_INT_CMP0
        
        /* enable NVIC request */
    nvic_irq_enable(SHRTIMER_IRQ0_IRQn, 0U, 0U);
        //nvic_irq_enable(SHRTIMER_IRQ1_IRQn, 0U, 2U);
        //nvic_irq_enable(SHRTIMER_IRQ2_IRQn, 0U, 1U);
        //nvic_irq_enable(SHRTIMER_IRQ3_IRQn, 0U, 3U);
        
        
        //=========通道使能=========================================================
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST0_CH0);//通道ST0_CH0使能
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST0_CH1);//通道ST0_CH1使能

    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST1_CH0);//通道ST1_CH0使能
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST1_CH1);//通道ST1_CH1使能
        
        shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST2_CH0);//通道ST2_CH0使能
    shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST2_CH1);//通道ST2_CH1使能
         //=======定时器计数使能====================================================
    shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_MT_COUNTER);//定时器计数使能
    shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST0_COUNTER);
        shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST1_COUNTER);
        shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_ST2_COUNTER);
        
}

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

9

帖子

0

粉丝