ADC trouble with dsPIC33FJ32MC204 - (MPlab/c30/RTDM)

Status
Not open for further replies.

zsolt1

Full Member level 6
Joined
Aug 11, 2012
Messages
367
Helped
50
Reputation
100
Reaction score
49
Trophy points
1,308
Location
Cluj-Napoca, Romania
www.et.utcluj.ro
Activity points
3,880
hi,
I am facing a problem with the ADC module of dsPIC33FJ32MC205 chip. The problem is that i can't get the voltage from any ANx pin . Am I doing something vrong i the code ?
...
OpenADC1(
ADC_MODULE_ON & ADC_IDLE_STOP & ADC_ADDMABM_ORDER &
ADC_AD12B_10BIT & ADC_FORMAT_SIGN_FRACT & ADC_CLK_AUTO &
ADC_AUTO_SAMPLING_OFF & ADC_MULTIPLE & ADC_SAMP_ON,

ADC_VREF_AVDD_AVSS & ADC_SCAN_OFF & ADC_SELECT_CHAN_0 &
ADC_DMA_ADD_INC_1 & ADC_ALT_BUF_OFF & ADC_ALT_INPUT_OFF ,

ADC_CONV_CLK_SYSTEM & ADC_SAMPLE_TIME_14 & ADC_CONV_CLK_14Tcy,

0,

ENABLE_AN3_ANA,
0,

0,
0
);
while(BusyADC1());
Isa = ADC1BUF0*0.00322;
CloseADC1();

...
I use Mplab with c30 , to view the result i use Mplab's RTDM feature . AN3 pin is input -TRISB1 is set- and i have 1.6 V on it, from opamp ...
 

Hi see this code this works fine on dsPIC33FJ64MC506A.
Code:
#define AINPUTS 	0xE1C3 
#define TTSENS1	TRISBbits.TRISB2	// Temperature Sensor
#define TCH1BAT12 	TRISBbits.TRISB10 	// +12V Channel 1
#define TCH2BAT12 	TRISBbits.TRISB11 	// +12V Channel 2
#define TCH1BAT24 	TRISBbits.TRISB3	// +24V Channel 1
#define TCH2BAT24 	TRISBbits.TRISB4	// +24V Channel 2
#define TCH3BAT24 	TRISBbits.TRISB5	// +24V Channel 3
#define TCH1BAT48 	TRISBbits.TRISB12	// +48V Channel 1
#define TCH2BAT48 	TRISBbits.TRISB9	// +48V Channel 2
void InitADC(int amask) 
{
	InitADCPins();
	AD1PCFGL = amask;
	//ConfigPinsAsAnalog();
	AD1CON1 = 0;			// Clear it
	AD1CON1bits.AD12B = 1;	// 12-bit, 1-channel ADC operation
	AD1CON1bits.FORM  = 0;	// Integer (DOUT = 0000 dddd dddd dddd)
	AD1CON1bits.SSRC  = 0;	// SSRC bit = 111 implies internal counter ends sampling and starts converting.
	AD1CON2bits.CSCNA = 0;	// NO Scan required
	AD1CON2bits.VCFG  = 0; 	// AVss and AVdd are used as Vref+/- 
	AD1CON3 = 0x1F02; 		// max sample time = 31Tad, Tad = 2 x Tcy = 125ns >75ns
    IFS0bits.AD1IF = 0;		// Clear the A/D interrupt flag bit
    IEC0bits.AD1IE = 0;		// Do Not Enable A/D interrupt
    AD1CON1bits.ADON = 1;	// turn on the ADC
} //initADC
void InitADCPins(void)
{
// make pins input
	TTSENS1   = 1;	// Temperature Sensor
	TCH1BAT24 = 1;	// +24V Channel 1
	TCH2BAT24 = 1;	// +24V Channel 2
	TCH3BAT24 = 1;	// +24V Channel 3
	TCH1BAT48 = 1;	// +48V Channel 1
	TCH2BAT48 = 1;	// +48V Channel 2
	TCH1BAT12 = 1;  // +12V Channel 1
	TCH2BAT12 = 1;  // +12V Channel 2 
}
void ConfigPinsAsAnalog(void)
{
	AD1PCFGLbits.PCFG2 = 0;
	AD1PCFGLbits.PCFG3 = 0;
	AD1PCFGLbits.PCFG4 = 0;
	AD1PCFGLbits.PCFG5 = 0;
	AD1PCFGLbits.PCFG9 = 0;
	AD1PCFGLbits.PCFG10 = 0;
	AD1PCFGLbits.PCFG11 = 0;
	AD1PCFGLbits.PCFG12 = 0;	
}
int ReadADC(char Analogchannel)
{
	AD1CHS0bits.CH0SA = Analogchannel;	// Connect ANX to CH0 input 
	asm("nop");							// Some delay
	asm("nop");
	asm("nop");
    AD1CON1bits.SAMP = 1;       		// start sampling, automatic conversion will follow
    TDelayms(5);						// Some delay
    AD1CON1bits.SAMP = 0;       		// start sampling, automatic conversion will follow
    while (!AD1CON1bits.DONE);  		// wait to complete the conversion
    return ADC1BUF0;            		// read the conversion result
}
write the number of analog channel and get the value!
enjoy!
 

    V

    Points: 2
    Helpful Answer Positive Rating
thanks , i adapted the code to my application, it works fine ... i don't know why peripheral library functions for adc failed, i don't have time to debug that now

best regards
z
 
Last edited:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…