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.

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:

16.4 ADC MODULE CONFIGURATION
The following steps should be followed for performing an A/D conversion:
1. Select 10-bit or 12-bit mode (ADxCON1<10>)
2. Select voltage reference source to match expected range on analog inputs
(ADxCON2<15:13>)
3. Select the analog conversion clock to match desired data rate with processor clock
(ADxCON3<7:0>)
4. Select port pins as analog inputs (ADxPCFGH<15:0> and ADxPCFGL<15:0>)
5. Determine how inputs will be allocated to Sample/Hold channels (ADxCHS0<15:0> and
ADxCHS123<15:0>)
6. Determine how many Sample/Hold channels will be used (ADxCON2<9:8>, ADx-
PCFGH<15:0> and ADxPCFGL<15:0>)
7. Determine how sampling will occur (ADxCON1<3>, ADxCSSH<15:0> and ADxCSSL<
15:0>)
8. Select Manual or Auto Sampling
9. Select conversion trigger and sampling time.
10. Select how conversion results are stored in the buffer (ADxCON1<9:8>)
11. Select interrupt rate or DMA buffer pointer increment rate (ADxCON2<9:5>)
12. Select the number of samples in DMA buffer for each ADC module input
(ADxCON4<2:0>)
13. Select the data format
14. Configure ADC interrupt (if required)
• Clear ADxIF bit
• Select interrupt priority (ADxIP<2:0)
• Set ADxIE bit
15. Configure DMA channel (if needed)
16. Turn on ADC module (ADxCON1<15>)

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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top