Bonjour à tous,
Je travaille actuellement sur un projet qui a pour but de faire l'acquisition d'un signal avec l'ADC d'un pic16f18.
Je rencontre un problème : quand je branche ma source sur la pin que j'ai configuré pour l'ADC, la tension double!
Par exemple, j'arrive sur la pin de mon pic avec un signal de 1.8V, quand je branche, la tension monte à 3.6V...
J'ai essayé de mettre un aop en suiveur avec un filtre avant d'attaquer l'ADC mais rien ne change.
J'ai sûrement du faire une erreur en configurant l'ADC, ci-joint le code :
I.Code:/** ADCC Generated Driver File @Company Microchip Technology Inc. @File Name adcc.c @Summary This is the generated driver implementation file for the ADCC driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs @Description This source file provides implementations for driver APIs for ADCC. Generation Information : Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.7 Device : PIC16F18446 Driver Version : 2.1.5 The generated drivers are tested against the following: Compiler : XC8 2.31 and above MPLAB : MPLAB X 5.45 */ /* (c) 2018 Microchip Technology Inc. and its subsidiaries. Subject to your compliance with these terms, you may use Microchip software and any derivatives exclusively with Microchip products. It is your responsibility to comply with third party license terms applicable to your use of third party software (including open source software) that may accompany Microchip software. THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. */ /** Section: Included Files */ #include <xc.h> #include "adcc.h" #include "mcc.h" /** Section: ADCC Module Variables */ /** Section: ADCC Module APIs */ void ADCC_Initialize(void) { // set the ADCC to the options selected in the User Interface // ADLTH 0; ADLTHL = 0x00; // ADLTH 0; ADLTHH = 0x00; // ADUTH 0; ADUTHL = 0x00; // ADUTH 0; ADUTHH = 0x00; // ADSTPT 0; ADSTPTL = 0x00; // ADSTPT 0; ADSTPTH = 0x00; // ADACC 0; ADACCU = 0x00; // ADRPT 0; ADRPT = 0x00; // ADPCH ANA0; ADPCH = 0x00; // ADACQ 0; ADACQL = 0x00; // ADACQ 0; ADACQH = 0x00; // ADCAP Additional uC disabled; ADCAP = 0x00; // ADPRE 0; ADPREL = 0x00; // ADPRE 0; ADPREH = 0x00; // ADDSEN disabled; ADGPOL digital_low; ADIPEN disabled; ADPPOL Vss; ADCON1 = 0x00; // ADCRS 0; ADMD Low_pass_filter_mode; ADACLR disabled; ADPSIS RES; ADCON2 = 0x04; // ADCALC First derivative of Single measurement; ADTMD disabled; ADSOI ADGO not cleared; ADCON3 = 0x00; // ADMATH registers not updated; ADSTAT = 0x00; // ADNREF VSS; ADPREF VDD; ADREF = 0x00; // ADACT disabled; ADACT = 0x00; // ADCS FOSC/2; ADCLK = 0x00; // ADGO stop; ADFM right; ADON enabled; ADCS FOSC/ADCLK; ADCONT disabled; ADCON0 = 0x84; } void ADCC_StartConversion(adcc_channel_t channel) { // select the A/D channel ADPCH = channel; // Turn on the ADC module ADCON0bits.ADON = 1; // Start the conversion ADCON0bits.ADGO = 1; } bool ADCC_IsConversionDone(void) { // Start the conversion return ((unsigned char)(!ADCON0bits.ADGO)); } adc_result_t ADCC_GetConversionResult(void) { // Return the result return ((adc_result_t)((ADRESH << 8) + ADRESL)); } adc_result_t ADCC_GetSingleConversion(adcc_channel_t channel) { // select the A/D channel ADPCH = channel; // Turn on the ADC module ADCON0bits.ADON = 1; //Disable the continuous mode. ADCON0bits.ADCONT = 0; // Start the conversion ADCON0bits.ADGO = 1; // Wait for the conversion to finish while (ADCON0bits.ADGO) { } // Conversion finished, return the result return ((adc_result_t)((ADRESH << 8) + ADRESL)); } void ADCC_StopConversion(void) { //Reset the ADGO bit. ADCON0bits.ADGO = 0; } void ADCC_SetStopOnInterrupt(void) { //Set the ADSOI bit. ADCON3bits.ADSOI = 1; } void ADCC_DischargeSampleCapacitor(void) { //Set the ADC channel to AVss. ADPCH = 0x3b; } void ADCC_LoadAcquisitionRegister(uint16_t acquisitionValue) { //Load the ADACQH and ADACQL registers. ADACQH = (uint8_t) (acquisitionValue >> 8); ADACQL = (uint8_t) acquisitionValue; } void ADCC_SetPrechargeTime(uint16_t prechargeTime) { //Load the ADPREH and ADPREL registers. ADPREH = (uint8_t) (prechargeTime >> 8); ADPREL = (uint8_t) prechargeTime; } void ADCC_SetRepeatCount(uint8_t repeatCount) { //Load the ADRPT register. ADRPT = repeatCount; } uint8_t ADCC_GetCurrentCountofConversions(void) { //Return the contents of ADCNT register return ADCNT; } void ADCC_ClearAccumulator(void) { //Reset the ADCON2bits.ADACLR bit. ADCON2bits.ADACLR = 1; } uint24_t ADCC_GetAccumulatorValue(void) { //Return the contents of ADACCU, ADACCH and ADACCL registers return (((uint24_t)ADACCU << 16)+((uint24_t)ADACCH << 8) + ADACCL); } bool ADCC_HasAccumulatorOverflowed(void) { //Return the status of ADSTATbits.ADAOV return ADSTATbits.ADAOV; } uint16_t ADCC_GetFilterValue(void) { //Return the contents of ADFLTRH and ADFLTRL registers return ((uint16_t)((ADFLTRH << 8) + ADFLTRL)); } uint16_t ADCC_GetPreviousResult(void) { //Return the contents of ADPREVH and ADPREVL registers return ((uint16_t)((ADPREVH << 8) + ADPREVL)); } void ADCC_DefineSetPoint(uint16_t setPoint) { //Sets the ADSTPTH and ADSTPTL registers ADSTPTH = (uint8_t) (setPoint >> 8); ADSTPTL = (uint8_t) setPoint; } void ADCC_SetUpperThreshold(uint16_t upperThreshold) { //Sets the ADUTHH and ADUTHL registers ADUTHH = (uint8_t) (upperThreshold >> 8); ADUTHL = (uint8_t) (upperThreshold); } void ADCC_SetLowerThreshold(uint16_t lowerThreshold) { //Sets the ADLTHH and ADLTHL registers ADLTHH = (uint8_t) (lowerThreshold >> 8); ADLTHL = (uint8_t) lowerThreshold; } uint16_t ADCC_GetErrorCalculation(void) { //Return the contents of ADERRH and ADERRL registers return ((uint16_t)((ADERRH << 8) + ADERRL)); } void ADCC_EnableDoubleSampling(void) { //Sets the ADCON1bits.ADDSEN ADCON1bits.ADDSEN = 1; } void ADCC_EnableContinuousConversion(void) { //Sets the ADCON0bits.ADCONT ADCON0bits.ADCONT = 1; } void ADCC_DisableContinuousConversion(void) { //Resets the ADCON0bits.ADCONT ADCON0bits.ADCONT = 0; } bool ADCC_HasErrorCrossedUpperThreshold(void) { //Returns the value of ADSTATbits.ADUTHR bit. return ADSTATbits.ADUTHR; } bool ADCC_HasErrorCrossedLowerThreshold(void) { //Returns the value of ADSTATbits.ADLTHR bit. return ADSTATbits.ADLTHR; } uint8_t ADCC_GetConversionStageStatus(void) { //Returns the contents of ADSTATbits.ADSTAT field. return ADSTATbits.ADSTAT; } /** End of File */
-----