Programmable Thermostat

Discussion in 'Embedded Systems and Microcontrollers' started by jenxin, Dec 5, 2012.

  1. jenxin

    Thread Starter New Member

    Nov 26, 2012
    27
    0
    My final project for my micro controllers class. I'll be posting in here to ask for help. This will be my second program done in C. The goal is to make a thermostat that can be programmed(time based).

    So far I have implemented my thermistor and converted the values into Fahrenheit. The LCD screen is implemented properly(thanks guys!), and my keypad is implemented. I'm still fairly new to C, but it's coming along pretty well. I will post my ideas here, and if you have an idea on improving mine, please share. Thanks!

    So onto the project..
    I've heard of a time.h that can be imported. My LCD should display the current time while no settings are being changed. My initial idea was to have a minutes counter and a hour counter. My flag for AM/PM can be switched with a keypress. The user enters 12:47 and makes it PM, then that will be the time. I was going to do all the incrementing in background.

    I am using a HCS12C - MC9S12C32 board. Using a seiko 16x2 LCD. and a regular 4x4 matrix keypad.
     
  2. rstevenson

    New Member

    Apr 5, 2011
    21
    1
    not knowing much about your board but generally time is kept better using a real time clock instead of a microcontroller. Good luck!
     
  3. jenxin

    Thread Starter New Member

    Nov 26, 2012
    27
    0
    I finished the whole project already, but can anyone explain how to use the clock interrupt to keep track of time? Not sure how to set it up. I used the delay methods and incremented my counter whenever a min passed.
     
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    990
    Well it is easier with an RTC since it is all done for you. But you could roll your own. Just set up an interrupt timer for once a second. Have a counter for seconds minutes, hours, days, months, years.
     
  5. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    990
    Also if you can't do a 1 second delay just do a millisecond delay and add another counter.

    You don't really even need separate minute, hour, day etc counters. You could borrow from several OSs and have one variable that is the number odf seconds since a certain date. Then just compute hours, minutes, days etc.
     
  6. jenxin

    Thread Starter New Member

    Nov 26, 2012
    27
    0
    My problem is how to use the interrupt. Not sure how I can have this interrupt last only 1 second while doing other things. I have other processes that will be running, like updating the LCD screen every few milliseconds, this process takes time to process though. Also I need to be able to scan for input every millisecond.
     
  7. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    990

    I already told you how to use the interrupt.

    The interrupt does not "last" one second, at least it shouldn't if your code is written properly. If you have a timer that interrupts every second then the interrupt routine only interrupts every second. Your ISR should be very short so as to not cause a problem with the code running in the main loop.
     
  8. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    990
    If you are talking about how to setup and program a timer interrupt then as an old electronics instructor used to say "Say what you mean and mean what you say".

    There are many tutorials on the web for setting up pic timer interrupts.
     
  9. jenxin

    Thread Starter New Member

    Nov 26, 2012
    27
    0
    Aha, I see okay! Thanks for the advice! I'll try to fix up my code after finals.. >:]

    And yes I didn't know how to setup and program the timer interrupt. I'll look more into the tutorials.
     
  10. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    990
    Here is one I have used

    http://www.mikroe.com/chapters/view/17/chapter-4-examples/#c4v5

    And others will criticize me but you might want to search on Pic Timer Calculator. There are several tools out there that will help you with the setting that you will need for a specific time duration.

    Also remember that not all timers will get you one second. Your options are to use one that does or simply count milliseconds, or 10s of mill seconds or whatever. If all you need is a second then a second interrupt is best because it is not occurring as often.

    But remember to keep your ISR short. The ISR will tie up the rest of your code. One trick for longer ISR is to have the ISR set a flag. Then in the main loop if the flag is set you execute the code and clear the flag.
     
  11. upand_at_them

    Active Member

    May 15, 2010
    246
    29
  12. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Gentlemen: Please note that in his orgional post jenxin stated he was using the Freescale Semiconductor MC9S12C32 as his processor.

    This is not a PIC device. You will just add to the general confusion by supplying documentation for a series of non compatible devices.
     
  13. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    990
    Oh good catch Ernie. I was confusing this thermometer thread with the other one, not to be confused with my thermometer thread. :)
     
Loading...