Menu

Low voltage detection

Jose Houle
2026-02-08
2026-02-19
  • Jose Houle

    Jose Houle - 2026-02-08

    hello guys,
    I need your help :)
    I can't find a way to measure Vdd and compare it to a voltage reference generated by the PIC.

    The main objective is to set off every output if a short circuit happen in a any output circuit.
    So I need to detect when Vdd is dropping to low..

    im using PIC18F24Q10

    please help me
    I'm frustrated on chatgpt :)
    José

     

    Last edit: Jose Houle 2026-02-08
  • Fabrice Engel

    Fabrice Engel - 2026-02-08

    Hello,

    I used internal voltage reference to read the battery voltage of my circuit (Short Circuit Probe).
    If you read the Vdd voltage by using 2 resistors as voltage dividor, would that be work?
    But maybe I miss something from your question.

    Here the function I created (Sorry Anobium, I was using my own ADC routine and not the build in from GCBasic):

    // Procedure to read AN3 analog values - 10 bits resolution for Battery voltage
    // This Function is not portable like that to other microcontroller because of non using GCBASIC internal ADC commands
    
    Function myBatteryReadAD10() As Word                                     // Port RA4 - AN3 is hardcoded inside the procedure, this code is not portable per default   
        FVRCON = 0b10000010                                                  // FVREN is activated and set to 2.048V (page 142)
        ADCON1 = 0b10010011                                                  // ADFM right justified, ADC conversion clock @Fosc/8, Vref- at Gnd, Vref+ at FVR 2.048V (page 151), voltage divider 0,32
        Set ANSELA.4 On                                                      // Define Port RA4 as Analog input (page 123)
        ADCON0 = 0b00001101                                                  // AN3 (RA4) actif, ADC is enabled (page 150)
        Wait 25 us                                                           // Wait 25µs to let charge capacitor (time could be increased!) - (see more page 154)
        // But FVRRDY is always ON on PIC16F1825 according note 1 page 142, anyway keep the instruction in the code for education and experience !
        Wait While FVRCON.FVRRDY OFF                                         // Wait until internal voltage reference is ready (previously cleared in the procedure by set FVRCON), 
        SET GO_NOT_DONE ON                                                   // Start the Analog Digital conversion
        Wait While GO_NOT_DONE ON                                            // We are waiting up conversion is completed, this is a blocking routine waiting on the flag 
        SET ADCON0.ADON OFF                                                  // Deactivate the ADC 
        myBatteryReadAD10 = ADRESL                                           // Copy LSB into low part variable to send back from function ADC value is 10 bits length (page 149)
        myBatteryReadAD10_H = ADRESH                                         // Copy MSB into high part variable to send back from function ADC value is 10 bits length (page 149)
        FVRCON = 0b00000010                                                  // FVREN is deactivated (page 142)   
    End Function
    
     
    • Anobium

      Anobium - 2026-02-08

      :-)

       
      😄
      1
  • Fabrice Engel

    Fabrice Engel - 2026-02-08

    btw, probably you noticed, the PIC used in my circuit is a PIC16F1825

     
  • Jose Houle

    Jose Houle - 2026-02-09

    Hello Fabrice
    Thank you so much for your reply !!

    I can't wait to try it later today !!

    Thanks !!!

     
  • Fabrice Engel

    Fabrice Engel - 2026-02-10

    Hi Jose,

    I cross my fingers that you will find the way to test Vdd. If you are looking for more content round the ADC management and how I used it, you can have a look in the full source code of my project.
    The source code is documented line by line, so I guess you will be able to better understand how I used it myself and how I was able shutoff the circuitry ordered from the microcontroller.

    The full project page is on Elektor here:
    https://www.elektormagazine.com/labs/short-circuit-probe

    Or on PCBWay here:
    https://www.pcbway.com/project/shareproject/Short_Circuit_Probe_f5e16641.html

     
  • Roger Jönsson

    Roger Jönsson - 2026-02-18

    (I guess):
    You can set the PIC18F24Q10 ADC to use VDD as reference, then use the ADC to measure one of the internal voltage reference sources?

     
  • Anobium

    Anobium - 2026-02-19

    Play with this.

    #chip 18f24q10
    #option Explicit
    
    
        DIM ADCValue AS WORD
        DIM ReadVDDmV AS WORD
    
        FVRInitialize ( FVR_off )
        ' --------------------------------------------------------
        ' Enable FVR at 1.024V
        ' FVRCON:
        ' bit7 FVREN = 1 (enable)
        ' bit6 FVRRDY = read-only (wait until 1)
        ' bit1-0 ADFVR = 01 (1.024V)
        ' --------------------------------------------------------
        FVRInitialize ( FVR_1x )
    
        ' Wait for FVR to stabilise
        wait while FVRIsOutputReady = false
    
        ' Read ADC
        ADCValue = READAD10( AN0 )
    
        ' --------------------------------------------------------
        ' Compute VDD in millivolts:
        ' VDDmV = (1023 * 1024) / ADCValue
        ' 1023 * 1024 = 1,047,552 fits in LONG
        ' --------------------------------------------------------
    
        ReadVDDmV = ( 1023 * 1024 ) / ADCValue
    
     

Log in to post a comment.

MongoDB Logo MongoDB