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

Problems using dspic33ep256mu806 AN0 and AN1 ADC

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



Joined: 26 Apr 2009
Posts: 11

View user's profile Send private message

Problems using dspic33ep256mu806 AN0 and AN1 ADC
PostPosted: Mon Nov 05, 2012 5:19 am     Reply with quote

Hello everybody, I am going to explain my problem.
I am developing a prototype using dsPIC33EP256MU806, in wich I need to use the 2 analog inputs, AN0 -> RB0 and AN1 -> RB1
I use PCWHD compiler from CCS version 4.128

The problem is that I can not read the correct ADC value (tested using a voltimeter and can see the desired voltage) either in AN0 and AN1.

The dsPIC is working because I use 4 hardware USARTs and I can see debug lines using fprintf.

I attach my first code:
Main.c
Code:
void main(){
  unsigned int16 lectura = 0; 
  setup_adc_ports(sAN0 | sAN1 | VSS_VDD); 
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0); 
   delay_us(READ_SAMPLE_TIMES);
   delay_ms(3000);
   fprintf(DEBUG,"Arranco\r\n");
   while(true){
               
      lectura = read_adc(ADC_START_AND_READ);
      fprintf(DEBUG,"ADC: %lu",lectura);
      delay_ms(1000);
   }
}


And the second one:

Main.c
Code:
void main(){
unsigned int16 lectura = 0; 

ADON = 0;      // ADC off
   AD12B = 0;     // 10 Bits
   FORM_1 = 0;    // unsigned int
   FORM_0 = 0;
   
   VCFG_2 = 0;    // AVdd - AVss
   VCFG_1 = 0;
   VCFG_0 = 0;
   CHPS_1 = 0;    // converts ch0
   CHPS_0 = 0;
   
   ADRC =1;       // Internal clock RC ADC
   
   SAMC_4 = 0;    // 0Tad
   SAMC_3 = 0;
   SAMC_2 = 0;
   SAMC_1 = 0;
   SAMC_0 = 0;
   
   CH0SA_4 = 0;   // AN0
   CH0SA_3 = 0;
   CH0SA_2 = 0;
   CH0SA_1 = 0;
   CH0SA_0 = 0;
   
   ADON = 1;      // ADC ON
delay_ms(3000);
   fprintf(DEBUG,"Arranco\r\n");
   while(true){
               
      lectura = read_adc(ADC_START_AND_READ);
      fprintf(DEBUG,"ADC: %lu",lectura);
      delay_ms(1000);
   }
}


Main.h
Code:
// ADC CONFIG
#WORD AD1CON1 = 0x0320         // ADON(15) - AD12B(10) - FORM(9,8)

#BIT ADON = AD1CON1.15
#BIT AD12B = AD1CON1.10
#BIT FORM_1 = AD1CON1.9
#BIT FORM_0 = AD1CON1.8


#WORD AD1CON2 = 0x0322         // VCFG(15,14,13) - CHPS(9,8)

#BIT VCFG_2 = AD1CON2.15
#BIT VCFG_1 = AD1CON2.14
#BIT VCFG_0 = AD1CON2.13
#BIT CHPS_1 = AD1CON2.9
#BIT CHPS_0 = AD1CON2.8


#WORD AD1CON3 = 0x0324         // ADRC(15) - SAMC(12,11,10,9,8)

#BIT ADRC = AD1CON3.15
#BIT SAMC_4 = AD1CON3.12
#BIT SAMC_3 = AD1CON3.11
#BIT SAMC_2 = AD1CON3.10
#BIT SAMC_1 = AD1CON3.9
#BIT SAMC_0 = AD1CON3.8


#WORD AD1CHS0 = 0x0328         // CH0SA(4,3,2,1,0)

#BIT CH0SA_4 = AD1CHS0.4
#BIT CH0SA_3 = AD1CHS0.3
#BIT CH0SA_2 = AD1CHS0.2
#BIT CH0SA_1 = AD1CHS0.1
#BIT CH0SA_0 = AD1CHS0.0


In both cases I always see 512 value.

I have simplified the code, so there is some configurations that I have omitted

Do you have any idea how to solve this problem?

Any suggestion will be appreciated, thank you so much.
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon Nov 05, 2012 7:23 am     Reply with quote

Obvious first thing, you have got Avdd, and AVss connected?. The supply for the ADC, is separate on these chips.

Best Wishes
mizzard



Joined: 26 Apr 2009
Posts: 11

View user's profile Send private message

PostPosted: Mon Nov 05, 2012 8:15 am     Reply with quote

Yes, tested with multimeter. I have 3.3V on AVdd pin (number 19) and GND on pin number 20.

Another thing I have detected is when I use set_adc_channel(0) occurs that I have said, but when I use set_adc_channel(1), the dsPIC is continiously on reset.

I have checked an0, an1, Avss, and AVdd lines and I don't find any problem. Confused
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Mon Nov 05, 2012 9:39 am     Reply with quote

Wondering if fuse setup is not right, and it thinks these pins are to be used for ICD/programming. However if you can program the chip this doesn't make sense.

Best Wishes
mizzard



Joined: 26 Apr 2009
Posts: 11

View user's profile Send private message

PostPosted: Mon Nov 05, 2012 9:44 am     Reply with quote

Here are my fuses:
Code:

#include <33EP256MU806.h>
#device adc=10

#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES PUT128                   //Power On Reset Timer value 128ms
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES PR_PLL
#FUSES HS
#FUSES ICSP1
#FUSES OSCIO
#FUSES CKSFSM
#FUSES NOIOL1WAY //Allows multiple reconfigurations of peripheral pins
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