pic led bargraph battery status indicator

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
mouton63
Posts: 17
Joined: Wed Jan 23, 2013 5:38 pm

pic led bargraph battery status indicator

Post by mouton63 »

Hi all
Im trying to use a pic with an analogue input (AN0/1..) to monitor the charge voltage of x2 12v 7Ah batteries in series.
i will be monitoring the battery voltages from 17v (battery low) to 26v (battery full)
i want to use the pic to give me the same linear "bar" type of output as a LM3914 chip.
the output setup for the LED's isn't a problem (i think.... :? ), my hassle comes in with the analogue port input & calculations.
I want to use 10 LED's indicating "low voltage" with x2 red LED's, "Caution" with x3 yellow LED's and "full/ok" with x5 green LED's.
im using the analogue knob in flowcode 5 professional with a 0 to 255 setting (i hope thats right) to simulate my voltage range.
My Problem #1;
How do i work out the value in the 0-255 for that 10v variance?
im trying to keep it simple by linking each LED to a one (1) volt increase/decrease.
My Problem #2;
how do i measure that 17-26v on the analogue pin of the processor without damaging the port/processor?
any help will be greatly appreciated guys.
Regards;
Andrew

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: pic led bargraph battery status indicator

Post by medelec35 »

Hi Andrew,
What I would do is use a potential divider using 2 resistors. I suggested a similar thing here:
http://www.matrixmultimedia.com/mmforum ... 98&#p34035

With 4K7 and 1K then max i/p voltage is 28V
If you would like to post a flowchart after doing as much has you can, then I will see if I can modify it for you so LED's will light on every 1V
From 16 to 26V. (10 LEDS) Or 17 to 27V

Martin
Martin

mouton63
Posts: 17
Joined: Wed Jan 23, 2013 5:38 pm

Re: pic led bargraph battery status indicator

Post by mouton63 »

hi Martin,
thanx for the feedback :)
please find attached my FCF file.
i've seen that if i move the knob from 0 to 50 fast (ie. click at the midway point when at 0) then it skips all the outputs in between, thats not what i want & its another problem im battling with.
i would like the LED's to remain in BAR mode even if i skip to say... 50 or 70 etc on the knob otherwise it might skip most of the LED's when i power up the unit & the voltage is sitting at maybe 23V?
I reckon it might do the same if i have a sudden large voltage drop, not really BAR mode & not what i want or had in mind... :(
Is it possible to make the red LED's flash when they are the only ones on? (battery charge low condition indication)
Regards;
Andrew
Attachments
Flowcode1.fcf
(19.44 KiB) Downloaded 300 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: pic led bargraph battery status indicator

Post by medelec35 »

Hi Andrew,
Just for your reference:
If using a not Float variable you won't be able to use a decimal point for a variable.
E.g if byte type variable you cant use 23.4
Bytes, integers Etc. must be whole numbers only with no decimal points
So for our flowchart I have use a Float, and a multiplier so you can enter voltage directly. e.g 19.0

I have taken into account you using a 4K7 resistor from +ve battery to microcontroller ADC i/p, and 1K resistor from microcontroller ADC i/p to ground.

Code: Select all

Upper R   Lower R
4700	   1000
	
Vbat V(ADC)
17	2.98
18	3.16
19	3.33
20	3.51
21	3.68
22	3.86
23	4.04
24	4.21
25	4.39
26	4.56
27	4.74

For protection of microcontroller ADC i/p (allow max 5V i/p to ADC) you could connect a 5.0V zener diode (cathode) also to ADC i/p and anode to ground.

Flashing of red LED in Simulation will be much slower then on real hardware.

Not had a great deal of time tonight so there maybe room for improvement.

Can you please let me know how it goes.

Thanks

Martin
Attachments
LED Bar1.fcf
(24.17 KiB) Downloaded 353 times
Martin

mouton63
Posts: 17
Joined: Wed Jan 23, 2013 5:38 pm

Re: pic led bargraph battery status indicator

Post by mouton63 »

Hi Martin
Thank you for the help, i understand now.
i didnt know that you couldnt use the decimal, thanx for the correction there :)
the program works perfectly! thank you so much! :D i now have an idea of where i went wrong.
:mrgreen: now to build & test.
i would so much love to learn about servo motor control, PWM, communication on the PIC's like RS232, can the PIC's use RS485? or interface on the PLC PROFIBUS communication?
Can you maybe help with this, or direct me to a site that has small little (above mentioned) programs for dummies like me maybe with tutorials where i can run them & play around with them to better understand the functionality of the program & maybe use as a guide line for any future experimenting?
Once again thank you so much for the help thus far, its much appreciated.
Kind Regards;
Andrew

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times

Re: pic led bargraph battery status indicator

Post by kersing »

Andrew,

Have you looked at the examples for Flowcode 5? Examples, Introductory Course and Flowcode Training Videos are all available at the main Flowcode page (just above the Products section).

Regards,

Jac
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: pic led bargraph battery status indicator

Post by medelec35 »

Hi Andrew,
Thanks and your welcome.

Re: sevo motors
Although I highly recommend using built in Flowcode component for controlling a servo motor (for that should be Jac's suggestion), I created an artical + flowchart which will control a servo using timer0.
See:
http://www.matrixmultimedia.com/article.php?a=435

That should give you an idea on how they are controlled.

There is a bug with 16F73 when using timer 0.
I'm going to look into that and post a solution if I can

Martin
Martin

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: pic led bargraph battery status indicator

Post by medelec35 »

I have fix the timer0 bug.
I believe it's an issue with boostC compiler and not Flowcode?

A I have posted a fix here:
http://www.matrixmultimedia.com/mmforum ... 47&t=11940

Martin
Martin

mouton63
Posts: 17
Joined: Wed Jan 23, 2013 5:38 pm

Re: pic led bargraph battery status indicator

Post by mouton63 »

Hi Martin, Jac,
thank you for the feedback, i will definitely go and have a look at what you suggested & practice it. :D
Martin i see you only mention windows 32 bit for the 16F73 (my fav chip to use :shock: ) timer problem, would i have the same problem if im using windows 7 64 bit?

Guys the reason im asking all these things are coz i thought i might be able to do the following if i knew how PWM etc. works...
i want to use a pic with x2 potentiometers;
potentiometer #1 must allow me to adjust a frequency of 10 Khz to 30 Khz... (50% duty cycle) linear
potentiometer #2 must allow me to adjust the amplitude of above mentioned frequency from 0V linear to 5V
im trying to build a small induction heater at home & it would be nice if i could use a pic processor to control the LC resonant
frequency as well as the output power (gate drive amplitude) to the MOSFET's
i have never done frequency generating or amplitude adjustments on a PIC processor, so i have absolutely no idea where or how to even start :(
any suggestions/help?
Kind Regards
andrew

Post Reply