View previous topic :: View next topic |
Author |
Message |
kben
Joined: 04 Oct 2003 Posts: 3
|
ADC with sleep() |
Posted: Tue Oct 07, 2003 4:29 am |
|
|
Hi,
Does anybody have a code sample for using the ADC with sleep().
I have PCM 3.178 and am using a 16F88 at 10Mhz. I have read
through the samples and the manual and also previous posts,
but I am still unclear on using sleep() with #int_ad.
Thanks in advance,
Kevin |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
![](templates/subSilver/images/spacer.gif) |
kben
Joined: 04 Oct 2003 Posts: 3
|
|
Posted: Tue Oct 07, 2003 6:59 am |
|
|
I was hoping I did not have to jump through all the hoops to get the compiler to do what it is supposed to in the first place. I did see that,
I just thought if I had the latest version there might be an easier way.
I guess I will define all the bit flags and give it a go.
Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Tue Oct 07, 2003 5:22 pm |
|
|
Remember, if you are using one of the newer versions of the compiler you won't need to adjust PEIE yourself. |
|
![](templates/subSilver/images/spacer.gif) |
kben
Joined: 04 Oct 2003 Posts: 3
|
|
Posted: Fri Oct 10, 2003 8:15 pm |
|
|
Thanks Haplo & RJ, I used the link you provided above and go it to work.
I am using v3.178 with a 16F88 and I DID have to set PEIE manually.
My code looks like this:
//************************ Used for setting ADC Interupt**
#byte ADRESL = 0x9E
#byte ADRESH = 0x1E
#bit ADGO = 0x1f.2
#bit ADON = 0x1f.0
#bit ADIF = 0xC.6
#bit PEIE = 0xB.6
//********************************************************
void main(void) {
// Set up ADC for measuring current and temperature
enable_interrupts(INT_AD);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports( sAN0 | sAN1 | VSS_VDD );
// Use RA0 and RA1 for ADC ref = VREF 0-5V
While(TRUE) {
enable_interrupts(GLOBAL);
set_adc_channel(0);
ADON=TRUE;
delay_us (10);
disable_interrupts(GLOBAL);
enable_interrupts(INT_AD);
PEIE=TRUE;
ADIF=FALSE;
ADGO=TRUE;
printf("\r\nGoing to sleep\r\n"); // Test
sleep();
printf("\r\nWaking from sleep\r\n"); // Test
value1=make16(ADRESH,ADRESL);
disable_interrupts(INT_AD);
enable_interrupts(GLOBAL);
printf("\r\nValue returned for ADC Channel 1: %lu ",value1);
} // End While Statement Block
} // End of Main Program |
|
![](templates/subSilver/images/spacer.gif) |
|