John Pinares
Newbie level 4
- Joined
- Aug 31, 2014
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- 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:
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!
#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!