Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Portable Electric Heater State Machine HomeWork

Status
Not open for further replies.

John Pinares

Newbie level 4
Newbie level 4
Joined
Aug 31, 2014
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
55
Hey everyone. This week I need help programming a heater. Here's the homework:

#1 A portable electric heater system should turn on heat (B0=1) when the actual temperature (A3-A0)
is less then the desired temperature (A7-A4). To let users see that the heater is on, the system should
blink B1 on for 500 ms and off for 500 ms. Capture the system using multiple tasks and a shared
variable.

Right now I'm working on turning B0 on and off. Here's my state machine and code:



Code:
/*
This code was automatically generated using the Riverside-Irvine State machine Builder tool
Version 2.7 --- 10/2/2014 17:5:26 PST
*/

#include "rims.h"

/*Define user variables and functions for this state machine here.*/
unsigned char actTemp;
unsigned char desTemp;

enum SM1_States { SM1_HeatOff, SM1_HeatOn } SM1_State;

TickFct_State_machine_1() {
   switch(SM1_State) { // Transitions
      case -1:
         SM1_State = SM1_HeatOff;
         break;
         case SM1_HeatOff: 
         if (actTemp<desTemp) {
            SM1_State = SM1_HeatOn;
         }
         break;
      case SM1_HeatOn: 
         if (actTemp>desTemp) {
            SM1_State = SM1_HeatOff;
         }
         break;
      default:
         SM1_State = SM1_HeatOff;
   } // Transitions

   switch(SM1_State) { // State actions
      case SM1_HeatOff:
         B0=0;
         actTemp = (A3<<3)+(A2<<2)+(A1<<1)+A0;
         desTemp = (A7<<3)+(A6<<2)+(A5<<1)+A4;
         break;
      case SM1_HeatOn:
         B0=1;
         break;
      default: // ADD default behaviour below
      break;
   } // State actions

}

int main() {

   
   SM1_State = -1; // Initial state
   B = 0; // Init outputs

   while(1) {
      TickFct_State_machine_1();} // while (1)
} // Main

Right now I'm having trouble getting from HeatOn to HeatOff. When actTemp is less than desTemp, the heater turns on, no problem. But when actTemp is greater than desTemp, the heater stays on. Thanks in advance for any help.

Also thank you for all the help I've been receiving so far. I'm not sure if many students ask for help on homework on this website, but thank you all for helping me with mine!
 

Well not being a software engineer...

I did notice your state machine doesn't tell what your supposed to do when you are in the HEAT OFF state and actTemp >= desTemp also when you are in the HEAT ON state you don't specify what to do when actTemp <= desTemp.

At least in hardware design done in Verilog/VHDL you would have to specify both those conditions.

I'm not sure if many students ask for help on homework on this website, but thank you all for helping me with mine!
What are you talking about, just look at other posts...at least you're asking for help with something you've actually worked on (x10 kudos for you)....around here there are far to many "students" who want someone on the forum to do their homework FOR them. 8-O

Regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top