stm32f4 for 智慧型電動輪椅系統part1

25
STM32F4 for 智慧電動輪 椅系統Part1 (JackABK) 2014/08/29 [email protected] 超威猛應輔具特隊

Upload: jack-wang

Post on 14-Jun-2015

758 views

Category:

Devices & Hardware


2 download

DESCRIPTION

暑期課程

TRANSCRIPT

Page 1: STM32F4 for 智慧型電動輪椅系統Part1

STM32F4 for 智慧電動輪椅系統Part1⺩王尹⾠辰(JackABK)

2014/08/29 [email protected]

超威猛應⽤用輔具特⼯工隊!

Page 2: STM32F4 for 智慧型電動輪椅系統Part1

智慧型電動輪椅系統架構

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

Embedded System

主微控制器(BeagleBoard-xM) 次微控制器(STM32F407)

Page 4: STM32F4 for 智慧型電動輪椅系統Part1

Demo

Page 5: STM32F4 for 智慧型電動輪椅系統Part1
Page 6: STM32F4 for 智慧型電動輪椅系統Part1

Filesystem

Page 7: STM32F4 for 智慧型電動輪椅系統Part1
Page 8: STM32F4 for 智慧型電動輪椅系統Part1

• The library for Smart EPW

Page 9: STM32F4 for 智慧型電動輪椅系統Part1

static 適⽤用時機?

Page 10: STM32F4 for 智慧型電動輪椅系統Part1

先了解其特質• ⼀一旦宣告後,就⼀一直存放在記憶體,不會隨著函數結束後⽽而釋放

• ⼀一個static函數表⽰示,其可以呼叫的範圍限於該原始碼⽂文件之中

在函數本體內(in Function Block),⼀一個被宣告為靜態的變數, 在這⼀一函數被呼叫過程中維持其值不變

在⼀一個Block(ie. {...} )內 (但在函數體外),⼀一個被宣告為靜態的變數 可以被Block內所有的函數存取,但不能被Block外的其它函數存取。 它是⼀一個區域裡⾯面的全局變數。

Page 11: STM32F4 for 智慧型電動輪椅系統Part1

• local variable 只在 { } 區間內有效,過了即消失。它的壽命就只有在進⼊入區間內到離開區間前。

• Static local variable 的壽命跟 global variable ⼀一樣⻑⾧長,但是只在宣告的 { }區間內是可視的。

void foo() { static count = 0; //只會被初始化⼀一次 count++; }

Page 12: STM32F4 for 智慧型電動輪椅系統Part1

volatile

⼀一個變數可以是const⼜又可以是volatile嗎?

⼀一個指標可以是volatile嗎?

int square(int *p) {

return *p * *p; }

問題在哪?

Page 13: STM32F4 for 智慧型電動輪椅系統Part1

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

define vs. inline

Page 15: STM32F4 for 智慧型電動輪椅系統Part1

何時需要⽤用到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

都⼀一樣是展開,但是展開的時期?

優點?缺點?

Page 17: STM32F4 for 智慧型電動輪椅系統Part1

#define example

Page 18: STM32F4 for 智慧型電動輪椅系統Part1

FreeRTOS

Page 19: STM32F4 for 智慧型電動輪椅系統Part1

FreeRTOS supported platforms

• ARM • MSP430 • AVR • C8051F

Page 20: STM32F4 for 智慧型電動輪椅系統Part1

Showcasing a Selection of FreeRTOS Ecosystem Products

Page 21: STM32F4 for 智慧型電動輪椅系統Part1

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

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

Ultrasonic Signal example!for HR-04

How to access duration time using GPIO?

Page 24: STM32F4 for 智慧型電動輪椅系統Part1

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

Thanks!