Hot!pic24f Adc sampling

Author
swatvv
Starting Member
  • Total Posts : 68
  • Reward points : 0
  • Joined: 2016/12/09 21:48:04
  • Location: 0
  • Status: offline
2017/10/14 02:41:50 (permalink)
0

pic24f Adc sampling

Hi,
i using pic24fj256gb106 and xc16 compiler and mplab x ide v3.55.
i just trying to sample the pwm square pulse of 40Hz to 60Hz and different duty cycle(pulse voltage diff is 600mV to 1.2V). i have slope on the square pulse.i need to sample the slope. 32MHz Fosc. if use the manual mode or auto mode, it results 0x0000 always. is that possible to sample this frequency pulse with this Fosc? i have 2.2K source impedence.
#1

5 Replies Related Threads

    DarioG
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re: pic24f Adc sampling 2017/10/14 08:17:38 (permalink)
    3 (1)
    Sure you can, yep.
     
    Maybe show your code...

    Dario Greggio
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #2
    Kayvon
    Starting Member
    • Total Posts : 59
    • Reward points : 0
    • Joined: 2010/04/21 16:01:54
    • Location: USA
    • Status: offline
    Re: pic24f Adc sampling 2017/10/25 09:49:07 (permalink)
    3 (1)
    That device samples at up to 500ksps, so your ability to sample the slope is limited by that.
    If you're always reading zero on your ADC, it sounds like something is amiss. How are the pins configured? How much sample/conversion time are you using? Start with a basic ADC read before jumping to the square wave.
    #3
    swatvv
    Starting Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2016/12/09 21:48:04
    • Location: 0
    • Status: offline
    Re: pic24f Adc sampling 2017/11/04 05:07:33 (permalink)
    0
    I used this sample code from corresponding reference manual. To test i do free running adc like below code.
     
    unsigned int count;
    unsigned int *ADC16Ptr;
    unsigned int ADCValue[16];
    AD1PCFG = 0xFFFE; // Only AN0 as analog input
    AD1CON1 = 0x00E0; // Internal counter triggers conversion
    AD1CHS = 0x0000; // Connect AN0 as positive input
    AD1CSSL = 0;
    AD1CON3 = 0x0F00; // Sample time = 15Tad, Tad = Tcy
    AD1CON2 = 0x003C; // Set AD1IF after every 16 samples
    AD1CON1bits.ADON = 1; // turn ADC ON
    while(1) // repeat continuously
    {
    ADCValue = 0; // clear value
    ADC16Ptr = (unsigned int*)&ADC1BUF0; // initialize ADC1BUF pointer
    IFS0bits.AD1IF = 0; // clear ADC interrupt flag
    AD1CON1bits.ASAM = 1; // auto start sampling for 31Tad
    // then go to conversion
    while (!IFS0bits.AD1IF){}; // conversion done?
    AD1CON1bits.ASAM = 0; // yes then stop sample/convert
    for (count = 0; count < 16; count++) // average the 16 ADC value
    {
    ADCValue[count] = *(ADC16Ptr++);
    }
    ADCValue = ADCValue >> 4;
    } // repeat

     
    i just read this value by putting breaking point while running.
    all the arrays are 0x000 always;
    #4
    swatvv
    Starting Member
    • Total Posts : 68
    • Reward points : 0
    • Joined: 2016/12/09 21:48:04
    • Location: 0
    • Status: offline
    Re: pic24f Adc sampling 2017/11/06 23:32:15 (permalink)
    0
    I Use PGEC1 and PGED1 to debug. (PGEC2 and PGED2 used to some other purpose)so i suspect this below Errata maybe for the result value of zero.
    If it is the problem then is there any automated testing to take the result by Perl programming while running with Mplab x ide v3.55?
     
    24. Module:
    A/D Converter When using PGEC1 and PGED1 to debug an application on any 64-pin devices in this family, all voltage references will be disabled. This includes VREF+, VREF-, AVDD and AVSS. Any A/D conversion will always equal 0x3FF. Work around Use PGEC2 and PGED2 to debug any A/D functionality.
     
     
    #5
    Kayvon
    Starting Member
    • Total Posts : 59
    • Reward points : 0
    • Joined: 2010/04/21 16:01:54
    • Location: USA
    • Status: offline
    Re: pic24f Adc sampling 2017/11/14 09:10:55 (permalink)
    0
    Nice find on that errata. I've gotten in the habit of checking the errata before finalizing my board design--it's saved me a couple times.
     
    I don't know how you'd integrate Perl with MPLAB. Totally different systems with different programming languages. What you could do, however, is run the chip without the debugger and use the UART to read out values. That would also allow for some Perl integration.
    #6
    Jump to:
    © 2017 APG vNext Commercial Version 4.5