high/low voltage detect

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

high/low voltage detect

Post 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

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: high/low voltage detect

Post 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.

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: high/low voltage detect

Post 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 ???

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: high/low voltage detect

Post 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?

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: high/low voltage detect

Post by siliconchip »

here is my code
Attachments
low voltage detect.fcf
(9.5 KiB) Downloaded 257 times

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: high/low voltage detect

Post 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

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: high/low voltage detect

Post 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 :(
Attachments
low voltage detect.fcf
(10 KiB) Downloaded 271 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: high/low voltage detect

Post 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

Code: Select all

FCV_TRIPPED = pir2.HLVDIF;
to a C code block inside the loop.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times
Contact:

Re: high/low voltage detect

Post by siliconchip »

thanks kersing the program now works as intended, :oops:

Post Reply