Pic12F675 serial voltmeter


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Nov 2005
    Posts
    36

    Default Pic12F675 serial voltmeter

    For carputer fanatics (but not only) a serial voltmeter to monitor the battery voltage.
    Features
    uC Pic12F675
    voltage range 9-20v
    resolution 100mV
    Com. port 2400baud , N , 8 , 1
    sampling rate ~1Sec.

    Attached SerVolt.zip (Pbp source code, hex file, schematic)

    Regards
    Gianni
    Attached Images Attached Images  
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    interesting project Gioppy.

    Don't give up!

    PS: i feel some may want to see the PC code as well.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Nov 2005
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Hi Steve.
    I have written the code time ago(I am a beginner with Vb6) only to test the device; the program is unfinished (the graphic part in particularly). Anyway if you are interested i'll send you a copy.

    Regards
    Gianni

    P.S.
    If someone is interested on my web page there is a "seven led car battery monitor" with more features.

  4. #4
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    Tips on designing GUI's ...

    1. Stick with neutral colors (unless you know what you're doing)
    2. No more than two fonts
    3. Plenty of whitespace (don't clutter things)
    4. Sensible naming conventions for controls
    5. Drop down menu's instead of buttons (where possible)

  5. #5
    Join Date
    Nov 2005
    Posts
    51


    Did you find this post helpful? Yes | No

    Default

    some cool projects you have there.

    Will your graph program be able to plot 4 inputs at once ?

    Will you share your VB6 code ?

    Thanks

    chuck

  6. #6
    Join Date
    Nov 2005
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by chuck View Post
    some cool projects you have there.

    Will your graph program be able to plot 4 inputs at once ?

    Will you share your VB6 code ?

    Thanks

    chuck
    1) No. You need a different program
    2) Yes

    Sometimes I use stamplot
    http://www.selmaware.com/stampplot/

    Regards
    Gianni

  7. #7
    Demus's Avatar
    Demus Guest


    Did you find this post helpful? Yes | No

    Default

    Hey, just wanted to say thanks to GioppY for this circuit. It helped me a lot. I built my own modeled after this one. I also rewrote the firmware, in C. I couldn't make heads or tails of the BASIC code. Ironic. Anyway, thought I would post my source in case anyone else was looking at this circuit.

    Some pictures of my setup:http://www.mrkowasaki.com/cpgallery/...s.php?album=10

    Code:
    /***************************************************************************\
     *                                                                         *
     *                                                                         *
     *                                                                         *
     *                                                                         *
     * Description: Firmware for the PIC 12F675 micro controller. Monitors a   *
     * 0-5v analog signal across pin GP0 and scales to the original input      *
     * signal.                                                                 *
     *                                                                         *
     *                                                                         *
     *  NO WARRANTY, EXPRESS OR IMPLIED. YOUR MILEAGE MAY VARY.                *
     *                                                                         *
     * Software written by Demus                                               *
     * Circuit designed by GioppY                                              *
     *                                                                         *
     * Compiler: mikroC DEMO version                                           *
     *                                                                         *
     * Notes: mikroC is very bloated. Any use of the math functions increased  *
     * the ROM size over the 1K limit. This tiny little bit of software left   *
     * only 17 bytes of free space. Virtually every part of the source was     *
     * groomed for space concerns, hence the "strange" style of code. I used   *
     * this circuit in conjunction with the Linksys MAX233 hack to monitor     *
     * several solar powered wifi stations remotely.                           *
     * Enjoy.                                                                  *
     *                                                                         *
     *                                                                         *
    \***************************************************************************/
     
    // Miscellaneous debugging functions. Due to space constraints you're better
    // off embedding the function contents wherever you had planned on calling it
    // from. It saves a few call/ret instructions worth of space.
    void write_crlf ()
    {
       Soft_Uart_Write (10);
       Soft_Uart_Write (13);
    }
    
    // Wrapper
    // Again, only useful for debugging.
    void uart_write_str (char *data)
    {
      while (*data)
            Soft_Uart_Write (*data++);
    }
    
    
    // This is where the real magic happens. Using some very basic
    // algebra and my own resistance measurements of the circuit
    // I was able to device a formula to obtain the battery voltage
    // to two decimal places without using any floating point math.
    
    // The PIC converts a 0-5V signal to a digital signal, a number
    // between 0 and 1023. Converting back to an analog voltage
    // representation is fairly easy and given by this formula:
    // (digital value/1024) * 5V = GP0 voltage
    
    // I then measured the voltage drop after the potentiometer,
    // and then right at the battery to determine the correct
    // ratio for MY circuit. It was 0.242 and leads way to this formula:
    // GP0 voltage / BAT voltage = 0.242
    
    // With some simple math, these two formulas can be substituted into
    // each other and we arrive at:
    // (digital value/1024) * 5V = 0.242 BAT voltage
    // Convert the decimal to a fraction, solve for BAT and then multiply
    // both sides by 100. This gives you the two decimal precision without
    // having to deal with floating point numbers. The math libraries are too
    // big to use for this project. And I couldn't find any reasonable
    // way to output the float in anything but raw notation.
    
    void displayVoltage (unsigned long value)
    {
         unsigned long batCentiVolts;
         unsigned long a,b;
    
         // Simplified formula, technically we'll end up with centi-volts.
         batCentiVolts = value * 500000 / 247808;
    
         // The only issue with converting our number to a string this way is
         // that A must not contain less digits than the number we are processing.
         // Since we know exactly what range of numbers we will be dealing with
         // it's ok in the situation.
         a = 10000; // Maximum of 100V
         
         // Skip any leading digits
         while (batCentiVolts < a)
             a /= 10;
    
         // Strip off one digit at a time, and output to the serial console
         // This is pretty much long division.
         while (batCentiVolts)
         {
               // Determine quotient
               b = batCentiVolts / a;
               // Add value to base ASCII code for '0'.
               Soft_Uart_Write ((unsigned char) (b + 0x30));
               // If we've just done the 3rd last digit, it means we
               // need to output the decimal.
               if (a==100)
                  Soft_Uart_Write (0x2E); // '.'
               // Carry over the remainder and repeat
               batCentiVolts %= a;
               // Reduce the divisor
               a /= 10;
         }
         
         // Send a CR LF to keep the output nicely formatted
         Soft_Uart_Write (10);
         Soft_Uart_Write (13);
    }
    
    // It's very important to keep your oscillator calibration
    // Software UART is extremely unreliable otherwise.
    // For reference, the calibration is stored in the two bytes
    // of the ROM.
    void set_osc_cal(void) {
    asm {
       bsf STATUS, RP0
       call 0x3ff
       movwf OSCCAL
       bcf STATUS, RP0
       }
    }
    
    void init_ports ()
    {
    
      CMCON  = 7;              // Turn off the comparators
      VRCON = 0;               // Turn off CVref circuit
      WPU = 0;                 // Disable pull up
      IOCB = 0;
    
      TRISIO = (1<<0) | (1<<3);              // Configure pins 0 and 3 as input
    
      ADCON0 = (1<<0) | (1<<7) ;             // Enable ADC and select right justified results
      ANSEL  = (1<<6) | (1<<4) | (1<<0);              //  Select analog processing for pin 0
    
      set_osc_cal ();
      Soft_Uart_Init(GPIO, 2, 5, 9600, 0);      // Setup UART (9600,N,1)
    }
    
    
    void main() {
    
      init_ports ();
    
      while (1) {
          // Infinite loop - Poll every two seconds
          displayVoltage (Adc_Read(0)); // Convert the analog signal to digital and send our results
          GPIO |= (1<<4);        // Turn the LED on
          Delay_ms(1000);        // Delay 1 second
          GPIO &= ~(1<<4);       // Turn the LED off
          Delay_ms(1000);        // Delay 1 second
      }
    }

  8. #8
    Join Date
    Feb 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default hi

    ill build this project but its nt wrk .pls help me
    damith

  9. #9
    Join Date
    Nov 2005
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    What does not work?

  10. #10
    Join Date
    Feb 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Unhappy Pic12F675 serial voltmeter

    thx 4 reply,
    i burn pic ,ur code have some errors ."internal oscillator ....."pls help me how to burn this pic ill use icprog software
    damith

  11. #11
    Join Date
    Nov 2005
    Posts
    36


    Did you find this post helpful? Yes | No

    Default

    Some programmer have problem with 12f675. Do a Google on "12F675, programming problems, internal oscillator".
    Keep in mind that the calibration oscillator value should be stored on address 0x3FF as a retlw instruction.
    If you've erased or written to the chip already, perhaps you've already destroyed the calibration value. Do e Google search.
    Regards

  12. #12
    Join Date
    Feb 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Smile thx

    thx i chk .......

  13. #13
    Join Date
    Nov 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by GioppY View Post
    Some programmer have problem with 12f675. Do a Google on "12F675, programming problems, internal oscillator".
    Keep in mind that the calibration oscillator value should be stored on address 0x3FF as a retlw instruction.
    If you've erased or written to the chip already, perhaps you've already destroyed the calibration value. Do e Google search.
    Regards
    This web site was very big help for me.

    Regards, Branko

Similar Threads

  1. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 17:03
  2. PIC12F675 problem with port 5
    By NL2TTL in forum mel PIC BASIC
    Replies: 2
    Last Post: - 5th June 2009, 01:23
  3. Pic12f675 Serial woes
    By simongie in forum Serial
    Replies: 1
    Last Post: - 30th April 2009, 21:41
  4. SERIN with a PIC12F675
    By ewandeur in forum Serial
    Replies: 4
    Last Post: - 30th July 2007, 15:04
  5. PIC12F675 trouble
    By russman613 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 27th February 2006, 18:40

Members who have read this thread : 3

You do not have permission to view the list of names.

Posting Permissions

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