Unable to read ADC Value

CuriousMind

Feb 8, 2017
2
Joined
Feb 8, 2017
Messages
2
Hello All!
I am trying to read ADCValue in my motorized slide pot.So,I have used a break point before the variable which I want to read the ADCValue.But,unfortunately no ADC value is showing in the variables window(not even the type of the variable).
Can someone tell me what is wrong here?Thanks
PS:using dsPIC33EP512MU810

Below is my code:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <p33EP512MU810.h>
#include <xc.h>
#include <libpic30.h>
/****************************CONFIGURATION****************************/
_FOSCSEL(FNOSC_FRC);
_FOSC(FCKSM_CSECMD & POSCMD_XT & OSCIOFNC_OFF & IOL1WAY_OFF);
_FWDT(FWDTEN_OFF);_FPOR(FPWRT_PWR128 & BOREN_ON & ALTI2C1_ON & ALTI2C2_ON);
_FICD(ICS_PGD1 & RSTPRI_PF & JTAGEN_OFF);
void initAdc1(void);
void Delay_us(unsigned int);
int ADCValue, i, j;
int main(void)
{

// Configure the device PLL to obtain 60 MIPS operation. The crystal frequency is 8 MHz.// Divide 8 MHz by 2, multiply by 60 and divide by 2. This results in Fosc of 120 MHz.// The CPU clock frequency is Fcy = Fosc/2 = 60 MHz.
PLLFBD = 58;/* M = 60*/
CLKDIVbits.PLLPOST = 0;/* N1 = 2*/
CLKDIVbits.PLLPRE = 0;/* N2 = 2*/
OSCTUN = 0;
/* Initiate Clock Switch to Primary Oscillator with PLL (NOSC = 0x3) */
__builtin_write_OSCCONH(0x03);
__builtin_write_OSCCONL(0x01);
while (OSCCONbits.COSC != 0x3);// Wait for Clock switch to occur
while (_LOCK == 0);/* Wait for PLL lock at 40 MIPS */
initAdc1();
while(1)
{

Delay_us(100);// Sample for 100 us
AD1CON1bits.SAMP = 0;// Start the conversion
while (!AD1CON1bits.DONE);// Wait for the conversion to complete
AD1CON1bits.DONE = 0;// Clear conversion done status bit
ADCValue = ADC1BUF0;// Read the ADC conversion result
}
}
void initAdc1(void)
{

/* Set port configuration */
ANSELA = ANSELB = ANSELC = ANSELD = ANSELE = ANSELG = 0x0000;
ANSELBbits.ANSB5 = 1;// Ensure AN5/RB5 is analog/* Initialize and enable ADC module */
AD1CON1 = 0x0004;
AD1CON2 = 0x0000;
AD1CON3 = 0x000F;
AD1CON4 = 0x0000;
AD1CHS0 = 0x0005;
AD1CHS123 = 0x0000;
AD1CSSH = 0x0000;
AD1CSSL = 0x0000;
AD1CON1bits.ADON = 1;
Delay_us(20);
}
void Delay_us(unsigned int delay)
{
for (i = 0; i < delay; i++)
{__asm__ volatile ("repeat #39");
__asm__ volatile ("nop");
}
}

BModerators note : used code tags for pieces of code
 

Attachments

  • IMG-20170210-WA0000.jpg
    IMG-20170210-WA0000.jpg
    44.9 KB · Views: 71
Last edited by a moderator:

kshitika

Sep 26, 2020
1
Joined
Sep 26, 2020
Messages
1
Hello curiousMind,

Could you solve this problem? I have referred the same example code.

Do you have the corrected code?

Or can you suggest me any edits?
 

bertus

Moderator
Nov 8, 2019
3,836
Joined
Nov 8, 2019
Messages
3,836
Hello,

@kshitika , Do you realize that the thread is more that 3 years old?
The user did not visit the forum since 10 feb 2017.

Bertus
 
Top