• <noframes id="6fok0"><bdo id="6fok0"><listing id="6fok0"></listing></bdo>
    <ruby id="6fok0"></ruby>

    <progress id="6fok0"></progress>
  • <progress id="6fok0"></progress>
    <ruby id="6fok0"><table id="6fok0"></table></ruby>
  • <progress id="6fok0"><u id="6fok0"><form id="6fok0"></form></u></progress>

    24小時(shí)聯(lián)系電話(huà):18217114652、13661815404

    中文

    您當前的位置:
    首頁(yè)>
    電子資訊>
    技術(shù)專(zhuān)題>
    有關(guān)于UCOSIII無(wú)法進(jìn)...

    技術(shù)專(zhuān)題

    有關(guān)于UCOSIII無(wú)法進(jìn)入軟件計時(shí)器的某些函數且不報錯的情況


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

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

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

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

                (OS_TICK )0, //0ms

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

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

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

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

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

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

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

                (OS_TICK )0, //0ms

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

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

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

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

    以下是源代碼中關(guān)于ucosiii軟件計時(shí)器的描述。

    *************************************************************************************************************************                                                   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().************************************************************************************************************************

    如果還有疑問(wèn)可以參考詳細的關(guān)于定時(shí)器用法的中文描述:
    UCOSIII軟件計時(shí)器的使用

    2.有關(guān)于UCOSIII同一計時(shí)器的不同line的pwm輸出不能共存的情況

    發(fā)生這種情況的原因是由于定義初始化函數時(shí)加入了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; //設置在下一個(gè)更新事件裝入活動(dòng)的自動(dòng)重裝載寄存器周期

    TIM_TimeBaseStructure.TIM_Prescaler =psc; //設置用來(lái)作為T(mén)IMx時(shí)鐘頻率除數的預分頻值

    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設置被清空,因此無(wú)法在TIM4中輸出2個(gè)PWM信號。

    經(jīng)過(guò)此次問(wèn)題,我明白了每一個(gè)函數都要好好看清楚具體的功能作用,不能一抄了之,寫(xiě)初始化函數的時(shí)候需要保證每一句都明白它的功能作用,不然會(huì )在后續的調試過(guò)程中產(chǎn)生隱患。

     

    請輸入搜索關(guān)鍵字

    確定
    色鲁99热99re超碰精品_91精品一区二区三区无码吞精_亚洲国产欧洲综合997久久_一级a性色生活片久久无
  • <noframes id="6fok0"><bdo id="6fok0"><listing id="6fok0"></listing></bdo>
    <ruby id="6fok0"></ruby>

    <progress id="6fok0"></progress>
  • <progress id="6fok0"></progress>
    <ruby id="6fok0"><table id="6fok0"></table></ruby>
  • <progress id="6fok0"><u id="6fok0"><form id="6fok0"></form></u></progress>