The Preternatural Reading about PIC18F25K80

Discussion of the PICO module, baseboard or peripherals

The Preternatural Reading about PIC18F25K80

Postby bakovsky » Tue Jun 06, 2017 6:17 am

Good day,
I am curently involved in a project about degug ad program of PIC18F25K80 by using mplab, however,the reading is abnormal ! The voltage of reference power supply whether outside or not gotten always under 10. The crystal oscillator outside is 8M and the ad pass is AN0. Can anyone help me? Thank you in advance.
the PIC18F25K80 PDF: http://www.kynix.com/uploadfiles/pdf65976/PIC18F25K80-E2fMM_659162.pdf
The main program:
Code: Select all
while (1)
    {
        // Add your application code
        Adresult=ADC_GetConversion(channel_AN0);//0V-5V  0-1024
        
        
        ledshan(Adresult);IO_RB2_SetHigh();delay500ms();
    }

Sub-program:
Code: Select all
adc_result_t ADC_GetConversion(adc_channel_t channel)
{
    // Select the A/D channel
    ADCON0bits.CHS = channel;

    // Turn on the ADC module
    ADCON0bits.ADON = 1;


    // Start the conversion
    ADCON0bits.GO_nDONE = 1;

    // Wait for the conversion to finish
    while (ADCON0bits.GO_nDONE)
    {
    }
    
    // Conversion finished, return the result

    return ((ADRESH << 8) + ADRESL);
}

Initializing program:
Code: Select all
void PIN_MANAGER_Initialize(void)
{
    /**
    LATx registers
    */   
    LATA = 0x00;   
    LATB = 0x00;   
    LATC = 0x00;   

    /**
    TRISx registers
    */   
    TRISA = 0xEF;
    TRISB = 0xFB;
    TRISC = 0xFF;

    /**
    ANSELx registers
    */   
    ANCON0 = 0x1F;
    ANCON1 = 0x07;

    /**
    WPUx registers
    */
    WPUB = 0xFF;

   


   
   
}
void OSCILLATOR_Initialize(void)
{
    // SCS FOSC; HFIOFS not stable; IDLEN disabled; IRCF 8MHz_HF;
    OSCCON = 0x60;
    // SOSCGO disabled; MFIOSEL disabled; SOSCDRV Low Power;
    OSCCON2 = 0x00;
    // INTSRC INTRC; PLLEN disabled; TUN 0;
    OSCTUNE = 0x00;
    // ROSEL System Clock(FOSC); ROON disabled; ROSSLP Disabled in Sleep mode; RODIV Fosc;
    REFOCON = 0x00;
    // Set the secondary oscillator
   
}
void ADC_Initialize(void)
{
    // set the ADC to the options selected in the User Interface
   
    // GO_nDONE stop; ADON enabled; CHS AN0;
    ADCON0 = 0x01;
   
    // TRIGSEL ECCP1; VNCFG AVSS; VCFG internal_2.048V; CHSN AN0;
    ADCON1 = 0x21;
   
    // ADFM Right; ACQT 4_Tad; ADCS FOSC/8;
    ADCON2 = 0x91;
   
    // ADRESH 0;
    ADRESH = 0x00;
   
    // ADRESL 0;
    ADRESL = 0x00;
   
}


Best regards~
bakovsky
 
Posts: 1
Joined: Tue Jun 06, 2017 3:33 am

Return to Hardware and peripherals

Who is online

Users browsing this forum: No registered users and 3 guests