|
|
View previous topic :: View next topic |
Author |
Message |
ktallevi
Joined: 17 Dec 2005 Posts: 58
|
ADC during idle mode |
Posted: Wed Aug 02, 2006 8:31 am |
|
|
Is it possible to perform ADC calculations while the pic18fxxxx is in idle mode? (CPU: off, peripherals :on)
Basically I want to monitor a battery voltage level without having the PIC run in full power mode.
thanks |
|
|
Ttelmah Guest
|
|
Posted: Wed Aug 02, 2006 9:53 am |
|
|
Reading (just one). Probably. More, possibly. 'Calculations'. No.
On most of the chips, you can run the ADC, from it's own internal clock, and can trigger a reading, then go to sleep till it has finished. This is actually the 'preferred' way to use the ADC, for low noise applications. However once this reading is complete, the processor has to 'wake', to do anything 'with' this value.
Remember that with many of the latter PICs (NanoPower versions), you can switch the CPU 'down' to a slower clock rate in this 'awake' time, and the consumption then, can be tiny.
Further, some of this family, have ADC buffers, and the ability to trigger readings at intervals, or triggered off an external signal.
However 'monitoring', implies some form of check being made, and this requires CPU operations.
Depending on the interval wanted between 'readings', and whether the timing needs any accuracy, probably the lowest power option, is to use the watchdog, wake at perhaps nominally about 70mSec intervals, read the last conversion 'value', check this, trigger a new conversion, and go back to sleep. The conversion will actually occur during the first few uSec of the sleep period, and the value will then be waiting to read at the next wake-up.
Best Wishes |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Wed Aug 02, 2006 10:08 am |
|
|
If you have a part w/ a comparator use that. There are all sorts of nifty things that can be done and all while asleep. Post your part number and pinouts and how flexible you are to moving some of them around. I'll try to get you started and the pros will be able to clean up my mess....
Obviously, this will work if you can live with a single 'trigger' point. I would imagine you're just trying to detect a low battery?
John |
|
|
ktallevi
Joined: 17 Dec 2005 Posts: 58
|
ADC during idle mode |
Posted: Thu Aug 03, 2006 11:48 am |
|
|
PIC18F8722 being used...
so I plan to have a constant 2.5v from a voltage reference (LM4120) to F6 of the pic. The battery will be connected to F5 and I will run the comparator while the pic is in sleep mode (not idle afterall).
Upon the battery dropping below 2.5v, an LED will turn on, on pin F2. So I guess my 2 main questions are how to handle hysteresis? .. and is this the correct code to init the ccp module before going to sleep...
--
setup_ccp1(CCP_COMPARE_RESET_TIMER);
setup_comparator(F6_F5_F4_F5_OUT_ON_F2_F1);
setup_vref(FALSE);
--
I do NOT need the pic to wake up, just output a high on F2 to turn on an LED. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 03, 2006 12:23 pm |
|
|
See the following thread. It shows a method of adding hysteresis to the
battery voltage detection code.
http://www.ccsinfo.com/forum/viewtopic.php?t=2236
Note that the code calls a "configure_vref()" function. This was done
because the built-in CCS function "setup_vref()" didn't work for that
particular PIC and version of the compiler. In your code you can
likely use the standard setup_vref() function. |
|
|
ktallevi
Joined: 17 Dec 2005 Posts: 58
|
ADC during idle mode |
Posted: Thu Aug 03, 2006 12:32 pm |
|
|
PCM Programmer,
I would require a hardware solution for the hysteresis since the PIC will be running in sleep mode to conserve power. Execution of any code would require the PIC to be running. |
|
|
Ttelmah Guest
|
|
Posted: Thu Aug 03, 2006 3:06 pm |
|
|
You use the comparator interrupt to wake up, adjust the vref for hysteresis, and go back to sleep. Don't be afraid of hving the chip wake, execute a few instructions, and sleep again. As an example, I have a couple of PICs, which have been running now for over two years off a pair of AA batteries, waking about every 18mSec, and just executing about a dozen instructions each time. The PIC is asleep for 99.9% of the time.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|