stm32f4 for 智慧型電動輪椅系統part1
DESCRIPTION
暑期課程TRANSCRIPT
![Page 2: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/2.jpg)
智慧型電動輪椅系統架構
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
![Page 3: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/3.jpg)
Embedded System
主微控制器(BeagleBoard-xM) 次微控制器(STM32F407)
![Page 4: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/4.jpg)
Demo
![Page 5: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/5.jpg)
![Page 6: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/6.jpg)
Filesystem
![Page 7: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/7.jpg)
![Page 8: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/8.jpg)
• The library for Smart EPW
![Page 9: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/9.jpg)
static 適⽤用時機?
![Page 10: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/10.jpg)
先了解其特質• ⼀一旦宣告後,就⼀一直存放在記憶體,不會隨著函數結束後⽽而釋放
• ⼀一個static函數表⽰示,其可以呼叫的範圍限於該原始碼⽂文件之中
在函數本體內(in Function Block),⼀一個被宣告為靜態的變數, 在這⼀一函數被呼叫過程中維持其值不變
在⼀一個Block(ie. {...} )內 (但在函數體外),⼀一個被宣告為靜態的變數 可以被Block內所有的函數存取,但不能被Block外的其它函數存取。 它是⼀一個區域裡⾯面的全局變數。
![Page 11: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/11.jpg)
• local variable 只在 { } 區間內有效,過了即消失。它的壽命就只有在進⼊入區間內到離開區間前。
• Static local variable 的壽命跟 global variable ⼀一樣⻑⾧長,但是只在宣告的 { }區間內是可視的。
void foo() { static count = 0; //只會被初始化⼀一次 count++; }
![Page 12: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/12.jpg)
volatile
⼀一個變數可以是const⼜又可以是volatile嗎?
⼀一個指標可以是volatile嗎?
int square(int *p) {
return *p * *p; }
問題在哪?
![Page 13: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/13.jpg)
Critical Section
void EXTI0_IRQHandler(){ encoder_left_counter++ ; }
void Calculate_motor_rpm(void) { 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
![Page 14: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/14.jpg)
define vs. inline
![Page 15: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/15.jpg)
何時需要⽤用到inline?
void forward_cmd(uint32_t pwm);
void backward_cmd(uint32_t pwm);
void stop_cmd(uint32_t pwm);
void right_cmd(uint32_t pwm);
void left_cmd(uint32_t pwm);
頻繁且⼤大量的被呼叫
程式碼很短
![Page 16: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/16.jpg)
都⼀一樣是展開,但是展開的時期?
優點?缺點?
![Page 17: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/17.jpg)
#define example
![Page 18: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/18.jpg)
FreeRTOS
![Page 19: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/19.jpg)
FreeRTOS supported platforms
• ARM • MSP430 • AVR • C8051F
![Page 20: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/20.jpg)
Showcasing a Selection of FreeRTOS Ecosystem Products
![Page 21: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/21.jpg)
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
![Page 22: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/22.jpg)
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
![Page 23: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/23.jpg)
Ultrasonic Signal example!for HR-04
How to access duration time using GPIO?
![Page 24: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/24.jpg)
while (ReadGPIO(echo_pin) == 1) { duration++; delay_us(1); };
Timer interrupt(Risig) Timer interrupt(Faling)
subtract
method 1 :
method 2 : Timer
若被其他執⾏行緒搶⾛走,
時間計算還會對嗎?
![Page 25: STM32F4 for 智慧型電動輪椅系統Part1](https://reader034.vdocuments.mx/reader034/viewer/2022052211/557da726d8b42a467c8b47d7/html5/thumbnails/25.jpg)
Thanks!