PDA

View Full Version : brown out resets



robertpeach
- 22nd September 2009, 14:34
hey again guys, ive managed to create my program eventually.. the pic is basically the controller of the rectifier controller of a wind turbine... :P everything works nice and smooth and how id like it to.

however there is one last thing i want to implement. im trying to display total kilowatt hours on the LCD, however obviously when the wind dies then the pic has no power and therefore turns off... but when the wind revives the pic restarts due to the brown out reset.

however when the brown out resets occurs i will have lost all temporary data in the ram. i was wondering if there was a way to use some form of brown out interupt to quickly save the data of "total energy accumulated" before the voltage goes so low that the pic turns off. and then when the reset occurs the energy accumulated is then taken from flash and carried on counting the energy?

or if there is another way of doing this effectively

thanks :P

Jerson
- 22nd September 2009, 14:53
What I'd recommend is to use an early warning signal. The raw voltage input to the 5V regulator would be a good point to monitor the power. Use this voltage to signal a power failing and if this is set properly, you can get sufficient time to put your counter to EEPROM. Your 5V should be bypassed sufficiently to allow the write to complete.

mackrackit
- 22nd September 2009, 15:09
This might give you an idea or two
http://www.picbasic.co.uk/forum/showthread.php?t=11567

robertpeach
- 22nd September 2009, 15:34
thanks guys, unforuantely i didnt really understand much of what was going on in that thread mack! it seems a bit advanced for me..

i havnt actually got a voltage regulator, or ever used one... so they take the input and then give me an output voltage which i can send to the pic? how would i measure the output voltage, just use an ADC port?

mackrackit
- 22nd September 2009, 15:50
OK, lets back up and tell how you are powering the PIC. Voltage and voltage source(source is from wind machine) but it has to be brought down/up to PIC levels.

If you are still on the same PIC and project I think you are running at 20Mhz, so I will assume you are getting around 5 volts from some place. ????

robertpeach
- 22nd September 2009, 16:08
well basically we have got the analogue high voltage part of the circuit which is converted to a 5v voltage for the CAP inputs and the ADC measuring voltages.

we also have a DC 12v supply from another part of the power electronics which i attach to a 12DC to 5DC converter... this is wheree i get the voltage to power the pic :)

mackrackit
- 22nd September 2009, 16:40
OK, that gives you plenty to work with. You should be able to adapt the schematic in the thread I linked you to.

What we are basically doing is monitoring the 12 volt in this case. An ADC could be used but you will have to keep checking it in your code. If you use the interrupt on change then it all happens for you...

Either way, the trick is having large enough caps to run the PIC long enough to write the data to eeprom. When the voltage coming to the PIC or the power supply drops beyond a certain point your software will jump to a SAVE/SHUT DOWN routine.

The problem I see happening with you setup is the voltage drops enough to go to the SAVE routine then comes back up before the PIC actually stops from lack of voltage.

robertpeach
- 23rd September 2009, 08:58
how do these interupts on change work? is this the DT instant interupt stuff? are there any specific brown out reset interupts?

edit: actually just found it in data sheet, looking through it now :)

mackrackit
- 23rd September 2009, 09:36
You can use DTs stuff for this but regular interrupts should be fast enough.

robertpeach
- 23rd September 2009, 09:53
ok thanks, ill just use normal interupts! im gonna look around and try and make some code to use interupts

robertpeach
- 23rd September 2009, 12:08
ok ive made my code, probably got some errors in, however thats not the problem. ive been thinking about this whole trouble with if the voltage is idling on a point lower than my low voltage detection level but not low enough that it causes a reset... problem is.. if it gets too that point my program starts looping because the interupt keeps getting set off by the low voltage.

i was thinking since when the wind turbine actually gets slow enough that the voltage is about 2-3 volts, its not actually giving out any power (if it does then its completely negligible). so when i get to a low point can i just turn off the pic? and get it too restart when the power gets higher?

mackrackit
- 23rd September 2009, 12:58
You might be able to use an external comparator to watch the voltage and kill the PIC that way....

What about a small rechargable battery pack to run the PIC for a few hours then the PIC is always on.

robertpeach
- 23rd September 2009, 13:17
im gonna look into the battery idea actually, but flaws with it could be that over 20 years a rechargeable battery will have effectively "lost its ability to recharge" and also there will be points where the wind is dead for longer than the battery can keep the pic and lcd running...

are there any commands to just turn off the pic and then get it back going when the voltage is high enough? cos surely if the pic is turned off... how can it be turned back on again? since the software is obvioulsy not running because the pic is off :S

robertpeach
- 23rd September 2009, 14:01
actually does the power on reset turn the pic back on after i have turned it off? if i put the mclr pin to Vdd, it will detect a rise in voltage? and cause a reset?

if i turned the pic off at a certain voltage... and then when the pic detects a rise in voltage the power on reset occurs and turns my pic back on and restarts the program?

mackrackit
- 23rd September 2009, 14:04
im gonna look into the battery idea actually, but flaws with it could be that over 20 years a rechargeable battery will have effectively "lost its ability to recharge" and also there will be points where the wind is dead for longer than the battery can keep the pic and lcd running...
Pros and cons no matter what. I have one of the "smart thermostats" at the house. It runs on two AA batteries that need changed once a year or so. Might have to be a bit of upkeep for the end user???? I know, not good.


are there any commands to just turn off the pic and then get it back going when the voltage is high enough? cos surely if the pic is turned off... how can it be turned back on again? since the software is obvioulsy not running because the pic is off :S
There is the sleep command but that just puts the PIC in low power mode.

I have a feeling that the best way to go will be an external comparator working a latching relay or FET on the 12 volt line. Rig it so when the voltage drops below X the relay stays off untill the voltage comes back up to Z. Give a little range between the two points.

Then the interrupt thing should work. If the PIC shuts down only from lack of power it will restart.

Just thinking.... Or is it babbling :)

robertpeach
- 23rd September 2009, 14:32
no ive been thinking and the ways that you describe are the only two ways i can think of doing it... the battery thing would work nicely i just dont think a customer would be too happy having to change batteries much...

im gonna try out ur second example with the comparator! thanks for your help once again mack! ill let u know how it goes

robertpeach
- 24th September 2009, 09:19
update:

well basically dave i looked into the whole idea... and basically it just seemed all a bit much for one thing. ive decided on the simplest option, even if it is a bit time consuming and not as efficient for the pic. im just gonna save the data to eeprom every 0.25 kwh instead of only saving when pic powers down... this will require a bit more pic power and wont be as accurate since it could be 0.24kwh through when the pic dies... and that 0.24 kwh is not actually added on... this could happen quite alot if the wind is low and the turbine keeps starting and stopping...(although it wont matter that much since the energy out at those stages is pretty negligible anyway) but will be cheaper and easier probably! less things to go wrong in my case :)

mackrackit
- 24th September 2009, 11:01
One more thought....
To keep from missing that last bit of good data you could have the code do a last write when the power, speed or what ever drops to a certain point. Anything below that point and you do not write data. Once the machine is running above a certain point it goes back to writing every 0.25kwh. That way the starts and stops will not bother.

robertpeach
- 24th September 2009, 11:21
thanks mack thats actually a good idea, ive already got the code for when the low voltage detection, so ill just implement that in. would i bother resetting the interupt flag once an interupt for low voltage detection is made? because that would cause an endless loop of the interupt if the wind turbine was at a speed low enough for low voltage detection but not low enough for a reset...

additionally ive come across another problem which is actually just me being stupid...

if ive got a power output which is being updated on my pic at a high frequency (power output is found from comparing the revolutions of the wind turbine per minute). how would i get a total energy accumulation value?

since the power will be changing over time... it means the rate that my total energy accumulation is increasing will change also... would i find the average poweer over lets say 10 seconds and then multiply that by 10 to get the total energy accumulated over 10 seconds?

additionally since ive only got picbasic pro and not pbpl it means i cant use LONG. this means i can only get up to 65536, whereeas the number of kwh is gonna be about 200,000 over the 20 years... any ideas on this one? if im gonna be wanting to use a decimal e.g 655.25 kwh then thats gonna mean im gonna get a max of 655 kwh...

its goonna be about 10,000 kwh a year... over 20 years thats 200,000... so if i write to eeprom every 0.25kwh then thats 800,000 writes... and a pic can only take a million erases?

mackrackit
- 24th September 2009, 13:02
I would try something like.
If rpm is less than X then disable the INTCON.

Calculating power from the RPMs. Setup a timer to read the rpm evert so many seconds, after maybe a 100 reads average the RPMs giving aveage power over that time span??? If the wind is not changing much it should be pretty accurate.

Of you have PBP then you have LONGS. Using MCS? Tell it to compile using PBPL. That can be found under one of the options in the tool bar. MPLAB? When you set the language it should b there.

Yup, the EEPROM has some limits. I have been using a SD card for data logging.
Add a RTC if you do not have one in the project and you have plenty of room on a SD to save the time, RPM, power and what ever else. When you want to just pop it into a PC and chart, display or what ever. Easy way to get data from PIC to PC.

Yup, more babbling :)

aratti
- 24th September 2009, 13:57
since ive only got picbasic pro and not pbpl it means i cant use LONG. this means i can only get up to 65536, whereeas the number of kwh is gonna be about 200,000 over the 20 years... any ideas on this one?

I don't have long either, this is my turn around:




AA var word
BB var word
CC var word
DD var word

Long:
AA=0
While AA<>BB
AA=AA+1
CC=CC+1
If CC=0 then DD=DD+1
wend

Return



You place your reading in variable BB and gosub long, here your reading will be accumulated in variable CC and DD, that you can save at your discretion.
Reading back the long is simple just (DD x 65536)+CC

Al.

Archangel
- 25th September 2009, 04:28
Hi Robert,
To get a clean PIC reset you could tie the MCLR pin to ground using an NPN transistor and a resistor to + , then on the transistor's base circuit feed it with a suitable capacitor, tied to the generator, when it spins up the transistor will pull the mclr pin low until the cap charges and then turn off.

ivirscar
- 4th October 2009, 07:12
Just use a simple voltage drop detector. I use a 4.5v detect on the supply of my odometers and I've tested the crap out of this application and NEVER fails to write the value to EEPROM once power is disrupted. The volt detector is nothing more than a "switch" to ground thus when it's supply which shares the supply of the pic, goes to 4.5 volts or lower, it will switch any input selected on the pic to low to activate your "save data" routine. Use a capacitor of 220uf to slowly drain the power while giving time to do the action. Once your action is complete, use a resistor or load to complete the cap drain...