PDA

View Full Version : Pic12F675 serial voltmeter



GioppY
- 28th September 2007, 22:45
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

mister_e
- 28th September 2007, 23:58
interesting project Gioppy.

Don't give up!

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

GioppY
- 29th September 2007, 09:50
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.

T.Jackson
- 29th September 2007, 10:17
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)

chuck
- 29th September 2007, 22:01
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

GioppY
- 4th October 2007, 10:17
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

Art
- 28th October 2007, 04:20
So it serialy outputs the monitored voltage continuously?
Looks great for keeping an eye on a solar installation when you can't
really keep an eye on it.
Art.

GioppY
- 29th October 2007, 23:28
So it serialy outputs the monitored voltage continuously?
Looks great for keeping an eye on a solar installation when you can't
really keep an eye on it.
Art.

Yes; every second.
Regards

GioppY
- 29th October 2007, 23:34
I have modified the vb6 program that receive, display and plot the battery voltage.
If someone want play with it, source code and BattMonitor.exe are attached.
Improvement and bug fix are welcome.
I use it with true serial port (com1-2), i do not know if it works with usb serial adapter.
Regards
Gianni

Art
- 31st October 2007, 21:40
Thanks a heap,
I'll give it a go as my solar installation becomes more developed.

Art
- 13th November 2007, 00:30
Improvement and bug fix are welcome.

Idea for improvement, I see GPIO 1 & 2 are free, so why not set GPIO1 as output
and switch it high if the solar panel voltage suddenly drops to say... zero.
You could call that status bit ALARM! :)
http://www.wind-sun.com/ForumVB/showthread.php?t=1611
Or I'll simply do it myself when I get motivated :D
Cheers Art.

GioppY
- 14th November 2007, 08:37
Yes that is possible.
Please note that the voltage measure implement a digital low pass filter, so the response is smoothed.



http://www.wind-sun.com/ForumVB/showthread.php?t=1611
Cheers Art.
IMHO a simple micro switch can do the job.

Regards
Gianni

Art
- 15th November 2007, 13:30
It would be harder to produce a constant voltage to satisfy your program if panels go missing than just cross two wires,
and it costs zero dollars if you're already using your circuit, and I could forget about loop back wires.

Art
- 15th November 2007, 13:55
There's a book called PIC Microcontroller Project Book by John Iovine that is all about
Pic BASIC projects. The last project in the book is a solar tracker that works with two
cds cells with a plate mounted vertically between them which casts a shadow over one
if a solar tracker isn't pointing the whole assembly directly at the Sun.
Then a picBASIC program makes adjustments to the traker to equalize the readings of
each cds cell so the solar panels on the tracker end up pointing at the Sun.

Anyway, I think you could use two of these circuits with a bigger pic to achieve the same
thing with two identical soalr panels or arrays.

Demus
- 11th April 2008, 22:38
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/thumbnails.php?album=10


/************************************************** *************************\
* *
* *
* *
* *
* 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
}
}

dnadishan
- 2nd March 2009, 06:52
ill build this project but its nt wrk .pls help me
damith

GioppY
- 2nd March 2009, 21:55
What does not work?

dnadishan
- 4th March 2009, 14:03
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

GioppY
- 5th March 2009, 08:24
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

dnadishan
- 7th March 2009, 12:28
thx i chk .......

Branez
- 7th March 2009, 16:13
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. (http://picprojects.org.uk/projects/recal/recal.htm)

Regards, Branko

Branez
- 8th March 2009, 12:31
I have modified the vb6 proogramm. Added only a little cosmetics to know who is the author and form with the plan.:)

Regards, Branko

Simondupin
- 20th November 2010, 14:20
Hello Gianni,

i would like to ask for advice. I am doing school project. And i need to use some simple voltmeter which will measure 230V AC and then send the value by serial link. Could be your voltmeter used like that?

thanks for answer.

Simon