PIC long elapsed time interrupt?

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Nov 14, 2010.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    989
    I already have one timer setup that interrupts each second. A counter is incremented and at the end of the max count, the LCD is turned off. So I already know how to use a counter in my interrupt routine to increase the resolution of the timer.

    Now I want another timer to time out at the end of 10 minutes to several hours. I can just extend what I have done so far but how efficient is that when it comes to using sleep? Does the PIC have to "wake up" to incrment the counter? If so, is there a more efficient to generate an interrupt at the end of my long time period?
     
  2. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Do not force the PIC into sleep mode or there are different power saving modes which allow some functions to operate.
     
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Which PIC and what timer are you using?
    A lot of timers stop during sleep.
    Waking up to increment something shouldn't use too much power - it's only a small fraction of the time, which could possibly be reduced further using pre or postscalers.
     
  4. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    989
    I am using the 18f14k22. I don't plan to use sleep right now. I want to get everything working first.

    I am not seeing anything in the datasheet that says they do not operate in sleep. I am using timer 2 right now and plan to use timer 3 also.
     
  5. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    Why do you plan to use the sleep function?

    Is it a battery powered system?
     
  6. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    989
    Yes it is a solar light controller for the entrance sign for our community. The buck regulator to power the lights is off the shelf as well as the charge controller for the battery. (I am not yet good at the analog stuff :) )

    What is really nice about the buck regulator is that is also supplies +5 for the PIC.

    The whole thing replaces an old "dumb" controller / charger that is now fried. Poor design in even poorer enclosure.

    The old board monitored the solar panel. As soon as it dropped to zero volts the light would come on, even though there was plenty of daylight to see the sign. The light would stay on till the battery was totally depleted.

    It all runs off a small 12V SLA.

    I ramped things up by making it PIC controlled. When the PIC detects 0V on the panel, a programmable timer is started (optional). At the end of that time, the light comes on and a programmable timer is started (optional). The light goes off when the timer expires or the battery voltage drops below a programmable level.

    It has an LCD panel. When a front panel button is pressed a timer starts and the LCD goes off when the timer expires.

    Most of the time the controller will not be touched by humans so during that time, I would like the PIC to wake up every once in a while and check voltages then go back to sleep, to save as much battery for the lights as possible.
     
  7. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    If you want to save processing power, then when calculating the delay, disable all other functions within the PIC to save power. In that way you don't need to put it in sleep mode and have problems with the timers. Also, by reducing the accuracy of the timer, the processing power decreases since less commands need to be executed with in a time interval.
     
  8. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    989
    Yeah thanks I already have the osc running about as slow as it is going to go. I don't care about accuracy. A few seconds difference on the LCD timer is not going to make any difference and the timers that run the lights can be off by several minutes for all I care.

    I already set the outputs to the LCD to low when they are not being used. Is there anything else I can to there that would get a couple more micro amps?

    I guess I can shut down the analog input and have a timer wake up every few minutes and reinitialize the analog inputs and read the solar panel and battery volts?

    Right now I poll the bin inputs for a switch press. Would I save a bit of power by using interrupts?
     
  9. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    You can use a low-power PIC if the one you are using is not.
     
  10. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    989

    It's pretty low power.

    Would I save anything by not polling the BINs for the switched?
     
  11. mik3

    Senior Member

    Feb 4, 2008
    4,846
    63
    The less processing the PIC does, the more power it is saved. Use interrupts instead of polling.
     
  12. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Most of the newer PICs only use 1 or 2mA even when running, if you run them at 4MHz. Even less if you use a lower freq xtal.

    I would expect your buck regulator probably wastes a lot more than 2mA, and the self-discharge of your SLA 12v battery is probably 10mA to 20mA.

    It's probably not worth nitpicking over microamps. :)
     
  13. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    989
    What is the best why to measure the current the circuit is using? I have not measured it since I dropped down the clock but I was measuring 6ma w.o the LCD and 12ma with the LCD. But I was using an ammeter. Is this the best way to measure the current? Or should I place an inline resistor and read the voltage and convert?
     
  14. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    989
    Just measured it again with ammeter. I am using a 250K clock. I am still getting 6.2 ma.
     
  15. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    6.2mA seems high for just the PIC without the LCD. Do you have resistors in the circuit (like voltage dividers?). If you post your schematic people might suggest ways to reduce the current.

    A good trick for current measurement is to put a big cap (470uF) across the leads of your ammeter. That will help average out the current pulses caused by the PIC.

    How big is your SLA battery?
     
  16. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    989
    I have posted this before.

    The "Buck Puck" that is in the schematic is not yet in the circuit. It is actually going to be by supply for the PIC as well as a current limiter for the lights.

    The SLA is a 5AH. It is not yet being used to power anything. I am currently using my bench top suppy.
     
  17. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    989
    I disconnected everything and put the PIC into a loop where it does nothing. It had no effect on the current.
     
  18. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,866
    989
    Figured it out! It was my PickKit 3 drawing so much. I had no idea it would have affected the current draw. I disconnected it and I only draw .06 ma now! And that is not even in idle or sleep. I think if I improve the code some I can get it to idle more.
     
Loading...