PDA

View Full Version : PIC based Low Voltage Alarm


FDC
Feb 02, 2005, 02:58 AM
Any experienced guys willing to program the pic based LV alarm using a 12F671 or 12F675 as proposed in the link below?

http://homepages.paradise.net.nz/bhabbott/lvw.html

Maybe an add on or modification to the circuit is to add a 16kB eeprom so it could also measure voltage that can be downloaded to the pc just like the HR-Lipoly low voltage alarm.

Chippie
Feb 03, 2005, 02:00 PM
Any experienced guys willing to program the pic based LV alarm using a 12F671 or 12F675 as proposed in the link below?

http://homepages.paradise.net.nz/bhabbott/lvw.html

Maybe an add on or modification to the circuit is to add a 16kB eeprom so it could also measure voltage that can be downloaded to the pc just like the HR-Lipoly low voltage alarm.


Dosn't look to me as if there are any spare pins on the pic to accomodate SDa and Scl for the eeprom.....24C16 I'm thinking......

FDC
Feb 03, 2005, 11:18 PM
Dosn't look to me as if there are any spare pins on the pic to accomodate SDa and Scl for the eeprom.....24C16 I'm thinking......

Well it's just an idea that I have and of course you'll have to modify the circuit as well. You can easily get two more pins by using only one LED, take out the switch and make the LVC auto-config from software or use only one pin for the buzzer. But the next question is do we need additional pins for the communication to the pc? I totally have no idea as I don't have any skills on knowledge on this.

Well this is just wishfull thinking on my part as I have yet to learn how to code s/w for the pic. I've just got a pickit with 12f675 to play around and learn with :).

PICmik
Feb 04, 2005, 07:46 PM
That depends on what kind of interface you want to the PC. A simple transmit only serial (RS232) link could be made using e.g. one of the LED pins, and putting the PIC into "upload" mode by e.g. holding a switch down whilst powering up. You would probably need to do some level shifting (some PC UARTS are happy with 0-5v, but the official specs are +-5 to +-15 volts).

Alternatively you could make a simple I2C interface for the PC on the parallel port to read the 24C16 Serial EEPROM directly.

If you are contemplating this as your first project, I'd suggest you take a step back and familliarise yourself with the PICs architechure and the development tools by programming e.g. a simple LED flasher. This way you get to prove the hardware is working ok as well.

I'd reccomend joining the PICLIST, which is a mail list for PIC users. However, it is a very high volume list. Check out http://www.piclist.com for subscription instructions and a load of usefull code snippets.

FDC
Feb 05, 2005, 12:42 PM
Thanks for the link. Just the sort of resources I'm looking for.

Yes youre right. I'm contemplating this to be my first pic project. I just got a pickit a about week back and am finished studying flashing the LEDS using the 12F675 :). Now it's time for to learn how to vary the flash rate using the ADC.

Thanks again!
FDC

FDC
Feb 13, 2005, 01:13 AM
Just broadening my search for information.

I'm through with learning the ADC on the 12F675 (thanks to mikroBasic which made it very simple) and it would be plain simple just using the pic with an LED and a buzzer. So to make it more interesting I want to add a voltage monitoring and periodically store it on a serial eeprom, similar to the functionality of the HRLipoly-X Lipo Low Volatage Alarm. Unfortunatety, mikroBasic only includes an I2C libary for PICs with MSSP.

Anyone has an asm I2C code to share for using 8-pin Pics? If not, then maybe can someone lead me in the right directions by providing some generic asm codes that I could start with.

I was thinking that the SCL can be generated on one pin using either timer0 or timer1 of the 12F675 and using interrupts. Then another pin for SDA. This is where I need the code to start off with.

Generally, my idea is for the following:

1 pin - ADC for monitoring voltage
1 pin - for 2 LED indicator lights
1 pin - for a buzzer
2 pins - for SCL and SDA
1 pin - reserved for ADC possibly for current monitoring (if possible)

Manual configuration could probably done (Low volatge alarm threshold and other configs) by using a push button on the divider circuit on the voltage adc.

Any comments if this is possible before I dig deeper into this thing. Would it be possible to program this into 1K of instructions for the 12F675? If not maybe a 12F683 would be better?

TIA,
FDC

westfw
Feb 13, 2005, 04:44 AM
Dosn't look to me as if there are any spare pins on the pic to accomodate SDa and Scl for the eeprom.....24C16 I'm thinking......

What for? The 12F675 has 128 bytes of internal eeprom.

You can use your one input-only pin for both programming and an "option";
add a pulldown resistor. Now, if you power it up and the input is low, you
assume it's behaving as "option" - flip a switch and get a different behavior.
If you power it up and the input is high, you assume you're connected to a
computer and await downloaded data...

I've built a couple of 12f675 projects, but nothing using the A/D converter.
I don't think there would be any problem fitting everything you've talked
about into the 1k of code space; PIC code is quite compact.

I second the recomendation for the piclist (www.piclist.com) - very high
signal to noise ratio, for rather broad ranges of "signal" (ie there is off
topic discussion, but it's still of high technical content.)

BillW

Chippie
Feb 13, 2005, 04:57 AM
Maybe an add on or modification to the circuit is to add a 16kB eeprom so it could also measure voltage that can be downloaded to the pc just like the HR-Lipoly low voltage alarm.

westfw,

perhaps if you re read the original post instead of being so quick to comment...

FDC,

try this link, http://www.epemag.wimborne.co.uk/tree/downloadtree.html
You may have to sieve thru a lot of the stuff but I'm sure I saw an article on using i2c..

westfw
Feb 13, 2005, 05:41 AM
westfw,
perhaps if you re read the original post instead of being so quick to comment...


oops. Sorry about that. Not familiar with the other LVD mentioned, so I just sorta glossed over it. Still, 128 bytes of internal eeprom is quite a few samples worth, depending on how often you're wanting to sample. What does that
other detector do? I couldn't find any references to it....

BillW

Chippie
Feb 13, 2005, 07:16 AM
oops. Sorry about that. Not familiar with the other LVD mentioned, What does that
other detector do? I couldn't find any references to it....

BillW

Bill,

from Bruce's site....

'In my proposed circuit, a Microchip PIC12C671 would be powered by a 3.3V regulator, which also acts as a voltage reference. The PIC is set to use its internal RC oscillator, making 6 pins available for I/O. The raw battery voltage is proportionally reduced to a level that the PIC can handle, and input through pin 7 (AN0). '

so, the 3.3v reg acts as a reference voltage and the raw battery volts are read at pin7 via a potential divider formed by R1/R2

I guess 128 bytes may be enough, depends on how many samples you want to record...even so a 24C16 eeprom is a lot of ram... :D

FDC
Feb 13, 2005, 09:28 AM
I intend to use this device on a micro EP heli and monitor the voltage discharge curve as well as a low voltage warning device.

Lets say that if I only use 8-bits for ADC (12F675) at 3.3V ref., that would only be 128 samples and let say we space the samples 10 seconds apart, it would give me about 21 minutes of voltage discharge data at around 13 mV resolution. I guess this would be enough as for a micro ep heli, the flight times are typically around 10-20 minutes per charge. If we use 10-bit AD resolution, it would be cut by half and barely sufficient to monitor the voltage discharge data.

But I feel 10 second samples will not be very accurate to see the voltage discharge curve, at minimum 1 second sampling rate for a 20 minutes window use up to 1200 bytes. If I'll use 10-bit resolution, it would be up to 2400 bytes.

I also intend to possibly monitor the current dischrage data also so more than 2kB memory is needed. It just so happened that I can only find a atmel 24C16A in my locality thats why I suggested a 16kB memory.

Thanks for bringing up the issue on the memory. I think I'll work on this idea using existing eeprom memory first as it is more achievable at my current knowledge in pics and programming.

Again, many thanks!
FDC

stevesey
Feb 13, 2005, 11:35 AM
Some PICs allow you to read/write to flash as well as EEPROM, thus you could use all your unused code spare. I think the 16f684 allows this.

westfw
Feb 13, 2005, 05:51 PM
I intend to use this device on a micro EP heli and monitor the voltage discharge curve as well as a low voltage warning device.
:
But I feel 10 second samples will not be very accurate to see the voltage discharge curve, at minimum 1 second sampling rate for a 20 minutes window use up to 1200 bytes. If I'll use 10-bit resolution, it would be up to 2400 bytes.

I also intend to possibly monitor the current dischrage data also so more than 2kB memory is needed. It just so happened that I can only find a atmel 24C16A in my locality thats why I suggested a 16kB memory.


That would certainly require more memory. :-)
SPI memory might be easier to deal with than I2C memory (but perhaps harder to find.

A "flight recorder" sort of peripheral that records this sort of data, perhaps even along with inputs for the servo outputs
of the receiver (and sensors? Accelerometer?) is an interesting idea for a more advanced project, and could do the
battery warning as a side effort. EEPROMs and "dataflash" memory get pretty big (capacity wise) without getting
much bigger physically. But this would need pretty complicated "playback" software as well... Best saved for later :-)

I think just using the 128bytes of internal memory is an excellent idea for a starter project. Amoung other things, it
will tell you pretty quickly how fast you need to sample; if you do 10 second intervals and don't see changes every sample,
it won't make a lot of sense to sample more often.
I don't think you need 10bits of resolution. Your "interesting range" is only the 1.2V or so between 3 and 4.2V, right?
So a bit of care in the external analog circuitry might increase the resolution with the same bits of A-D...

westfw
Feb 13, 2005, 05:57 PM
from Bruce's site....
'In my proposed circuit, a Microchip PIC12C671 ...:D

No, no. I read Bruce's site. I meant this:
...just like the HR-Lipoly low voltage alarm.

I don't know what the "HR-Lipoly" gadget does.

I wouldn't have thought that detailed discharge curves during actual flight would be very useful, but my
background is ALL micros and software, and I'm just starting to try to learn something about RC flight...

BillW

Chippie
Feb 13, 2005, 06:00 PM
That would certainly require more memory. :-)
SPI memory might be easier to deal with than I2C memory (but perhaps harder to find.)


If you want to go the spi route, as Bill suggests(wish I'd thought of that too... :p ) Microship do the 25 series eeprom...Do a search on SPI eeprom there a few..

good call Bill ;)

labmaster
Feb 13, 2005, 07:27 PM
Howdy,

this is my first post on rcgroups, but i'am still reading for couple of month.

here is my statement regarding a voltage monitor:

1. i2c is just as simple as SPI, as long as your pic is the only master at the i2c bus.
You need 4 routines to comunicate with a i2c eeprom like a 24c16 or whatever then.
a. routine for setting a startcondition on sda and scl (about 6 pic instructions)
b. routine for setting a stopcondition on sda and scl (about 6 pic instructions)
c. routine for sending data (about 20 pic instruction)
d. routine for receiving data (about 20 pic instruction)

If someone is interested, i can post sample source from older projects using i2c eeproms.

I've made such a voltage alarm device a while back and even tested it on my Logo 20 ep helicopter.
On that device i used two high power extreme bright leds one red and one green. The green LED tells me the actual voltage by different flash patterns and the red one tells me the lowest voltage apeard since hook up of the battery. I've set the dimension (resistor divider and other things to use it on up to 10 Lipo cells (about 45 Volt max)
I've gone the same aproche as shown on (http://homepages.paradise.net.nz/bhabbott/lvw.html) and used a 3.3 LDO for supplying the pic and LED's.
During my tests on the logo with 8 serial lipos about (33Volt) i run into big problems. on voltage above 20 Volt the 3.3 V LDO is a big problem, as the microcontrolle and the LED's draw about 20 to 30 mA in the middle, so there is a lost of 0.5 Watt transformed into heat. This get worth if the voltage is at 33 Volt (like on my logo20) and both high power led's are flashing or lightning (70 mAh x 33V = 2,3 Watt). The rsult is i've messed up a couple of LDO and got.

My question: if there is a simple and cheap way to generate the voltage for the LED's not using a linear LDO instead more a swichting supply made out of simple components but regulated enought to drive high power leds' with a current up to 40 mA each ?


PS: i hope someone will understand my bad english, sorry, it's not my native language

FDC
Feb 13, 2005, 10:41 PM
Howdy,
I've someone is interested, i can post sample source from older projects using i2c eeproms.

Thank you very much. Could you please share and post your i2C routine asm codes. Although I'm using basic language right now, I eventually want to write my own asm code to optimize the code and sample codes would help a lot.

I actually cheated myself by using mikroBasic compiler specially with the byte and word comparison for the ADC results to determine number of cells and low voltage cut-offs.

After further poking into mikroBasic, I found out it also actually implements software I2C routines. :)


As a side note to your problem, I assume that you are already using a U/SBEC so why not power up your LowVoltage Warning device via one of the Rx's servo channel if your SBEC have enough capacity to spare :confused: I just don't know what the consequences would be running two wire to the Rx and two wires to the LipoCells.

Also check out this link: http://www.datel.com/newdpm.htm. A switching type VR with inputs up to 40V the size of a TO-220.

Thanks for the inputs!
FDC

westfw
Feb 14, 2005, 03:04 AM
Heh. You know those "Secure Digital" and "MMC" flash cards used in some digital cameras?
You can talk to THEM with SPI. Want a gigabyte of saved data? No problem. Perhaps
more relevantly, the low end (now "obsolete") show up a deep discount prices at more
accessible vendors than the average high-density chip. A while ago I picked up a couple of 16Mbyte (14MB?) cards for about $3 each (and free shipping.)

I dunno if they're QUITE light enough to fly, but they're not very heavy, and there is also the new "mini" version...

This also solves the problem of getting the data into a PC for later analysis. Sort of
(you have to figure out how to get the PIC to write PC-readable files. But that's been
done and published...)

BillW

westfw
Feb 14, 2005, 03:23 AM
My question: if there is a simple and cheap way to generate the voltage for the LED's not using a linear LDO instead more a swichting supply made out of simple components but regulated enought to drive high power leds' with a current up to 40 mA each ?

(your english is wonderful. I wouldn't have guessed you for a non-native-speaker if you hand't said anything.)

Using an N-channel mosfet or NPN transistor and a couple resistors, you can
drive the LEDs directly from the unregulated supply, and greatly reduce the current that the regulator has to deal with...

westfw
Feb 14, 2005, 03:30 AM
(Ack. Wow. 30+V! I see I made another bad assumption that this sort of monitor was aimed mainly at 1S/2S/3S lipoly usage. No wonder you might need more than 8 bits for the A-D sample!) (although, at 30V worth of battery weight, maybe you can spare a separate battery for the LVD mechanism.)

labmaster
Feb 14, 2005, 02:51 PM
(your english is wonderful. I wouldn't have guessed you for a non-native-speaker if you hand't said anything.)

Using an N-channel mosfet or NPN transistor and a couple resistors, you can
drive the LEDs directly from the unregulated supply, and greatly reduce the current that the regulator has to deal with...


nope, thats not a solution, as my device it programmable by a Jumper to work with 2 up to 10 lipo cells. so i need a solution for adapting the voltage for the led without converting them to heat. a simpler buck/boost converter should work, but have no clue yet how to design it correctly and with less componets as possible.


As a side note to your problem, I assume that you are already using a U/SBEC so why not power up your LowVoltage Warning device via one of the Rx's servo channel if your SBEC have enough capacity to spare I just don't know what the consequences would be running two wire to the Rx and two wires to the LipoCells.

1. no, i don't use a bec, i use 2 sepearte lipoly cells for receiver, servos and gyro, together with a sepeate mosfet regulator circuit (bought from www.helitron.de)
2. no way to make a physical connetion between the power an dthe receiver system, otherwise i will render the optocopler stuff and a couple of other security things useless.


BTW: today i had no chance to care about the i2c sources in tha company, will do that tomorrow, sorry.

westfw
Feb 14, 2005, 05:50 PM
There's a simple switching regulator described here:
http://www.romanblack.com/smps.htm
that you can probably customize for high input voltages simply by being careful
about transistor and schotky selection, but I'm not sure how it will behave over the
wide input range you're talking about.

Since you hardly need "low dropout" regulators if you have 30V of power, you could incorporate several intermediate "standard" regulators to gradually cut the voltage down. You'd still be "wasting" the same amount of power, but it would be distributed
across (for example) 24V, 12V, 8V, and the 3.3V regulators...

BillW

labmaster
Feb 15, 2005, 07:22 AM
Howdy,

i've uploaded now some i2c sample code to one of our servers.

www.fmpoing.de/i2ctest.asm (http://www.fmpoing.de/i2ctest.asm)


Regards,
Walter

Mr.RC-CAM
Feb 15, 2005, 11:21 AM
...if there is a simple and cheap way to generate the voltage for the LED's not using a linear LDO instead more a swichting supply made out of simple components...If your microcontroller has a hardware PWM output, you could use it to create the lower effective LED voltages you need. Keep the PWM freq as high as possible and change the pulse width to suit the applied battery voltage. The concept requires that your PWM waveform provides the average LED current that you need.

Besides that, there are dozens of buck regulator IC's out there that require minimal parts to work. For example:
http://www.micrel.com/product-info/products/lm2574.shtml
http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3990/ln/

You could create something with descrete components, perhaps at lower cost, but it would require more parts. In any event, be careful with magnetic switcher supplies -- they can emit EMI/RFI if the design is not carefully considered.

RC-CAM

labmaster
Feb 15, 2005, 04:04 PM
If your microcontroller has a hardware PWM output, you could use it to create the lower effective LED voltages you need. Keep the PWM freq as high as possible and change the pulse width to suit the applied battery voltage. The concept requires that your PWM waveform provides the average LED current that you need.

Besides that, there are dozens of buck regulator IC's out there that require minimal parts to work. For example:
http://www.micrel.com/product-info/products/lm2574.shtml
http://www.maxim-ic.com/quick_view2.cfm/qv_pk/3990/ln/

You could create something with descrete components, perhaps at lower cost, but it would require more parts. In any event, be careful with magnetic switcher supplies -- they can emit EMI/RFI if the design is not carefully considered.

RC-CAM


Hello Mr. RC-CAM,

i've already thought times ago about pic PWM doing the swiching for the
LED regulation, but i think this will be a little bit risky, as what happens if the pic can not respond fast enought to fast changes in the powersupply. (don't know what should cause such a quick change, but who knows)

I've even already checked some buck regulators from national and from micrel. Micrel only goes up to 40V input and National has only very big chip packages (SSOP 14) byside wafer or diy options.

Maxim was the next i wanted to check.


regards,
Walter

Mr.RC-CAM
Feb 15, 2005, 04:14 PM
...as what happens if the pic can not respond fast enough to fast changes in the powersupply.That should not be a significant concern in this battery powered application. If necessary, you could include a fast over-current circuit to save the LEDs from errant code or unexpected operation. Once comfortable with it, you could eliminate this protection hardware to reduce size/weight/cost.

RC-CAM

labmaster
Feb 16, 2005, 12:50 PM
That should not be a significant concern in this battery powered application. If necessary, you could include a fast over-current circuit to save the LEDs from errant code or unexpected operation. Once comfortable with it, you could eliminate this protection hardware to reduce size/weight/cost.

RC-CAM

What would be your suggestion to use as over current protection.
Varistor with fuse oder a polyswitch or something special ?

Mr.RC-CAM
Feb 16, 2005, 01:16 PM
What would be your suggestion to use as over current protection.
Varistor with fuse oder a polyswitch or something special ?Those are probably too slow to save an LED. I would suggest creating a transistor based current limit circuit instead. I would suspect that examples could be found using google.

BTW, this LED discussion is a bit off topic and should probably be in its own thread.

RC-CAM

Katanadon
Mar 11, 2005, 05:15 PM
If you are going to familiarize yourself with SPI then you might as well try this setup......

http://www.captain.at/electronics/pic-mmc/

MMC card data transfer with PIC, 3.3 v logic conversion, I suggest using a low voltage device.....