homework 7

Dependencies:   mbed-rtos mbed C12832_lcd LM75B

Files at this revision

API Documentation at this revision

Comitter:
gatedClock
Date:
Fri Sep 13 00:15:02 2013 +0000
Parent:
124:55c83dbeba2c
Child:
126:70439be77e75
Commit message:
ok, any way to shut down the blinkers faster?

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Sep 12 23:52:30 2013 +0000
+++ b/main.cpp	Fri Sep 13 00:15:02 2013 +0000
@@ -7,12 +7,8 @@
     gotchyas
     1. using pc.printf inside a ticker routine will freeze the routine.
     2. using queues (get, put) will not work within a ticker routine.
-    3. Ticker has a bug.  http://mbed.org/questions/1563/Mbed-Tickerfunction-hangs-system-from-re/
-    
-    improvements
-    countdown timer needs to be sync'd to start button press.
-    this could not be done, use granularity setting instead.
-    
+    3. Ticker has/had a bug.  http://mbed.org/questions/1563/Mbed-Tickerfunction-hangs-system-from-re/
+   
     global variables considerations (mutex)
     the global variables associated with joystick button presses are 
     in the structure 'tButtons' (instance 'giButtons').  ISRs store that a
@@ -25,7 +21,7 @@
     
     some mutex's are in use, but I'm running out of time, --
     
-    here are use cases & things tested
+    tested use cases.
     
     1.
     * user sets maximum time.
@@ -68,12 +64,24 @@
     * user hits 'start'.
     * nothing happens.
     
+    6. 
+    * user opens door.
+    * user sets time.
+    * user hits 'start'.
+    * -> set time still there,
+    * -> but cook cycle not started.
+    * user closes door.
+    * user hits 'start'.
+    * operation continues as normal.
+    
+    I just saw some bounce, increased debounce time from 16 to 32 mS.
+    
     
     tour of software
     * ISRs register button presses into global structure.
     * debounce mechanism.
     * ISRs share common bottom-half thread, which clears the 
-      button-press structure values, and forards mail to other
+      button-press structure values, and forwards mail to other
       threads of just-pressed button status.
     * total time control thread handles setting total time, and
       will suppress total time changes or clear total time based
@@ -85,20 +93,41 @@
     * temperature thread reads physical temperature, or calculates
       synthetic temperature at 1/6 degree increase per second, 
       upon commands from the FSM.
-    * LCD thread 
+    * LCD thread, idle priority and moderate wait time.
+      it will update display only upon a display value change
+      in order to reduce 'blinkieness'.
+      
+      some globals could be moved into mail, such as data sent
+      to the LCD.
     
     magnetron timing
     * LED2 is used for magnetron control (non-blinking).
       - front-end control is used to turn it off:
       - it is turned off in the 'stop' button ISR for safety.
-      - it is turned OFF in the door-toggle ISR for safety.
+      - it is turned off in the door-toggle ISR for safety.
       - this ensures immediate magnetron off.
+      - the FSM will also turn it on/off according to the cook-state,
+        and the control is the first statement in all states.
+      - the FSM's switch statement default also turns off the
+        magnetron for safety.
     
     other timing
     * the FSM thread has (if I counted right) six message get/puts worst
       case in one loop, all with 1mS timeout, and the loop has a 1mS wait,
       so it would be running on the order of once each 10mS.
       this is the highest priority thread.
+      
+    countdown timer needs to be sync'd to start button press.
+    this could not be done, use granularity setting instead.
+    I made the countdown timer operate at a high speed, and divided-out the
+    output to 1s resolution.  This because I wanted to provide the appearance
+    of resetting the phase to zero upon 'start' button press, rather than
+    having the countdown change at an arbitrary moment within one second
+    of the 'start' press.
+    
+    I had a half-baked idea of adding some type of background thread to 
+    verify consistency of states and turning off the mangetron if it found
+    anything suspicious.  Haven't thought this through.
     
     
 -----includes-----------------------------------//----------------------------*/
@@ -112,7 +141,7 @@
     #define LCD3 lcd.locate(0,22);              // LCD line 3.
        
 
-    #define DEBOUNCEmS       16                 // debounce wait in mS.
+    #define DEBOUNCEmS       32                 // debounce wait in mS.
     #define uS_TIMEOUT      100                 // Timer uS timeout.
     #define LBSIG             1                 // left button signal code.
     #define PIPEuS         1000                 // pipeline clock period.
@@ -627,7 +656,15 @@
             break;
           }       
 //---           
-          default       : {dFSMstate = FSM_IDLE; break;}
+          default       :                       // SAFETY
+          {
+            led2 = 0;                           // magnetron OFF.
+            led3 = 0;                           // carousel  OFF.
+            giMagnetron.cMagnetron = 0;         // ennunciator.
+            giMagnetron.cCarousel  = 0;         // ennunciator.
+            dFSMstate = FSM_IDLE; 
+            break;
+          }
         
         }