
Simple test program to get familiar with functionality of MBED RTOS on ST Nucleo-F411RE. Tasks for LED blinking, user button, temperature measurement with DS1620, temperature measurement with internal temperature sensor of ST32F411RE, ultrasonic distance measurement and displaying result on 16x2 TextLCD.
Dependencies: DS1620_improved TextLCD_improved mbed-rtos mbed
Revision 15:a627638edd9c, committed 2015-12-14
- Comitter:
- dzoni
- Date:
- Mon Dec 14 21:46:45 2015 +0000
- Parent:
- 14:bd01b5240dee
- Child:
- 16:cfb774e3e7fc
- Commit message:
- Hangs out in display ("Raw: 20" and that's all)
Changed in this revision
--- a/todo.txt Mon Dec 14 19:48:36 2015 +0000 +++ b/todo.txt Mon Dec 14 21:46:45 2015 +0000 @@ -1,2 +1,1 @@ -1. Change distance measurement principle. Result fluctuations too big. -2. Change thread principle from Thread::wait() to FSM and its evaluation in given times and signals to particular threads. +1. Change thread principle from Thread::wait() to FSM and its evaluation in given times and signals to particular threads.
--- a/tsk_display.cpp Mon Dec 14 19:48:36 2015 +0000 +++ b/tsk_display.cpp Mon Dec 14 21:46:45 2015 +0000 @@ -8,7 +8,7 @@ #include "tsk_dist.h" #include "tsk_main.h" -static TextLCD *lcd = NULL; +static TextLCD *lcd; uint32_t initDisplay(void const *args) { @@ -36,10 +36,10 @@ while (true) { lcd->cls(); lcd->printf("Raw:%3u % 5.0f mm", temp_data.temp_raw, dist_data.distance); - uiCnt += 2; +// uiCnt += 2; lcd->locate(0, 1); lcd->printf("Float: %3.2f%cC", temp_data.temperature, 0xdf); - Thread::wait(2000); + Thread::wait(1896); } } \ No newline at end of file
--- a/tsk_dist.cpp Mon Dec 14 19:48:36 2015 +0000 +++ b/tsk_dist.cpp Mon Dec 14 21:46:45 2015 +0000 @@ -8,10 +8,27 @@ static DigitalOut trigDist(PB_9); -static DigitalIn echoDist(PA_6); +static InterruptIn echoDist(PA_6); static Timer timer; +static void rising(void) { + timer.start(); +} + +static void falling(void) { + timer.stop(); + echoDist.rise(0); + echoDist.fall(0); + + dist_data.timerTicks = timer.read_us(); + + // 340 ms-1 + dist_data.distance = (timer.read()/2.0f - 0.0f)*340.0f*1000.0f; + + // Vynuluj timer + timer.reset(); +} void dist_thread(void const *args) { @@ -25,29 +42,15 @@ dist_data.timerTicks = 0; dist_data.distance = 0.0f; } else { + // Vynuluj timer timer.stop(); timer.reset(); - // Cekej na hranu na Echo - while (echoDist != 1) - ; - - // Zacni merit cas - timer.start(); - - // Cekej na hranu na Echo - while (echoDist != 0) - ; - - // Zastav mereni - timer.stop(); - - dist_data.timerTicks = timer.read_us(); - - // 340 ms-1 - dist_data.distance = (timer.read()/2.0f - 0.0f)*340.0f*1000.0f; + // Cekej na hrany na Echo + echoDist.rise(&rising); + echoDist.fall(&falling); } - Thread::wait(1000); + Thread::wait(500); } }
--- a/tsk_main.cpp Mon Dec 14 19:48:36 2015 +0000 +++ b/tsk_main.cpp Mon Dec 14 21:46:45 2015 +0000 @@ -1,6 +1,5 @@ #include "mbed.h" #include "rtos.h" -#include "TextLCD.h" #include "tsk_button.h" #include "tsk_display.h" @@ -15,7 +14,7 @@ struct task_definition_struct { void(*task)(void const *args); - uint32_t(*init)(void const *args); // 1 = OK, 0 = FAIL + uint32_t(*init)(void const *args); // Result: 1 = OK, 0 = FAIL void *task_args; // NULL For DEFAULT (NULL) void *init_args; // NULL For DEFAULT (NULL) osPriority priority; @@ -27,11 +26,11 @@ }; static struct task_definition_struct taskList[] = { - { dist_thread, NULL, NULL, NULL, osPriorityRealtime, 0, NULL, 0 }, - { temp_thread, &initDS1620Temp, NULL, NULL, osPriorityLow, 0, NULL, 0 }, - { button_thread, NULL, NULL, NULL, osPriorityAboveNormal, 0, NULL, 0 }, - { led_thread, NULL, NULL, NULL, osPriorityNormal, 0, NULL, 0 }, - { disp_thread, &initDisplay, NULL, NULL, osPriorityLow, 0, NULL, 0 }, + { dist_thread, NULL, NULL, NULL, osPriorityNormal, 0, NULL, 0 }, + { temp_thread, &initDS1620Temp, NULL, NULL, osPriorityLow, 0, NULL, 0 }, + { button_thread, NULL, NULL, NULL, osPriorityNormal, 0, NULL, 0 }, + { led_thread, NULL, NULL, NULL, osPriorityNormal, 0, NULL, 0 }, + { disp_thread, &initDisplay, NULL, NULL, osPriorityNormal, 0, NULL, 0 }, }; static uint32_t initTasks(void) { @@ -60,21 +59,9 @@ int main() { - Thread::wait(1000); - initDS1620Temp(NULL); - initDisplay(NULL); - -/* - Thread tempThread(temp_thread, NULL, osPriorityLow); - Thread distThread(dist_thread, NULL, osPriorityRealtime); - Thread ledThread(led_thread, NULL, osPriorityNormal); - Thread buttonThread(button_thread, NULL, osPriorityAboveNormal); - Thread dispThread(disp_thread, NULL, osPriorityNormal); -*/ - initTasks(); Thread::wait(osWaitForever);