<strike id="0k9r3"><p id="0k9r3"></p></strike>
  • <form id="0k9r3"></form>
    <nav id="0k9r3"></nav>
    <em id="0k9r3"><p id="0k9r3"></p></em>
  • <tr id="0k9r3"><source id="0k9r3"></source></tr>
    <form id="0k9r3"></form>
    <sub id="0k9r3"></sub>

      <sub id="0k9r3"><address id="0k9r3"></address></sub>
      1. <form id="0k9r3"></form>

        24小時聯系電話:18217114652、13661815404

        中文

        您當前的位置:
        首頁>
        電子資訊>
        技術專題>
        有關于UCOSIII無法進...

        技術專題

        有關于UCOSIII無法進入軟件計時器的某些函數且不報錯的情況


        發生這種情況的原因是由于定義的ucosiii自帶的軟件單次計時器錯誤的時間設置導致的,如下所示:

        圖中有兩個OS_TICK類型,單次計時器的定時時間應設置在第一個OS_TICK上。上面的是初始定時時間設置,可用于單次計時器周期計時器中;下面的是重裝載時間設置,用于僅周期定時器中。(之后在周期定時器的設置時將兩個參數都設置為0也無法正確觸發)

        //錯誤代碼OSTmrCreate((OS_TMR *)&tmra_20s, //定時器tmra_20s

                    (CPU_CHAR *)"tmra_20s", //定時器名字

                    (OS_TICK )0, //0ms

                    (OS_TICK )200,            //2000*10=20000ms=20s

                    (OS_OPT )OS_OPT_TMR_ONE_SHOT,  //單次定時器

                    (OS_TMR_CALLBACK_PTR)tmra_20s_callback,//定時器回調函數

                    (void    *)0, //參數為0

                    (OS_ERR    *)&err); //返回的錯誤碼//正確代碼OSTmrCreate((OS_TMR *)&tmra_20s, //定時器tmra_20s

                    (CPU_CHAR *)"tmra_20s", //定時器名字

                    (OS_TICK )200,               //2000*10=20000ms=20s

                    (OS_TICK )0, //0ms

                    (OS_OPT )OS_OPT_TMR_ONE_SHOT,  //單次定時器

                    (OS_TMR_CALLBACK_PTR)tmra_20s_callback,//定時器回調函數

                    (void    *)0, //參數為0

                    (OS_ERR    *)&err); //返回的錯誤碼

        以下是源代碼中關于ucosiii軟件計時器的描述。

        *************************************************************************************************************************                                                   CREATE A TIMER** Description: This function is called by your application code to create a timer.** Arguments  : p_tmr           Is a pointer to a timer control block**              p_name          Is a pointer to an ASCII string that is used to name the timer.  Names are useful for*                              debugging.**              dly             Initial delay.*                              If the timer is configured for ONE-SHOT mode, this is the timeout used*                              If the timer is configured for PERIODIC mode, this is the first timeout to wait for*                              before the timer starts entering periodic mode**              period          The 'period' being repeated for the timer.*                              If you specified 'OS_OPT_TMR_PERIODIC' as an option, when the timer expires, it will*                              automatically restart with the same period.**              opt             Specifies either:**                                  OS_OPT_TMR_ONE_SHOT       The timer counts down only once*                                  OS_OPT_TMR_PERIODIC       The timer counts down and then reloads itself**              p_callback      Is a pointer to a callback function that will be called when the timer expires.  The*                              callback function must be declared as follows:**                                  void  MyCallback (OS_TMR *p_tmr, void *p_arg);**              p_callback_arg  Is an argument (a pointer) that is passed to the callback function when it is called.**              p_err           Is a pointer to an error code.  '*p_err' will contain one of the following:**                                 OS_ERR_NONE*                                 OS_ERR_ILLEGAL_CREATE_RUN_TIME if you are trying to create the timer after you called*                                                                  OSSafetyCriticalStart().*                                 OS_ERR_OBJ_CREATED             if the timer has already been created*                                 OS_ERR_OBJ_PTR_NULL            is 'p_tmr' is a NULL pointer*                                 OS_ERR_OBJ_TYPE                if the object type is invalid*                                 OS_ERR_OPT_INVALID             you specified an invalid option*                                 OS_ERR_TMR_INVALID_DLY         you specified an invalid delay*                                 OS_ERR_TMR_INVALID_PERIOD      you specified an invalid period*                                 OS_ERR_TMR_ISR                 if the call was made from an ISR** Returns    : none** Note(s)    : 1) This function only creates the timer.  In other words, the timer is not started when created.  To*                 start the timer, call OSTmrStart().************************************************************************************************************************

        如果還有疑問可以參考詳細的關于定時器用法的中文描述:
        UCOSIII軟件計時器的使用

        2.有關于UCOSIII同一計時器的不同line的pwm輸出不能共存的情況

        發生這種情況的原因是由于定義初始化函數時加入了TIM_DeInit()函數導致的,如下所示:

        GPIO_InitTypeDef GPIO_InitStructure;

        TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

        TIM_OCInitTypeDef TIM_OCInitStructure;


        TIM_DeInit(TIM4);//把TIM4的設置清空


        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); 

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); 


        //設置該引腳為復用輸出功能,輸出TIM4,CH3的PWM脈沖波形

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 

        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

        GPIO_Init(GPIOB, &GPIO_InitStructure); 

        TIM_TimeBaseStructure.TIM_Period = arr; //設置在下一個更新事件裝入活動的自動重裝載寄存器周期

        TIM_TimeBaseStructure.TIM_Prescaler =psc; //設置用來作為TIMx時鐘頻率除數的預分頻值

        TIM_TimeBaseStructure.TIM_ClockDivision = 0; 

        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM向上計數模式

        TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); 

        TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //PWM模式1

        TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //比較輸出使能

        TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;//輸出極性:TIM輸出比較極性高

        TIM_OC3Init(TIM4, &TIM_OCInitStructure); //初始化外設TIM4

        TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable);//CH3預裝載使能

        TIM_Cmd(TIM4, ENABLE); //使能TIM3

        TIM_SetCompare3(TIM4, 0);*****************以下為部分TIM_DeInit()函數代碼**********************************void TIM_DeInit(TIM_TypeDef* TIMx){

          /* Check the parameters */

          assert_param(IS_TIM_ALL_PERIPH(TIMx)); 

         

          if (TIMx == TIM1)

          {

            RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, ENABLE);

            RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1, DISABLE);  

          }     

        TIM_DeInit(TIM4)初始化其他初始化函數中對于TIM4的設置清空,導致我們設置的其他通道的PWM設置被清空,因此無法在TIM4中輸出2個PWM信號。

        經過此次問題,我明白了每一個函數都要好好看清楚具體的功能作用,不能一抄了之,寫初始化函數的時候需要保證每一句都明白它的功能作用,不然會在后續的調試過程中產生隱患。

         

        請輸入搜索關鍵字

        確定
        国产在线视频在线