hi all
im interested in adding the high/low voltage detect function (HLVDCON) using a pic 18f4550 to a future project, therefore at a set voltage say 3.9v I could display a warning on an lcd to change the batteries, I know how to set the HLVDCON register but once the trip point (3.9volts) is reached im having trouble in initiating a warning on the LCD, I don't know how to monitor this register to show a warning at the desired voltage, any help please, many thanks in advance
high/low voltage detect
Moderator: Benj
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 25 times
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
Re: high/low voltage detect
I don't have that microcontroller so I can't test it but, you could try this.
Add a variable in Flowcode called tripped. If the voltage crosses the trip point, bit HLVDIF of PIR2 register gets set, so you just need to monitor that bit. Drop a "C Code" icon and add the folowing FCV_TRIPPED=pir2.HLVDIF; and then check if variable tripped = 1.
Add a variable in Flowcode called tripped. If the voltage crosses the trip point, bit HLVDIF of PIR2 register gets set, so you just need to monitor that bit. Drop a "C Code" icon and add the folowing FCV_TRIPPED=pir2.HLVDIF; and then check if variable tripped = 1.
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 25 times
Re: high/low voltage detect
HI
I have added the variable tripped along with the code in a c box but no joy, am I right in thinking I need to set bit7 of intcon if so how do I set a single bit or does all of intcon need setting if at all ???
I have added the variable tripped along with the code in a c box but no joy, am I right in thinking I need to set bit7 of intcon if so how do I set a single bit or does all of intcon need setting if at all ???
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
Re: high/low voltage detect
Setting bit 7 of the intcon register won't help since the HLVDIF bit of the pir2 register never gets set. Can you share the portion of your code dealing with this so we can have a look at what the problem might be?
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 25 times
Re: high/low voltage detect
here is my code
- Attachments
-
- low voltage detect.fcf
- (9.5 KiB) Downloaded 295 times
-
- Flowcode v5 User
- Posts: 211
- Joined: Tue Feb 19, 2013 9:51 pm
- Has thanked: 72 times
- Been thanked: 177 times
Re: high/low voltage detect
Just from reading the data sheet on how to set up the HLVD module you first configure the register hlvd=0b00001110; and then enable it with set_bit(hlvdcon,HLVDEN); . Sometimes, but not always, setting up modules and turning them on in one write cycle can cause unexpected results. Then you have to wait for it to stabilize by either inserting a delay or monitoring the IRVST bit to make sure it is set. You can monitor the IRVST bit the same way you monitor the HLVDIF bit. Create a new variable ready. FCV_READY =hlvdcon.IRVST; and monitor for variable ready=1in a loop. Then the module is able to set the HLVDIF bit of the pir2 register when a voltage trip point has occurred. So now you can start to monitor it with FCV_TRIPPED=pir2.HLVDIF;
Good luck
Good luck
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 25 times
Re: high/low voltage detect
I have added extra C code and spent several hours going over this reading the data sheet and making changes but i am not getting the desired effect on hardware but now I feel im going round in circles, would appreciate my code being looked at 

- Attachments
-
- low voltage detect.fcf
- (10 KiB) Downloaded 306 times
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: high/low voltage detect
One thing I notice right away: you are not reading the bit in the loop, just once at the start of your code.
To read the bit in the loop, move
to a C code block inside the loop.
To read the bit in the loop, move
Code: Select all
FCV_TRIPPED = pir2.HLVDIF;
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
- Posts: 392
- Joined: Wed Jan 05, 2011 11:24 am
- Has thanked: 101 times
- Been thanked: 25 times