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

Post on 14-Jun-2015

758 Views

Category:

Devices & Hardware

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

暑期課程

TRANSCRIPT

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

2014/08/29 abkabkabkyes@gmail.com

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

智慧型電動輪椅系統架構

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

Embedded System

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

Demo

Filesystem

• The library for Smart EPW

static 適⽤用時機?

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

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

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

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

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

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

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

volatile

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

⼀一個指標可以是volatile嗎?

int square(int *p) {

return *p * *p; }

問題在哪?

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

define vs. inline

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

頻繁且⼤大量的被呼叫

程式碼很短

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

優點?缺點?

#define example

FreeRTOS

FreeRTOS supported platforms

• ARM • MSP430 • AVR • C8051F

Showcasing a Selection of FreeRTOS Ecosystem Products

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

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

Ultrasonic Signal example!for HR-04

How to access duration time using GPIO?

while (ReadGPIO(echo_pin) == 1) { duration++; delay_us(1); };

Timer interrupt(Risig) Timer interrupt(Faling)

subtract

method 1 :

method 2 : Timer

若被其他執⾏行緒搶⾛走,

時間計算還會對嗎?

Thanks!

top related