Storage of ADC result in dsPIC

Status
Not open for further replies.

angeline

Newbie level 5
Joined
Mar 4, 2008
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,354
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 ?

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
 

adc interrupt dspic

I don't know much about ADC beside what can be seen in the datasheet:


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
at the beginning you need to declare an array and a pointer:
Code:
#define N 128
unsigned int array[N];
unsigned int* array_pointer=array;

than you need to perform your conversion N times in this way:
*array_pointer++=ADCBUF0;

you need to ensure, that this will happen only N times, because the pointer writes beyound array size will destroy variables in RAM which were above the array and probably may do many crazy things...

you can do it the safe way, without pointers:
Code:
int i;
for(i=0;i<N;i++)
{
ADCON1bits.SAMP = 1; // start sampling then ... 
// after 31Tad go to conversion 
while (!ADCON1bits.DONE); // conversion done? 
  array[i] = ADCBUF0; // yes then get ADC value 
}

good luck with the main issue...

0x41 0x56 0x45!!
 

store adc samples in array dspic30f

Thanks a lot for your advice ... MAnage to try this afternoon ... ya i get over the ADC part ... now trying the main FFT ... =) thanks a lot freddie chopin ...
 

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…