Announcement

Collapse
No announcement yet.

PIC checking voltage?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PIC checking voltage?

    Hey everyone. I have a quick question. I want to design a PIC interface with my computer. One of the things I want is to check the voltage of my battery and send red flags up if it goes too low. Now, I know of ADC (Analog-digital converters), but not how to use them. I can't find a website either. Can anyone give me a quick tutorial, schematic and code, or anything? Thanks in advance.

  • #2
    Originally posted by KyleYankan
    Hey everyone. I have a quick question. I want to design a PIC interface with my computer. One of the things I want is to check the voltage of my battery and send red flags up if it goes too low. Now, I know of ADC (Analog-digital converters), but not how to use them. I can't find a website either. Can anyone give me a quick tutorial, schematic and code, or anything? Thanks in advance.
    http://www.rentron.com/serial.htm

    You will find what your looking for

    Mastero

    Comment


    • #3
      PIC Basic? *gag*
      MII-12000 / Ampie / Lilliput 7" / BU-355 / PicoPSU / uSDC
      Currently: Enjoying the setup, but always contemplating my next move...

      Comment


      • #4
        PICBasic? Never heard of it. I'm on my way to fireworks, il read tha ttonight though. thanks.

        Comment


        • #5
          http://www.winpicprog.co.uk/pic_tutorial11.htm

          Comment


          • #6
            You should probably put a zener on the input pin just to keep it within the 5V range so it doesn't damage anything and increase those resistors for the higher volts.

            Comment


            • #7
              Well I just read that the PIC16F877A has 8 A2D inputs, so I ordered them and a few 4.0 mhz crystals. It's too bad I can't find any C code, because that's what I was hoping to program the rest in.

              Comment


              • #8
                That's why I decided on the 18F2455. With the guys here using it and all the source and C compilers, it was easy. I've already got driverless USB I/O going.
                You can search forum.microchip.com for anything related. Something good might show up.

                Comment


                • #9
                  Kyle: I think I have some C code for the 874 (same ports as 877 I believe) which was supposed to be a 0-1.5V battery tester using one pin of the ADC. If you think it would be any use I'll dig it up and any docs that went with it.
                  MII-12000 / Ampie / Lilliput 7" / BU-355 / PicoPSU / uSDC
                  Currently: Enjoying the setup, but always contemplating my next move...

                  Comment


                  • #10
                    rsd: if it's not too much trouble. IT makes me want t ogo back and get an assembly book. there's like NO c code for pics on the internet. at least any that I see.

                    Comment


                    • #11
                      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.

                      Comment


                      • #12
                        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.
                        MII-12000 / Ampie / Lilliput 7" / BU-355 / PicoPSU / uSDC
                        Currently: Enjoying the setup, but always contemplating my next move...

                        Comment


                        • #13
                          I am hoping you don't want to measure over 5V's do you?

                          Comment


                          • #14
                            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.
                            MII-12000 / Ampie / Lilliput 7" / BU-355 / PicoPSU / uSDC
                            Currently: Enjoying the setup, but always contemplating my next move...

                            Comment


                            • #15
                              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.

                              Comment

                              Working...
                              X