10 bit ADC in dpsic30f2010

Discussion in 'Embedded Systems and Microcontrollers' started by dick l, Jul 30, 2013.

  1. dick l

    Thread Starter New Member

    Jul 30, 2013
    1
    0
    I am using the 2010 to control 3 BDC motors speed set by separate unit with pic16f688 digitising pots and sending via RS232 to 2010 timers RS232 and PWM all ok but I don't understand the ADC in the dspic30 tried many times but never works, I want to read 3 tachos and another analogue signal simultaneously for the PID loops here is my init ADC

    Code ( (Unknown Language)):
    1.  
    2. void setup_ADC(void)
    3. {
    4.  ADCON1bits.ADON = 0;  //15 ADC off
    5.  ADCON1bits.ADSIDL = 0;  //13 continuous was  
    6.  ADCON1bits.FORM = 0;  //9-8 output data in raw format
    7.  ADCON1bits.SSRC = 7;  //7-5 auto convert
    8.  ADCON1bits.SIMSAM = 1;  //3 enable simultaneous sampling
    9.  ADCON1bits.ASAM = 0; //2 no auto start
    10.  ADCON1bits.SAMP = 0; //1 holding
    11.  ADCON1bits.DONE= 0;  //0 not done
    12.  
    13.  ADCON2bits.VCFG = 0; //15-13 AVDD and AVSS reference
    14.  ADCON2bits.CSCNA = 0; //10 do not scan inputs
    15.  ADCON2bits.CHPS = 2; //9-8 convert ch0,1,2,3 channels
    16.  ADCON2bits.BUFS = 0; //7 lower buff
    17. // ADCON2bits.SMPI = 0; //5-2 interrupt after sample sequence
    18.  ADCON2bits.BUFM = 0; //1 single buffer
    19.  ADCON2bits.ALTS = 0; //0 use MUXA
    20.  ADCON3bits.SAMC = 31;   //12-8 Total time = (15 + 15) * Tad = 12us
    21.  ADCON3bits.ADRC = 0; //7 system clock
    22.  ADCON3bits.ADCS = 63; //5-0 ADC clock  Tad = Tcy(ADCS + 1) / 2
    23.  ADCHSbits.CH123SA = 0;  // AN0 = CH1,AN1 = CH2, AN2 = CH3
    24.  ADCHSbits.CH0SA = 3;  // CH0 = AN3
    25.  ADPCFG = 0xFFF0;  // AN0-3 analogue inputs
    26.  ADCSSL = 0x0000;
    27.  
    28.  ADCON1bits.ADON = 1; // start
    29. }
    30.  
    can anyone help dick l
     
    Last edited by a moderator: Jul 30, 2013
Loading...