
Originally Posted by
jason
this is to be fabricated by the hundreds, price is an issue.
What about the onboard "HLVD"
But then again its all in ASM. It talks about these steps
1. Write the value to the HLVDL3:HLVDL0 bits that
selects the desired HLVD trip point.
2. Set the VDIRMAG bit to detect high voltage
(VDIRMAG = 1) or low voltage (VDIRMAG = 0).
3. Enable the HLVD module by setting the
HLVDEN bit.
4. Clear the HLVD interrupt flag (PIR2<2>), which
may have been set from a previous interrupt.
5. Enable the HLVD interrupt if interrupts are
desired by setting the HLVDIE and GIE bits
(PIE2<2> and INTCON<7>). An interrupt will not
be generated until the IRVST bit is set.
How do I write these values that it needs. Can I do it in PicBasic pro?
I have been working with the onboard HLVD module in a 18F4550 to use it as a low voltage monitor for my application. I am posting my current PBP code below that is suppose to do steps 1-5 you list above that are called out in the Data Sheet. I am prettry sure this is the right code, but it wasn't working, so I ran an ICD on it and discovered that when it gets to this procedure which is located in my main program loop, the first HLVDCON statement executes to clear HLVDCON.4, however the next statement (HLVDCON = %00011101) which is suppose to perform steps 1-3 in your above listing, doesn't execute....nor do any of the remaining statements in this process block execute...instead the program always jumps to an Interrupt Service Routine that is suppose to service a DT_INTS-18 interrupt triggered by a real-time clock. However the RTC interrupt isn't timed to happen when this happens. I can't figure out why this this HLVDCON statement is not executing and the rest of this block is not executing in the main loop before the interrupt happens.
Can anyone advise me what is happening here and how to fix it??
Code:
' Test for low battery conditon
' Set registers for using HLVD feature
HLVDCON.4 = 0 'Disable the module by clearing HLVDCON.4
' Set the trip point at Vdd=4.4 vdc by setting HLVD3:HLVDL0=1101
' Set VDIRMAG=0 (HLVDCON.7) to detect low voltage transition
' Enable the HLVD module (HLVDCON.4=1)
HLVDCON = %00011101
' Clear the HLVDIF interrupt flage (PIR2<2>)
PIR2.2 = 0
' Enable the HLVD interrupt
PIE2.2 = 1
INTCON.7 = 1
' Set IRVST bit (HLVDCON.5 =1) to allow interrupt generation
HLVDCON.5 =1
If PIR2.2 =1 THEN ' Test for HLVD interrupt (HLVDIF bit = 1)
For I = 0 TO 4 ' Blink the RED LED 5X as low battery warning
High LED_RED
Pause 500
LOW LED_RED
pause 500
next
ENDIF
Bookmarks