More Related Content
Similar to STM32F4 for 智慧型電動輪椅系統Part1
Similar to STM32F4 for 智慧型電動輪椅系統Part1 (20)
STM32F4 for 智慧型電動輪椅系統Part1
- 2. 智慧型電動輪椅系統架構
USB Morse
code device
Nipple
Tablet PC
Image display
Information by EPW
EPW Control Panal
STM32F407
(ARM Cortex-M4)
Motor
Controller
Linear
Actuator
BeagleBoard-xM
(ARM Cortex A8 + C64x DSP dual core)
Webcam
Wi-Fi
Adapter
Wi-Fi
- 10. 先了解其特質
• ⼀一旦宣告後,就⼀一直存放在記憶體,不會隨著函數結束後⽽而釋放
在函數本體內(in Function Block),⼀一個被宣告為靜態的變數,
在這⼀一函數被呼叫過程中維持其值不變
• ⼀一個static函數表⽰示,其可以呼叫的範圍限於該原始碼⽂文件之中
在⼀一個Block(ie. {...} )內 (但在函數體外),⼀一個被宣告為靜態的變數
可以被Block內所有的函數存取,但不能被Block外的其它函數存取。
它是⼀一個區域裡⾯面的全局變數。
- 11. • local variable 只在 { } 區間內有效,過了即消失。它
的壽命就只有在進⼊入區間內到離開區間前。
• Static local variable 的壽命跟 global variable ⼀一樣
⻑⾧長,但是只在宣告的 { }區間內是可視的。
void foo()
{
static count = 0; //只會被初始化⼀一次
count++;
}
- 13. Critical Section
void Calculate_motor_rpm(void)
{
void EXTI0_IRQHandler(){
encoder_left_counter++ ;
}
detachInterrupt(EXTI_Line0); /*close external interrupt 0*/
!
rpm_left_motor=encoder_left_counter * (2.0f/3.0f)* 60.0f /500.0f;
!
attachInterrupt(EXTI_Line0);
ISR
Critical Section
- 21. Polling in FreeRTOS(1/2)
xTimerHandle PID_Timers;
PID_Timers=xTimerCreate(“PID_Algorithm_Polling Start”, 20, pdTRUE,
( void * ) 1, PID_Algorithm_Polling);
xTimerStart( PID_Timers, 0 );
void PID_Algorithm_Polling(void)
{
….
}
step1
step3
step2
- 22. Polling in FreeRTOS(2/2)
in timers.h:
!
xTimerCreate ( const char * const pcTimerName,
const TickType_t xTimerPeriod,
const UBaseType_t uxAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction );
more info. xTimerCreate Paremeters
- 24. method 1 :
while (ReadGPIO(echo_pin) == 1) {
duration++;
delay_us(1);
};
若被其他執⾏行緒搶⾛走,
時間計算還會對嗎?
subtract
method 2 : Timer
Timer interrupt(Risig) Timer interrupt(Faling)