發表文章

freeRTOS The Idle Task and the Idle Task Hook

Idle Task  There must always be at least one task that can enter the Running state. To ensure this is the case, an Idle task is automatically created by the scheduler when vTaskStartScheduler() is called. The idle task does very little more than sit in a loop—it is always able to run. The idle task has the lowest possible priority ( priority zero ), to ensure it never prevents a higher priority application task from entering the Running state—although there is nothing to prevent application designers creating tasks at, and therefore sharing, the idle task priority, if desired. Note: If an application uses the vTaskDelete() API function then it is essential that the Idle task is not starved of processing time. This is because the Idle task is responsible for cleaning up kernel resources after a task has been deleted. Idle Task Hook Functions It is possible to add application specific functionality directly into the idle task through the use of an idle hook (or idle cal...

freeRTOS Time Measurement

Time Measurement time slicing : In the examples, both tasks were created at the same priority, and both tasks were always able to run. Therefore, each task executed for a ‘time slice’, entering the Running state at the start of a time slice, and exiting the Running state at the end of a time slice. The length of the time slice is effectively set by the tick interrupt frequency, which is configured by the application-defined configTICK_RATE_HZ For example, if configTICK_RATE_HZ is set to 100 (Hz), then the time slice will be 10 milliseconds. The time between two tick interrupts is called the ‘tick period’. One time slice equals one tick period. FreeRTOS API calls always specify time in multiples of tick periods,  which are often referred to simply as ‘ticks’. The pdMS_TO_TICKS() macro converts a time specified in milliseconds into a time specified in ticks. pdMS_TO_TICKS() cannot be used if the tick frequency is above 1KHz (if configTICK_RATE_HZ is greater than 1...

freeRTOS Task Function

freeRTOS Task Function Each task is a small program in its own right. It has an entry point, will normally run forever within an infinite loop, and will not exit. FreeRTOS tasks must not be allowed to return from their implementing function in any way—they must not contain a ‘return’ statement and must not be allowed to execute past the end of the function. (必需要是無限迴圈) If a task is no longer required, it should instead be explicitly deleted. A single task function definition can be used to create any number of tasks—each created task being a separate execution instance, with its own stack and its own copy of any automatic (stack) variables defined within the task itself. (每個task都有自己的記憶體塊和自己的變數) Function The xTaskCreate() API Function Tasks are created using the FreeRTOS xTaskCreate() API function. BaseType_t xTaskCreate( TaskFunction_t pvTaskCode, const char * const pcName, uint16_t usStackDepth, void *pvParameters, UBaseType_t uxPriority, TaskHandle_t *pxCreatedTas...

DC motor control project part2 Initsys.c & Initsys.h

Initsys程式包含main.c用到的各種function Initsys.c ======================================================================== 標頭檔 #include "stm32f4xx.h" #include "Initsys.h" #include "stm32f4xx_gpio.h" #include "stm32f4xx_rcc.h" 全域變數 TIM_OCInitTypeDef TIM_OCStruct; -------------------------------------------------------------------------------------------------------- delay_ms呼叫此函數可以讓系統暫停輸入值的mini second void delay_ms(uint32_t nms){      volatile uint32_t temp,tempval;     SysTick->LOAD=(uint32_t)nms*21000; //168000000/8 SysTick->VAL =0x00;            SysTick->CTRL=0x01 ;    do { temp=SysTick->CTRL; tempval=SysTick->VAL; } while(temp==1);   SysTick->CTRL=0x00;        SysTick->VAL =0X00;             } -------------------------------------------------------------------------------------------...

DC Motor control project part1 main.c

圖片
因為不知道馬達何時開始轉動,所以使用External interrupt來讀取編碼器的數值 STM32F407VG的External interrupt 有16條線分別對應pin腳的數字。 選擇PD0和PD1作為我的外部中斷腳位 選擇好要使用的pin腳後接下來要設定interrupt handlers設定方法為如下表格 IRQ                         |        Handler                             |      註解 EXTI0_IRQn          |        EXTI0_IRQHandler         |      EXIT line 0的Handler  EXTI1_IRQn          |        EXTI1_IRQHandler         |      EXIT line 1的Handler  EXTI2_IRQn          |        EXTI2_IRQHandler         |      EXIT line 2的Handler  EXTI3_IRQn          |...