Modulo ADC DSPIC30 a la máxima velocidad

Hola a todos mi problema es el siguiente:

El programa es una simple prueba para determinar el buen funcionamiento del ADC, lo unico que pretende hacer es que convierta una señal análoga que se ingresa por el pin AN3 y apage el pin D0 si el resultado del buffer ADCBUF0 esta entre 0 y 255 y tambien apague el pin D2 pero si el resultado de ADCBUF1 esta en el rango antes mencionado. lo que ocurre es que solo enciende y apaga el pin D0 lo que indica que el resultado de la conversion en ADCBUF0 esta bien pero el pin D2 siempre se mantiene en 0.

Estoy intentando configurar el modulo ADC del DSPIC30F para que trabaje a 1 mega muestra por segundo. Pero el resultado de esto se debe guardar en ADCBUF0 y ADCBUF1 pero solo se guarda el resultado en ADCBUF0 el otro buffer (ADCBUF1) no me guarda el resultado de la conversion. no se si me falta algun registro por que solo me funciona un buffer y el otro no????

el codigo es un adaptado para el DSPIC ya mensionado de un ejemplo que esta en la pagina de la microchip.

el main principal es:

Código:
#include "p30f4011.h"
_FOSC(CSW_FSCM_OFF & XT_PLL16);                            
_FWDT(WDT_OFF);                
_FBORPOR(MCLR_EN & PWRT_OFF);   
_FGS(CODE_PROT_OFF);       

int main (void);
int main (void)
{
        TRISD = 0;
        ADC_Init();             //Initialize the A/D converter

        while (1);
        return 0;
}



Las funciones estan en:

Código:
#include "p30f4011.h"

unsigned int ADCcode1 = 0;
unsigned int ADCcode2  = 0;


//Functions and Variables with Global Scope:
void ADC_Init(void);
void __attribute__((__interrupt__)) _ADCInterrupt(void);

//Functions:
//ADC_Init() is used to configure A/D to convert 16 samples of 1 input
//channel per interrupt. The A/D is set up for a sampling rate of 1MSPS
//Timer3 is used to provide sampling time delay.
//The input pin being acquired and converted is AN7.
void ADC_Init(void)
{
        //ADCON1 Register
        //Set up A/D for Automatic Sampling
        //Use internal counter (SAMC) to provide sampling time
        //Set up A/D conversrion results to be read in 1.15 fractional
        //number format.
        //Set up Sequential sampling for multiple S/H amplifiers
        //All other bits to their default state
        ADCON1bits.FORM = 0;
        ADCON1bits.SSRC = 7;
        ADCON1bits.ASAM = 1;
        ADCON1bits.SIMSAM = 0;

        //ADCON2 Register
        //Set up A/D for interrupting after 2 samples get filled in the buffer
        //Set up to sample on 2 S/H amplifiers - CH0 and CH1
        //All other bits to their default state
        ADCON2bits.SMPI = 1;
        ADCON2bits.CHPS = 1;
	ADCON2bits.VCFG = 3; //Ideally use external references

        //ADCON3 Register
        //We would like to set up a sampling rate of 1 MSPS
        //Total Conversion Time= 1/Sampling Rate = 125 microseconds
        //At 29.4 MIPS, Tcy = 33.9 ns = Instruction Cycle Time
        //The A/D converter will take 12*Tad periods to convert each sample
        //So for ~1 MSPS we need to have Tad close to 83.3ns
        //Using equaion in the Family Reference Manual we have
        //ADCS = 2*Tad/Tcy - 1
        ADCON3bits.SAMC = 0;
        ADCON3bits.ADCS = 4;

        //ADCHS Register
        //Set up A/D Channel Select Register to convert AN3 on Mux A input
        //of CH0 and CH1 S/H amplifiers
        ADCHS = 0x0023;

        //ADCSSL Register
        //Channel Scanning is disabled. All bits left to their default state
        ADCSSL = 0x0000;

        //ADPCFG Register
        //Set up channels AN3 as analog input and configure rest as digital
        //Recall that we configured all A/D pins as digital when code execution
        //entered main() out of reset
        ADPCFG = 0xFFFF;
        ADPCFGbits.PCFG3 = 0;

        //Clear the A/D interrupt flag bit
        IFS0bits.ADIF = 0;

        //Set the A/D interrupt enable bit
        IEC0bits.ADIE = 1;

        //Turn on the A/D converter
        //This is typically done after configuring other registers
        ADCON1bits.ADON = 1;



}

//_ADCInterrupt() is the A/D interrupt service routine (ISR).
//The routine must have global scope in order to be an ISR.
//The ISR name is chosen from the device linker script.
void __attribute__((interrupt, no_auto_psv)) _ADCInterrupt(void)
{

    ADCcode1 = ADCBUF0;
    ADCcode2 = ADCBUF1;
    if(ADCcode1 <= 512 && ADCcode1 >= 0)
    PORTDbits.RD0 = 0;
    else
    PORTDbits.RD0 = 1;
    if(ADCcode2 <= 512 && ADCcode2 >= 0)
    PORTDbits.RD2 = 0;
    else
    PORTDbits.RD2 = 1;
	
        //Clear the A/D Interrupt flag bit or else the CPU will
        //keep vectoring back to the ISR

        IFS0bits.ADIF = 0;
 
}
 
Atrás
Arriba