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 CCS Technical Support

ADC on 16F689 channel 13

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



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

ADC on 16F689 channel 13
PostPosted: Fri Oct 20, 2006 4:34 pm     Reply with quote

Just a quick question. I need to use channel 13 on the 16F689 as a comparative reference. What do I use for setting up the port when calling:
Code:
setup_adc_ports(sAN0 | VSS_VDD);


sAN13 is not a valid option in the 16F689.h file. To make it a valid option I can define it, but what value does it need to be assigned to make it work correctly?

Code:
#define sAN0            1       //| A0
#define sAN1            2       //| A1
#define sAN2            4       //| A2
#define sAN3            8       //| A4
#define sAN4            16      //| C0
#define sAN5            32      //| C1
#define sAN6            64      //| C2
#define sAN7            128     //| C3
#define sAN8         0x10000    //| C6
#define sAN9         0x20000    //| C7
#define sAN10        0x40000    //| B4
#define sAN11        0x80000    //| B5
// My definitions for channels 12 and 13
#define sAN12       0x100000  //| CVref
#define sAN13       0x200000  //| VP6



Would this be correct, or am I totally wrong in my thinking? Or since they are not ports, do I even need to do a setup_adc_ports() call for channels 12 and 13?

Thanks!

jspencer
Ttelmah
Guest







PostPosted: Sat Oct 21, 2006 2:19 am     Reply with quote

The 689, does not support 13 channels on the ADC.
Look at table 4, in the data sheet.
It supports analog channels AN0 to AN11, which is what the existing setup already gives you. Pin 13 on the chip, connects to AN10, which may be what you are referring to. Vref for the ADC, can only use the supply rail, or RA1.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 21, 2006 10:43 pm     Reply with quote

Do you want to read the VP6 voltage with the A/D ?

To do that, you basically need to enable VP6 and then
select channel 13. I don't have a 16F689 to test, but
I've read the data sheet and I think the following program
should work:
Code:

#include <16F689.h>
#device adc=10
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, ERRORS)

#byte VRCON = 0x118
#bit  VP6EN = VRCON.4

//=====================================
void main()
{
int16 result;

VP6EN = 1;      // Enable VP6 voltage (0.6v)
delay_us(100);  // Wait for required settling time

setup_adc(ADC_CLOCK_DIV_16); // Use /16 with a 4 MHz xtal

set_adc_channel(13);         // Select channel for VP6
delay_us(20);

result = read_adc();

// The A/D value for VP6 should be approximately 123.
// (With the PIC's Vdd at +5.0 volts, and a 10-bit A/D).
printf("result = %lu\n\r", result);

while(1);
}
jspencer



Joined: 22 Dec 2003
Posts: 57
Location: Boise, ID USA

View user's profile Send private message

PostPosted: Mon Oct 23, 2006 9:30 am     Reply with quote

PCM that is correct. Since I do not have a constant Voltage supply (3V coin cell) we are going to use the ratio of the VP6 to scale the ADC channels readings appropiately. After doing a little more reading, what you posted is what I came up with. I will give it a shot today and see how it works.

Thanks!

jspencer
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