Page 1 of 1
high/low voltage detect
Posted: Fri Sep 27, 2013 3:58 pm
by siliconchip
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
Re: high/low voltage detect
Posted: Fri Sep 27, 2013 7:10 pm
by Kenrix2
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.
Re: high/low voltage detect
Posted: Fri Sep 27, 2013 9:32 pm
by siliconchip
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 ???
Re: high/low voltage detect
Posted: Fri Sep 27, 2013 10:03 pm
by Kenrix2
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?
Re: high/low voltage detect
Posted: Fri Sep 27, 2013 10:36 pm
by siliconchip
here is my code
Re: high/low voltage detect
Posted: Fri Sep 27, 2013 11:28 pm
by Kenrix2
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
Re: high/low voltage detect
Posted: Sat Sep 28, 2013 3:20 pm
by siliconchip
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

Re: high/low voltage detect
Posted: Sat Sep 28, 2013 6:02 pm
by kersing
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.
Re: high/low voltage detect
Posted: Sat Sep 28, 2013 6:52 pm
by siliconchip
thanks kersing the program now works as intended,
