Hi All,
I was wondering if anyone has done any work with the LVD module in the 18F pic's.
I've been reading the 18F425 datasheet, and unfortunately ISIS doesn't model the LVD module in the PIC, so I'm about to start some testing and just wondered if anyone could give me a start with some sample code.
Thanks heaps.
Jason
Low Voltage Detect Code
Moderators: David Barker, Jerry Messina
Hello Jason,
I use it a lot for controlling external battery switching, heres some excepts that may be of use to you.
The CtlEXt and CtlBatt are the control lines to the battery switches. The interrupt fires to switch the system from ext to battery, the switch back (not shown here) actually occurs on a slow timer to add some hysteresis to the system. It watches the extpresent variable and uses the ExtDebounce to keep track. In my system the debounce is essential as the connect / reconnect of power is a messy business!
Hope this makes sense!
Interrupt:
This is the initialisation;
I use it a lot for controlling external battery switching, heres some excepts that may be of use to you.
The CtlEXt and CtlBatt are the control lines to the battery switches. The interrupt fires to switch the system from ext to battery, the switch back (not shown here) actually occurs on a slow timer to add some hysteresis to the system. It watches the extpresent variable and uses the ExtDebounce to keep track. In my system the debounce is essential as the connect / reconnect of power is a messy business!
Hope this makes sense!
Interrupt:
Code: Select all
// HLVD Stuff
Public Const
DirUp = 1, 'HLVD directions
DirDown = 0
Public Dim
ExtDebounce As Word,
ExtPresent As Boolean
Code: Select all
// In interrupt
If HLVDIF = 1 Then
// Determine current state
If HLVDDir = DirDown Then 'Switch to battery
CtlBatt = 1
CtlExt = 0
HLVDDir = DirUp 'Watch for Rising Ext
ExtPresent = false
ExtDebounce = 25 'was 500
HLVDIE = 0 'Turn off Rising edge interrupt for a while
'Reenabled by timer at extdebounce = 1
Else 'Ext is Present
ExtPresent = true 'Set timed switch
HLVDDir = DirDown 'Watch for Falling Ext
ExtDebounce = 50 'was 255
EndIf
HLVDIF = 0 'Clear Flag
EndIf
Code: Select all
Public Dim
HLVDOn As HLVDCON.4,
HLVDDir As HLVDCON.7,
HLVDStable As HLVDCON.5,
HLVDIF As PIR2.2,
HLVDIE As PIE2.2,
HLVDIP As IPR2.2
Code: Select all
//HLVD Setup
Low(CtlExt)
Low(CtlBatt)
// Set for External input
HLVDCON.3 = 1
HLVDCON.2 = 1
HLVDCON.1 = 1
HLVDCON.0 = 1
HLVDIP = 0 'Low Priority
HLVDDir = DirDown 'Check for falling Ext supply initally
HLVDOn = 1
Repeat
DelayMS(100)
Inc(n)
Until HLVDStable = 1 Or n = 50
HLVDIF = 0
// Enable HLVD Interrupt
HLVDIE = 1
Thank you so much Ranger bob!!
You and Jerry Messina are so awesome on this forum.
Ok, I'm off to do some coding!!
I'm making a battery management module for some lithium phosphate polymer batteries (LiFePO4). It's a battery pack I've made up for a sound level meter, and I need the LVD module in the pic to cut off supply when the voltage gets too low. That kind of thing.
Thanks again for sharing your code.
You and Jerry Messina are so awesome on this forum.
Ok, I'm off to do some coding!!
I'm making a battery management module for some lithium phosphate polymer batteries (LiFePO4). It's a battery pack I've made up for a sound level meter, and I need the LVD module in the pic to cut off supply when the voltage gets too low. That kind of thing.
Thanks again for sharing your code.