PDA

View Full Version : Changing Settings ???



tico
- 17th December 2006, 15:25
I am trying to build a type of Thermostat Using a PIC16f877 I have all of the hardware fiqured out and most of the software. I am using two LM34CAZ to read the temperature and displaying it on a LCD and Out the serial port. I am using PicBasic Pro

What I would like to do is use a few switches and/or a serial port to change the setting of the thermostat ie. Mode Summer/Winter, High Set Point, Low Setpoint and cant seem to find any code samples.

How do you store settings in a PIC and use a switch input to change those settings.

Thanks in advance for any help.

tico
- 22nd December 2006, 23:21
I guess I didnt ask nicely enough ???

b1arrk5
- 23rd December 2006, 04:53
It's not that you didn't ask nicely enough, it's just that this is a busy time of year, even for geeks and other engineering types! Plus your requirements will take a little thought, and after all of the eggnog floating around, well......

I have given requisite thought to developing a thermostat to supplement a project that I have been playing with for a while, so here goes;

Your setpoints, the temperature at which you will energize your relays to bring on the heating and air-conditioning, can fit in a byte sized variable, provided we are using the thermostat for comfort heating and cooling, as opposed to process control. Herein lies the first dilemma, will you allow settings in Fahrenheit, Celcius, or both? I will assume for now that you will allow settings to be in either. We can use a flag in picbasic to check for degrees F. or degrees C. I like to use a variable that is byte sized, and call it something silly and obscure, like, I don't know, Flags, or something. So let's try it.
'following line is an actual picbasic pro command;

Flags var byte 'variable to hold up to eight flags.

I didn't pay attention, but don't your selected temperature sensors output a voltage based upon a change in degrees Fahrenheit? So if we want the setpoint to be in degrees F. we just set the Flags.f = 1, and if we decide to change to degrees C. at some point then we just change the Flags.f = 0. So now when we test the flag using the pic basic command;
'following line is an actual picbasic pro command;

IF Flags.f true then
' this is where any code goes to accept Fahrenheit data.
Now, this is important, because you have to decide, will you test to ensure that if the Flags.f bit is a 1, or true, that your Pic won't accept any setpoints below 55 degrees, or over 95 degrees? If you are expecting F. setpoints, and your cousin from Quebec comes in over your serial port and sees a heating setpoint setting, he will of course enter something sane, like 21 degrees. This is a comfortable setting for our friends to the far north, but here in Pennsylvania most of us would put in a 71 or so setpoint. So we can do something like,


get_setpoint:
serin2 [setpoint]
If Flags.f = 1 and dec setpoint < 55 or dec setpoint > 95 then
lcdout $fe,1,"Setpoint out of range, please try again"
gosub get_setpoint 'go back and try again.

next we can set a flag for heating or cooling

if Flags.h = 1 then 'we are set for heating mode
so when we read our temperature in the controlled space we can compare it
to see if we need to turn on the heat.

I'll assume that you have the adc reading the lm34 temp sensors, and that you have stored the value in a variable called temperature.

if Flags.h = 1 and temperature < setpoint then gosub turn_the_heat_on
if Flags.h = 1 and temperature >= setpoint then gosub turn_the_heat_off
if Flags.h = 0 and temperature > setpoint then gosub turn_on_the_air-conditioning
if Flags.h = 0 and temperature <= setpoint then gosub turn_off_the_air-conditioning

You will also need a fan switch. Usually you can set fan on, off, or auto.
The fan must be turned on anytime that the air conditioning system is running, or you will freeze your indoor(evaporator) coil. If you are using this on a heat pump, then the fan must also be turned on immediately. If you are heating with a fossil fuel, such as a gas furnace, then you want to select let the air in the plenum come up to tempature first, then energize the fan, this way you don't blow cold air into the conditioned space. So, if the Auto flag is set, we will call for heat, and let a bonnet switch, or something similar, bring the fan on when the plenum temperature reaches at least ninety degrees or so F.
Let's us set two flags, Flags.auto and Flags.off

turn_the_heat_on:
if flags.auto = 1 then 'set the pin high to energize your heat relay.
ensure that the furnace will bring a blower on when the plenum temperature rises. This switch is usually located in the front control panel on the furnace.

Oops, Santa's helper says that I have to leave now. I'll try to get back to
finish this up over the next few days. I know a lot about thermostats and heating and air conditioning systems, so I can get you started with coming up with an anticiaptor, and other things.
Have a Merry Christmas,

Jerry

Acetronics2
- 23rd December 2006, 15:04
What I would like to do is use a few switches and/or a serial port to change the setting of the thermostat ie. Mode Summer/Winter, High Set Point, Low Setpoint and cant seem to find any code samples.

How do you store settings in a PIC and use a switch input to change those settings.

.

Hi,Tico

First you'll have to choose how to "poll" the request for changes ...

Interrupts looks the easiest way , as interrupts on port change, and interrupt on USART receive already exist aboard your PIC !!!

Then, just decide which coding you'll choose for the differents parameters ( serial input ) , and which menu you'll write for button programming ... looks a LCD could be useful here ...

After that, when the "valid" switch pushed or serial code will be received, just write parameters to their respective EEPROM locations ...

Alain

tico
- 28th December 2006, 03:10
Thanks b1arrk5
I started feeling left out and thought that maybe I asked a question with an obvious answer, I did scour the forum and found a post about a clock that used switches to set the time, I am using that code by Melanie as my basis for the input, of course I am trying to find that post now for reference and cant find it, I believe I still have an excess of eggnog floating around also.
I did find the file on my pc though it is mn1307.bas

Would I be correct to say that I could just add the SEROUT2 command everwhere it has an LCDOUT command and vice versa with the input switch use a SERIN2 command.
I pasted a section of code below to show what I mean

SetupLoop:
LCDOut $FE,1,"Set "
SEROUT2 "Set"

'
' First Display the Menu Prompts
' ------------------------------
' This is a crude way of doing the entry Menu's but it was
' pretty fast and quite mindless to program this lunch-hour
'
If CounterC=0 then
LCDOut "Mode"
SEROUT2 "Mode"

I am hoping that this method will work.....

Thanks for the suggestion for set point variable being between 55 and 95 I didnt think of that one.
And yes I will be using the LM34CAZ so the temperature will be in deg F.
Yes the LM34 outputs 10mV per deg F that is what I am pumping into the ADC with a Vref so that no conversion is necessary.

This is a starting point project for myself I have tried this a few time before with no gain. Now that I am using PicBasic it seems to make more sense and I can actually get code to compile (not like in ASM). I have no issues when it comes to hadware but the programming end of it needs alot of work for myself.

Thanks to all that contributed on this forum and I hope to hear from others soon.