Timer 3 dspic30F Resetea


Me estoy peleando con el ADC del dspic30F6013A. Quiero configurar el ADC con el timer3, pero cuando activo el T3, T3CONbits.TON=1, el dsp se resetea.

Alguien podría explicarme qué está mal?

muchas gracias

Mi código es el siguiente:

void ADCInit (){

        //ADCON1 Register
        //Set up A/D for Automatic Sampling
        //Use Timer3 to provide sampling time
        //Set up A/D conversrion results to be read in 1.15 fractional
        //number format.
        //All other bits to their default state
        ADCON1bits.FORM = 3;
        ADCON1bits.SSRC = 2;
        ADCON1bits.ASAM = 1;

        //ADCON2 Register
        //Set up A/D for interrupting after 16 samples get filled in the buffer
        //All other bits to their default state
        ADCON2bits.SMPI = 15;
        //ADCON3 Register
        //We would like to set up a sampling rate of 8KHz
        //Total Conversion Time= 1/Sampling Rate = 125 microseconds
        //At 20 MIPS, Tcy = 50 ns = Instruction Cycle Time
        //Tad > 667ns (for -40C to 125C temperature range)
        //We will set up Sampling Time using Timer3 & Tad using ADCS<5:0> bits
        //All other bits to their default state
        //Let's set up ADCS arbitrarily to the maximum possible amount = 63
        //So Tad = Tcy*(ADCS+1)/2 = 1.6 microseconds
        //So, the A/D converter will take 14*Tad periods to convert each sample (12-bits ADC) =  14*1.6usec= 22.4usec. 
        ADCON3bits.ADCS = 63;

        //Next, we will to set up Timer 3 to time-out every 125 microseconds
        //As a result, the module will stop sampling and trigger a conversion
        //on every Timer3 time-out, i.e., 125 microseconds. At that time,
        //the conversion process starts and completes 14*Tad periods later.
        //When the conversion completes, the module starts sampling again
        //However, since Timer3 is already on and counting, about 103 (102.6usec)
        //microseconds later (=125 microseconds - 14*Tad), Timer3 will expire
        //again. Effectively, the module samples for 103 microseconds and
        //converts for 15 microseconds
        //NOTE: The actual sampling rate realized may be 7998.698 Hz (103 + 14*1.6 = 7974.48Hz)
        //      due to a small round off error. Ensure you provide the
        //      true sampling rate to dsPICworks if you are trying to plot
        //      the sampled or filtered signal.

        TMR3 = 0x0000;
        PR3 = SAMPCOUNT; // (FCY/SAMPLINGRATE)+1 = ((FOSC*PLL/4)/SAMPLINGRATE)+1 = ((10000000*8/4)/8000)+1 = 2501
        IFS0bits.T3IF = 0;
        IEC0bits.T3IE = 0;

        //ADCHS Register
        //Set up A/D Channel Select Register to convert AN3 on Mux A input
        ADCHS = 0x0003;

        //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;

        //Start Timer 3
        T3CONbits.TON = 1;
¿Has seguido estos pasos?
Configure the ADC module:
a) Configure the analog pins, voltage reference and digital I/O.
b) Select the ADC input channels.
c) Select the ADC conversion clock.
d) Select the ADC conversion trigger.
e) Turn on the ADC module.

Mi error es que el codigo estaba mal ordenado, antes tenía:

void __attribute__ ((__interrupt__, no_auto_psv)) _ADCInterrupt(void)
(el codigo)

void ADCInit (){
y lo correcto es:

void ADCInit (){

void __attribute__ ((__interrupt__, no_auto_psv)) _ADCInterrupt(void)
(el codigo)
Muchas gracias por tu intención de ayudarme!

Temas similares