Vorrei andare a configurare AN0 AN1 AN2 e AN3 con ingressi analogici e campionarli
contemporaneamente intorno ai 100Ks/s
Ho impostato i registri e campiono correttamente AN1-2-3 ma non riesco a venirne fuori con AN0
vi allego il codice :
Code:
//inizializzazione adc
ADCON1bits.ADON=0;
ADCON1bits.ADSIDL=0; // 0 = Continue module operation in Idle mode
ADCON1bits.FORM=0b00; // 00 = Integer (DOUT = 0000 00dd dddd dddd)
ADCON1bits.SSRC=0b111; // 111 = Internal counter ends sampling and starts conversion (auto convert)
ADCON1bits.SIMSAM=1; // 1 = Samples CH0, CH1, CH2, CH3 simultaneously (when CHPS = 1x)
ADCON1bits.ASAM=1; // 0 = Sampling begins when SAMP bit set
ADCON1bits.SAMP=0; // When ASAM = 0, writing ‘1’ to this bit will start sampling
ADCON2bits.VCFG=0b000; // AVSS AVDD selected
ADCON2bits.CSCNA=0; // do not scan imputs
ADCON2bits.CHPS=0b10; // 1x = Converts CH0, CH1, CH2 and CH3
ADCON2bits.SMPI=0b1111; // 1111 = Interrupts at the completion of conversion for each 16th sample/convert sequence
ADCON2bits.BUFM=0; // 0 = Buffer configured as one 16-word buffer ADCBUF(15...0)
ADCON2bits.ALTS=0; // 0 = Always use MUX A input multiplexer settings
ADCON3bits.SAMC=0b01000; // 01000 = 8 TAD max = 11111 0 32 TAD
ADCON3bits.ADRC=0; // 0 = Clock derived from system clock
ADCON3bits.ADCS=0b001011;// = TCY/2 • (ADCS<5:0> + 11)
ADCHSbits.CH123NB=0b00; // come sotto
ADCHSbits.CH123SB=0; //
ADCHSbits.CH0NB=0; //
ADCHSbits.CH0SB=0b0011; //
ADCHSbits.CH123NA=0b00; // CH1, CH2, CH3 negative input is VREF-
ADCHSbits.CH123SA=0; // CH1 positive input is AN0, CH2 positive input is AN1, CH3 positive input is AN2
ADCHSbits.CH0NA=0; // Channel 0 negative input is VREF-
ADCHSbits.CH0SA=0b0011; // Channel 0 Positive Input Select for MUX A Multiplexer Setting bits Channel 0 positive input is AN3
ADPCFGbits.PCFG0=0; // 0 = Analog input pin in Analog mode AN0/RB0
ADPCFGbits.PCFG1=0; // 0 = Analog input pin in Analog mode AN1/RB1
ADPCFGbits.PCFG2=0; // 0 = Analog input pin in Analog mode AN2/RB2
ADPCFGbits.PCFG3=0; // 0 = Analog input pin in Analog mode AN3/RB3
ADPCFGbits.PCFG4=1; // 0 = Analog input pin in DIGITAL mode AN4/RB4
ADPCFGbits.PCFG5=1; // 0 = Analog input pin in DIGITAL mode AN5/RB5
ci sono un paio di cose che non mi sono chiare nel datasheet
ADCON2bits.VCFG puo' essere impostato a 0b000 opuure a 0b1xx per avere VrefH=AVDD e VrefL=AVSS , entrambe le impostazioni sono equivalenti ?