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

Trouble with 12F675 A/D unit

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



Joined: 27 Nov 2007
Posts: 2
Location: Konya/Turkey

View user's profile Send private message

Trouble with 12F675 A/D unit
PostPosted: Tue Nov 27, 2007 7:38 pm     Reply with quote

Hi,

I am using PCWHD 4.057. I had some troubles with 12F675 a few days ago. I corrected it but i couldn't understand why it is happening.

I used PICWizard to create project because I have limited time to it but it take too much time:) this is the code generated by PicWizard and I controlled it more times from help.

I made a project to my school project which is reading analog value in GP2 pin and send it to PC by RS-232. I used A/D interrupt so i am using read_adc(); functions in main() function with this argument ADC_START_ONLY. In the interrupt function I am using read_adc with ADC_READ_ONLY. So i start conversion after send data and wait for int. after int. flag will be seted and checked in main loop. if flag set i send data and start conversion again.

This is .h file which contains my defines.

Code:
#include <12F675.h>
#device adc=10

#FUSES WDT                    //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 MCLR                     //Master Clear pin enabled
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES BANDGAP_HIGH         

#use delay(clock=4000000,restart_wdt)
#use rs232(baud=19200,parity=N,xmit=PIN_A4,rcv=PIN_A5,bits=8,FORCE_SW,restart_wdt)
int1 flag;
union tanim
   {
   unsigned int16 l;
   unsigned int8 c[2];
   }deger;

#byte ansel = 0x9f
#byte adcon = 0x1f

#rom 0x3ff={0x3458}


this is code generated by PicWizard.
Code:
   
   setup_adc_ports(sAN2|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
.....
.....
   enable_interrupts(INT_AD);
   enable_interrupts(GLOBAL);
//TODO:
set_adc_channel(sAN2);
delay_ms(1);
read_adc(ADC_START_ONLY);



when i did it and control it in PROTEUS afte read_adc function processed proteus give warning. "The GPIO<0> is not configured as analog input.". I think maybe PROTEUS can't do it so i tested in board I token same values. I read only digital port values and it was only 0x00 or 0x3ff. After some tries i put ansel and adcon defines to my .h file and i deleted all CCS adc functions. I opened 12f675 datasheet and calculated all values to be written to Tris, Adsel and Adcon and i make them like this.

Code:

   set_tris_a(0x2c);
   ansel=0x34;
   adcon=0x89;
....
....
read_adc(ADC_START_ONLY);


after this my simulation and board worked perfectly.

Why happened this and why i could't use CCS's adc functions???

Have you have any idea???
_________________
IBeRyUS was here...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 27, 2007 7:49 pm     Reply with quote

Quote:
set_adc_channel(sAN2);

This is wrong. The parameter for this function is the channel
number, such as 0, 1, 2, 3, etc. It's not the "sANx" number.
IBeRyUS



Joined: 27 Nov 2007
Posts: 2
Location: Konya/Turkey

View user's profile Send private message

thx
PostPosted: Tue Nov 27, 2007 7:55 pm     Reply with quote

thanx PCM Programmer. Really I couldn't see it.
_________________
IBeRyUS was here...
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