Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with getting constant digital value of dspic33f ADC

Status
Not open for further replies.

fuzedmass

Junior Member level 2
Joined
Apr 11, 2011
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,527
Hello,

I am currently using DSPIC33fJ128GP710 at 80MHZ (FRC with PLL). I am using the ADC of dspic33f in
1. 12bit mode.
2. Vref+ = 3.3v & Vref-=0v.
3. I have configured TAD and Sampling time to be automatic.

Now the problem I am facing is that the digital value is not constant, I mean I know that you get a very very small error but in my case ADC always shows +-300 digital value error on a constant voltage (using online debugging of PICkit2 I have noted the digital value), I have also configured 10bit ADC but this problem still persisted.

Should I configure TAD and Sampling time to be maximum, is this the problem ?

My CODE:

//
AD1CSSH=0x1000; //select AN28 for analog input
//


AD1CHS0 = 28; // channel input is AN28
AD1CON1bits.ASAM = 1; // SAMP bit auto set
AD1CON1bits.SSRC = 7; // auto sampling and convert
AD1CON1bits.AD12B = 1; // select 12-bit, 1 channel ADC operation
// No channel scan for CH0+, Use MUX A, SMPI = 1 per interrupt, Vref = AVdd/AVss
AD1CON2 = 0x0000;
AD1CON3bits.SAMC=0x3; // auto sample time
AD1CON3bits.ADCS=0x1f; // conversion clock select
IFS0bits.AD1IF = 0; // reset ADC interrupt flag
AD1CON1bits.ADON = 1; // turn on ADC module
while(IFS0bits.AD1IF == 0); // wait for conversion
AD1CON1bits.ADON = 0; // turn off ADC module
IFS0bits.AD1IF = 0; // reset ADC interrupt flag


Please Help me. Thanks
 

Re: dspic33f ADC problem

tried you code on an Explorer 16 with a DSPIC33fJ128GP710 PIM reading the potentiometer on AN5
Code:
// initialise ADC1 to read AN5 - potentiometer on Explorer 16
void ADC1initialise( void )
{
 	AD1PCFGLbits.PCFG5 = 0;         // ensure AN5/RB5 is analog (Analog Pot)
	AD1CHS0 = 0x0005;				// channel input is AN5 		
//
//AD1CSSH=0x1000; //select AN28 for analog input
//

//AD1CHS0 = 28; // channel input is AN28
AD1CON1bits.ASAM = 1; // SAMP bit auto set
AD1CON1bits.SSRC = 7; // auto sampling and convert
AD1CON1bits.AD12B = 1; // select 12-bit, 1 channel ADC operation
// No channel scan for CH0+, Use MUX A, SMPI = 1 per interrupt, Vref = AVdd/AVss
AD1CON2 = 0x0000;
AD1CON3bits.SAMC=0x3; // auto sample time
AD1CON3bits.ADCS=0x1f; // conversion clock select
IFS0bits.AD1IF = 0; // reset ADC interrupt flag
AD1CON1bits.ADON = 1; // turn on ADC module
//while(IFS0bits.AD1IF == 0); // wait for conversion
//AD1CON1bits.ADON = 0; // turn off ADC module
//IFS0bits.AD1IF = 0; // reset ADC interrupt flag
}

// read ADC1
int ADC1read( void )
{	
	while(IFS0bits.AD1IF == 0) Nop(); //  wait for conversion           
	IFS0bits.AD1IF = 0; 			//  reset ADC interrupt flag           
	return ADC1BUF0;       			// read ADC1 data      
}
appears to be OK, e.g. sample output
Code:
dsPIC33 test program
Fosc 84000000
868 991
871 991
869 987
868 992
872 984
869 983
875 990
1304 983
1311 991
1310 991
1307 983
1319 986
1316 984
1310 984
1312 980
1311 989
the first column is calling ADC1read() - you can see when I changed the pot value from 875 to 1304
some variation in reading but that is expected
are you sure you have a stable voltage on AN28?
 

Re: dspic33f ADC problem

the voltage is constant :(

---------- Post added at 18:49 ---------- Previous post was at 18:49 ----------

so my configurations are right then ???
 

Re: dspic33f ADC problem

the only thing I changed was to change the analogue input from AN28 to AN5
however, looking at yout code again the following statement looks incorrect
Code:
AD1CSSH=0x1000; //select AN28 for analog input
looking at the specification of AD1PCFGH it states
1 = Port pin in Digital mode, port read input enabled, ADC input multiplexer connected to AVSS
0 = Port pin in Analog mode, port read input disabled, ADC samples pin voltage

try changing the above statement to
Code:
 	AD1PCFGHbits.PCFG28 = 0;         // ensure AN28 is analog
 

Re: dspic33f ADC problem

Dear fuzedmass
I am also trying to learn dsPIC33F.
Can you hlp me how shoul i program dsPIC33 IC.
what software is required. I have MPLAB.
Thanks in advance.

---------- Post added at 06:57 ---------- Previous post was at 06:54 ----------

I have Microstick DM330013 dev board.
I it not detected by computer.
Please can you help me in loading hex file in the IC.
 

download and instal the dsPIC compiler from
**broken link removed**

to test the Microstick download Microstick Flash LED from
**broken link removed**

instal the dsPIC33FJ64MC802 in the Microstick
start MPLAB in Configure > Select Device select the dsPIC33FJ64MC802
in main_led.c and traps.c replace
#include "p24hxxxx.h" /* generic header for PIC24H family */
with
#include "p33FJ64MC802.h"

hit F10 to build the program
connect the Microstick and the Output window should show it is connected
select Debugger > Select Tool > Starter kits
select Debugger > Program
select Debugger > Run
the LED should flash
 

    V

    Points: 2
    Helpful Answer Positive Rating
Thanks horace1
The programme is build.
But the kit is not detected by the computer.
What could be the problem ?
 

check the operating system is finding the microstick, e.g. Windows 7
1. click Control Panel > System > Device Manager > Human Interface Devices
2. you should see a list of HID devices
3. plug in the microstick
4. you should see two new HID devices appear in the list

in MPLAB if you select Debugger > Select tool > 11 Starter kits
the output window should show
StarterKit.jpg

make sure you have the latest version of MPLAB
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top