Simple program to test a steppermotor. Min/maxspeed, accelleration, distance and steps/m can be changed while the program is running for quick adjustment.

Dependencies:   mbed-rtos mbed

Fork of cmsis_rtos_queue by mbed official

Revision:
5:63fe92075b71
Parent:
4:09c35ecb3218
Child:
6:cfbef7079a6f
--- a/main.cpp	Sun Jun 15 20:57:59 2014 +0000
+++ b/main.cpp	Mon Jun 16 05:25:02 2014 +0000
@@ -20,34 +20,27 @@
 osMessageQDef(queue, 16, stepcmd);
 osMessageQId  queue;
 int qcnt = 0;
+Timeout timer;
 
-void read_thread (void const *args)
+void read_isr()
 {
-    while (true) {
+        StepLED = !StepLED;
         osEvent evt = osMessageGet(queue, 0);
         if (evt.status == osEventMessage) {
             stepcmd *cmd = (stepcmd*)evt.value.p;
             DirLED = cmd->dir;
-            StepLED = 1;
-            osDelay(100);
-            StepLED = 0;
             osPoolFree(cmdpool, cmd);
             qcnt--;
-        } else { // assume no info available
-            osDelay(100);
-        }
-        osDelay(2000);
-    }
+        } 
+        timer.attach(read_isr, 2);
 }
 
-osThreadDef(read_thread, osPriorityNormal, DEFAULT_STACK_SIZE);
-
 int main (void)
 {
     cmdpool = osPoolCreate(osPool(cmdpool));
     queue = osMessageCreate(osMessageQ(queue), NULL);
 
-    osThreadCreate(osThread(read_thread), NULL);
+    timer.attach(read_isr, 2);
     bool mydir = true;
 
     while (true) {