I've designed a temperature controller, based on a TI MSP430 micro. I use a thermistor to sense temperature, and a thermoelectric unit to heat/cool my enclosure. My hardware is working and I've written some working code in C that is successfully implementing a simple on/off control scheme to set the temperature. To control temperature I use a state machine implemented with a case statement. Since the state machine is small and only has a few states, this works well. Currently I have a software delay that executes each time through the state machine.
I would like to improve the program by using a timer to set a time interval and execute the state machine once per interval. There are lots of ways to do this. I'm much more of a hardware designer than a programmer, so I 'm looking for some general advice on ways to handle this type of code.
Here are some options I see ...
(1) Just use the timer to count a fixed time and use that for a delay after each time through the state machine.
(2) Place the sate machine code into a timer overflow interrupt routine.
(3) Set a global flag inside a timer interrupt service routine that I use to tell me when to execute the state machine.
I'm looking for general advice on best practice to handle this kind of program. Perhaps a simple outline of common ways to program or arcihtect this would be greatly appreaciated. Thanks in advance.
I would like to improve the program by using a timer to set a time interval and execute the state machine once per interval. There are lots of ways to do this. I'm much more of a hardware designer than a programmer, so I 'm looking for some general advice on ways to handle this type of code.
Here are some options I see ...
(1) Just use the timer to count a fixed time and use that for a delay after each time through the state machine.
(2) Place the sate machine code into a timer overflow interrupt routine.
(3) Set a global flag inside a timer interrupt service routine that I use to tell me when to execute the state machine.
I'm looking for general advice on best practice to handle this kind of program. Perhaps a simple outline of common ways to program or arcihtect this would be greatly appreaciated. Thanks in advance.