Page 2 of 5 FirstFirst 12345 LastLast
Results 11 to 20 of 42

Thread: PIC checking voltage?

  1. #11
    What can I say? I like serial. Curiosity's Avatar
    Join Date
    Mar 2004
    Location
    Florence Yall, BFKY
    Posts
    2,684
    Ok, this is looking real easy now. Microchip C would look something like this (I hope):

    TRISA = 0xFF; // Set all port A to input (or just the ones you want)
    ADCON0 = 1; // Turn A/D on
    ...
    ADCON0 = (7 << 3) | 1; // Set ADC to AN7 (bits 5,4,3) + leave ADC on
    ADCON0 |= 2; // GO (or ADCON0bits.GO = 1)
    while(ADCON0bits.NOT_DONE); // wait on bit 1 for completion

    // Some result buffer...
    result[0] = ADRESL;
    result[1] = ADRESH;
    ...

    I didn't add the Fosc/x bits. You'll just have to play with the timing stuff.

  2. #12
    Variable Bitrate
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    311
    Similar code written for PICC compiler, slightly more readable IMHO.

    // Creating the long integer
    long int ADC_Num;
    // Setting up Port A to do ADC on Pin 2
    // (Note: Pin 2 is A0)
    setup_port_a(ALL_ANALOG);
    setup_adc(ADC_CLOCK_INTERNAL);
    set_adc_channel(0);
    // Allowing a delay to make sure the ADC
    // works properly
    delay_us(20);
    // Getting the value from the ADC port
    ADC_Num = read_adc();

    It uses functions which are defined for the CCS inc compiler though, so you'd need their headers to compile it.

  3. #13
    Low Bitrate Stonewall78's Avatar
    Join Date
    Dec 2003
    Location
    Calgary, AB
    Posts
    99
    I am hoping you don't want to measure over 5V's do you?

  4. #14
    Variable Bitrate
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    311
    The ADC measures up to the supply voltage only. You take the Vcc voltage and divide by the resolution and this gives volts/bit. To measure over 5V (or 3.3 or whatever you're running at - PICs can take a good range) you will need to step it down somehow. I'd recommend just a voltage divider. Not entirely accurate but really you're just looking to create a threshold to trip the pic, so if you use a POT as one half of your divider, you can adjust.

  5. #15
    What can I say? I like serial. Curiosity's Avatar
    Join Date
    Mar 2004
    Location
    Florence Yall, BFKY
    Posts
    2,684
    If you want to display it, I would think drop it down so it gets most of the range around 7 to 15 and you could display 1 or 2 decimal places too, maybe.

  6. #16
    Constant Bitrate BADDERICK's Avatar
    Join Date
    Jun 2005
    Location
    Las Vegas
    Posts
    143
    Check this out. Volt meter


    I've bought a few things from this guy. He has fast shipping but he can't add when you combine shipping....just a warning...LoL. But check his store. he has amp meters, peltiers, dc to dc regulaters. Lots a cool ****......Um I mean stuff:-"
    2003 100th harley F-150
    PCChips C3 VIA/eden, M1 ATX smart car.
    Here is my project so far: My 100TH Harley-Puter
    Ride safe


    Buy my stuff: Stuff

  7. #17
    Maximum Bitrate KyleYankan's Avatar
    Join Date
    Mar 2005
    Posts
    491
    I'm sorry, but I need one more thing. lol.

    How in the world do you make a coltage divider? I want to drop the 7v-15v to below 5v.

    So divide the voltage by three? how?

  8. #18
    What can I say? I like serial. Curiosity's Avatar
    Join Date
    Mar 2004
    Location
    Florence Yall, BFKY
    Posts
    2,684
    Google is your friend! What's the draw of the PIC? Like 1uA or something? It looks like it's really sensitive.

  9. #19
    Variable Bitrate
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    311
    Vin o---/\/\/\/\/---o---/\/\/\/\/---o Gnd
    Call the first resistor R1, and the second R2.

    Two resistors in series going from the voltage you're checking to gnd. Make them large (hundreds of K ohms), and make the node between them go to your PIC. Choose the values such that R2/(R1+R2) is about 3. So, say R2=1megohm, R1=2megohm. If you think about it you've just created a direct path from your battery positive to negative, so make sure those resistances are high.

  10. #20
    Registered User
    Join Date
    May 2003
    Posts
    1,736
    Keep the source resistance within spec else the reading is going to be inaccurate. It should be 10K max for the PICs.

    There you go, it look like you got alot of members here whos willing to help you out with the PIC specific problems...strange though they never existed a few months before

Page 2 of 5 FirstFirst 12345 LastLast

Similar Threads

  1. Need help understanding efficiency and voltage regulation
    By sansoo24 in forum Power Supplies
    Replies: 3
    Last Post: 04-22-2005, 03:45 AM
  2. Replies: 7
    Last Post: 01-14-2005, 11:56 AM
  3. What Gauge wires do I use?
    By Showmehow in forum Newbie
    Replies: 25
    Last Post: 07-25-2004, 11:41 AM
  4. ITPS and Voltage drop issues
    By Wiredwrx in forum Power Supplies
    Replies: 7
    Last Post: 04-20-2004, 07:09 AM
  5. DC-DC psu and high capacity HDD
    By GrahamS in forum General Hardware Discussion
    Replies: 46
    Last Post: 12-19-1999, 06:44 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •