PEU
Flashlight Enthusiast
Since DJPark presented us with the POP driver concept (and then it was used by a myriad of other drivers) it was a mistery to me how to know when the circuit lost its power. Found many solutions to this problem, but none of them were as elegant as the original idea.
So I decided that was about time to do an extra effort.
I started by stripping a DealExtreme 5levels driver to its bare board and capture the schematics:
Its clear that the capacitor holds the power while the power is down in the ON-OFF-ON cycle that changes levels.
But then what happens? I didn't knew, so I posted a question in a Microchip Related Forum (Thanks Alain & Others!!) to see if someone else was able to help me.
The solution was found in less than a couple of hours, but it took ME a couple of days to understand it
Here is the gist of it, to understand the following, some knowledge of PIC programming is needed.
The PIC chips (12F629 in this case) have a Brown-Out Detection feature that can be enabled at programming time by setting a bit in the configuration register. Its called the BODEN bit (Brown-out Detection ENABLE)
Then we have the capacitor that performs two functions in the circuit:
1) keep power when battery power is lost
2) by carefully selecting its value, you allow the uC to survive n milliseconds
Then we have the Brown-Out and Power on Reset bits at the PCON register.
In normal conditions, when the uC starts for the first time or when power was lost for a long time this bit is set at 0 (datasheet: TABLE 9-6: INITIALIZATION CONDITION FOR SPECIAL REGISTERS)
BUT, here is the KEY, if power was lost but our capacitor managed to keep the uC running in the ON-OFF-ON with voltage below vBOD (Brownout voltage, see datasheet) but above vreset (below this value uC cold resets) BOR will show that power was lost for a little while but then it was recovered.
To be able to detect changes in these bits, we must set them to 1 the line after we check their value, remember Brown-Out Reset restarts your program from the top, not from where it was running, the only difference this time is that the PCON register values aren't lost like what happens in a cold start.
The metacode would be something like this:
I hope this help some of you guys to develop new drivers, I hope I can finish mine
Another option can be used: instead of building a driver from scratch, why not reprogram already made ones to suit your need
I must say thanks again to the people that helped me in this quest to learn new stuff, without them I would be still scratching my head.
Pablo
So I decided that was about time to do an extra effort.
I started by stripping a DealExtreme 5levels driver to its bare board and capture the schematics:
Its clear that the capacitor holds the power while the power is down in the ON-OFF-ON cycle that changes levels.
But then what happens? I didn't knew, so I posted a question in a Microchip Related Forum (Thanks Alain & Others!!) to see if someone else was able to help me.
The solution was found in less than a couple of hours, but it took ME a couple of days to understand it
Here is the gist of it, to understand the following, some knowledge of PIC programming is needed.
The PIC chips (12F629 in this case) have a Brown-Out Detection feature that can be enabled at programming time by setting a bit in the configuration register. Its called the BODEN bit (Brown-out Detection ENABLE)
Then we have the capacitor that performs two functions in the circuit:
1) keep power when battery power is lost
2) by carefully selecting its value, you allow the uC to survive n milliseconds
Then we have the Brown-Out and Power on Reset bits at the PCON register.
In normal conditions, when the uC starts for the first time or when power was lost for a long time this bit is set at 0 (datasheet: TABLE 9-6: INITIALIZATION CONDITION FOR SPECIAL REGISTERS)
BUT, here is the KEY, if power was lost but our capacitor managed to keep the uC running in the ON-OFF-ON with voltage below vBOD (Brownout voltage, see datasheet) but above vreset (below this value uC cold resets) BOR will show that power was lost for a little while but then it was recovered.
To be able to detect changes in these bits, we must set them to 1 the line after we check their value, remember Brown-Out Reset restarts your program from the top, not from where it was running, the only difference this time is that the PCON register values aren't lost like what happens in a cold start.
The metacode would be something like this:
Code:
init configuration bit to enable BOD
init registers to proper values
(depending on your program, main loop needs)
if PCON.1=1 and PCON.0=0 then this means BOD was detected
set these bits to 1
mainloop
your payload here
loop
end
I hope this help some of you guys to develop new drivers, I hope I can finish mine
Another option can be used: instead of building a driver from scratch, why not reprogram already made ones to suit your need
I must say thanks again to the people that helped me in this quest to learn new stuff, without them I would be still scratching my head.
Pablo