angeline
Newbie level 5
dspic adc
I am doing ADC on a current signal to perform FFT using DSPIC30F3010. I have written the ADC coding with help from the data sheet . The result should be store in ADCBUF0 .
However , when I try to view the result using MPLAB IDE under IDC2 debugger mode , the value of the register ADCBUF0 not changing, instead the changing one is ADCBUF4-7.
I have list my code below can someone please give me some advice ?
I also know that this ADC value have to store as an array to be used later for FFT. MAy I know how to do that? Thanks in advance
I am doing ADC on a current signal to perform FFT using DSPIC30F3010. I have written the ADC coding with help from the data sheet . The result should be store in ADCBUF0 .
However , when I try to view the result using MPLAB IDE under IDC2 debugger mode , the value of the register ADCBUF0 not changing, instead the changing one is ADCBUF4-7.
I have list my code below can someone please give me some advice ?
Code:
#include <p30f3010.h>
void SETUP_ADC (void);
int main (void)
{
int ADCValue;
TRISD=0;
SETUP_ADC();
ADCON1bits.ADON=1;
while(1)
{
ADCON1bits.SAMP = 1; // start sampling then ...
// after 31Tad go to conversion
while (!ADCON1bits.DONE); // conversion done?
ADCValue = ADCBUF0; // yes then get ADC value
// repeat // repeat
}
return(0);
}
void SETUP_ADC (void)
{
ADPCFGbits.PCFG1 = 0;
ADCON1 = 0x00E0; // SSRC bit = 111 implies internal
// counter ends sampling and starts
// converting.
ADCHS = 0;
ADCHSbits.CH0NA=0;
ADCHSbits.CH0SA=2;
ADCSSL = 0;
ADCON3 = 0x1F02; // Sample time = 31Tad, Tad = internal 2 Tcy
ADCON2 = 0;
}
//ADCON1bits.ADON = 1; // turn ADC ON
// while (1) // repeat continuously
//{
// ADCON1bits.SAMP = 1; // start sampling then ...
//// after 31Tad go to conversion
//while (!ADCON1bits.DONE); // conversion done?
// ADCValue = ADCBUF0; // yes then get ADC value
//} // repeat // repeat
I also know that this ADC value have to store as an array to be used later for FFT. MAy I know how to do that? Thanks in advance