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

12F683 analog

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



Joined: 13 Jan 2004
Posts: 29
Location: Green Bay, Wisconsin

View user's profile Send private message

12F683 analog
PostPosted: Fri Apr 07, 2006 8:56 am     Reply with quote

compiler version: 3.242

I have been working on a project that uses the sAN0 and sAN3 analog inputs on the 12F683 and seem to have found serveral discrepencies between the compiled code and the datasheet. Sample code below:

Code:

#include <12F683.h>

#device *=8 adc=10

#FUSES NOWDT                  //No Watch Dog Timer
#FUSES INTRC_IO               //Internal RC Osc, no CLKOUT
#FUSES NOCPD                  //No EE protection
#FUSES NOPROTECT              //Code not protected from reading
#FUSES NOMCLR                 //Master Clear pin used for I/O
#FUSES NOPUT                  //No Power Up Timer
#FUSES NOBROWNOUT             //No brownout reset
#FUSES IESO                   //Internal External Switch Over mode enabled
#FUSES FCMEN                  //Fail-safe clock monitor enabled

#use delay(clock=8000000)
#use rs232(baud=4800,xmit=PIN_A1,rcv=PIN_A2,parity=N,bits=8,errors)
//#priority EXT,TIMER0
#ZERO_RAM

void main()
{
   setup_oscillator(OSC_8MHZ);

    // initialize adc hardware
    setup_adc_ports(sAN3|VSS_VDD);     
    setup_adc(ADC_CLOCK_INTERNAL);
    set_adc_channel(sAN3);

   while (TRUE){

      delay_ms(500);
     
      printf( "Analog Data:%Lu\n\r", read_adc() );
     
   }
}

this results in this ASM:

....................       // initialize adc hardware
....................       setup_adc_ports(sAN3|VSS_VDD);
03F9:  BCF    1F.6
03FA:  BSF    03.5
03FB:  BCF    1F.0
03FC:  BCF    1F.1
03FD:  BCF    1F.2
03FE:  BSF    1F.3

....................       setup_adc(ADC_CLOCK_INTERNAL);
03FF:  BSF    1F.4
0400:  BSF    1F.5
0401:  BCF    1F.6
0402:  BCF    03.5
0403:  BSF    1F.7
0404:  BSF    1F.0



In the data sheet to setup for sAN3 the control register 1F.2 and 1F.3 should be set. And the select regiester should be 9F and not 1F.

I am I correct about this?

Has any one used the analog on this chip and if so what compiler version?

Regards,
Matt
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Apr 07, 2006 12:20 pm     Reply with quote

Well, this is an old subject and reason why I even see is between us.

It is an error in the constant definition in the 12F683.h file.

In the paragraph:
// Constants used in SETUP_ADC_PORTS()
Replace this lines
#define sAN0 1 //| GP0
#define sAN1 2 //| GP1
#define sAN2 4 //| GP2
#define sAN3 8 //| GP4


For this:
#define sAN0 0 //| GP0
#define sAN1 4 //| GP1
#define sAN2 8 //| GP2
#define sAN3 12 //| GP4


and the life will smile you.


Humberto
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 07, 2006 12:31 pm     Reply with quote

Here is an explanation of the listing file:
Code:

...     setup_adc_ports(sAN3|VSS_VDD);       
00D6:  BCF    03.5    // Bank 0
00D7:  BCF    1F.6    // VCFG = 0
00D8:  BSF    03.5    // Bank 1
00D9:  BCF    1F.0    // AN0 = digital pin
00DA:  BCF    1F.1    // AN1 = digital pin
00DB:  BCF    1F.2    // AN2 = digital pin
00DC:  BSF    1F.3    // AN3 = Analog pin

...     setup_adc(ADC_CLOCK_INTERNAL); 
00DD:  BSF    1F.4    // ADCS = 011 = use internal clock
00DE:  BSF    1F.5
00DF:  BCF    1F.6
00E0:  BCF    03.5    // Bank 0
00E1:  BSF    1F.7    // ADFM = 1  (right justify)
00E2:  BSF    1F.0    // ADON = 1


Also, the parameter you have used in the following line is not valid:
Quote:
set_adc_channel(sAN3);

You must use numbers for the channels. It should be:
Code:
set_adc_channel(3); 

This is in the manual.
mmprestine



Joined: 13 Jan 2004
Posts: 29
Location: Green Bay, Wisconsin

View user's profile Send private message

PostPosted: Fri Apr 07, 2006 1:24 pm     Reply with quote

Thanks,
I will change it and give it a try. Strange that it compiles with the wrong parameter.
Matt
mmprestine



Joined: 13 Jan 2004
Posts: 29
Location: Green Bay, Wisconsin

View user's profile Send private message

PostPosted: Fri Apr 07, 2006 1:51 pm     Reply with quote

Well as soon as I change the header file to Humberto's new defines and try to use analog 3 the serial does not function anymore. By serial I mean that I am using the external interrupt to parse serial data through a Max232. It appears to be affecting the external interrupt. Any thoughts on this?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 07, 2006 2:01 pm     Reply with quote

Put the #define statements back to the way they were in
the original 12F683.H file. Example:
Code:

#define sAN0   1     //| GP0
#define sAN1   2     //| GP1
#define sAN2   4     //| GP2
#define sAN3   8     //| GP4


Then do your A/D setup code like this:
Code:
setup_adc_ports(sAN3 | VSS_VDD);     
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(3);
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Apr 07, 2006 2:28 pm     Reply with quote

Quote:

Put the #define statements back to the way they were in
the original 12F683.H file.


PCM Programmer you are right, sorry. It was an old issue.

Humberto
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