CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ADC during idle mode

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ktallevi



Joined: 17 Dec 2005
Posts: 58

View user's profile Send private message

ADC during idle mode
PostPosted: Wed Aug 02, 2006 8:31 am     Reply with quote

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







PostPosted: Wed Aug 02, 2006 9:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Aug 02, 2006 10:08 am     Reply with quote

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

View user's profile Send private message

ADC during idle mode
PostPosted: Thu Aug 03, 2006 11:48 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 03, 2006 12:23 pm     Reply with quote

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

View user's profile Send private message

ADC during idle mode
PostPosted: Thu Aug 03, 2006 12:32 pm     Reply with quote

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







PostPosted: Thu Aug 03, 2006 3:06 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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