|
|
View previous topic :: View next topic |
Author |
Message |
IBeRyUS
Joined: 27 Nov 2007 Posts: 2 Location: Konya/Turkey
|
Trouble with 12F675 A/D unit |
Posted: Tue Nov 27, 2007 7:38 pm |
|
|
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
|
|
Posted: Tue Nov 27, 2007 7:49 pm |
|
|
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
|
thx |
Posted: Tue Nov 27, 2007 7:55 pm |
|
|
thanx PCM Programmer. Really I couldn't see it. _________________ IBeRyUS was here... |
|
|
|
|
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
|