INTERRUPT FOR PIC 16F1937

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

INTERRUPT FOR PIC 16F1937

Post by SILVESTROS9 »

Hello to all !
I would like to monitor the total current on 2 resistors (schematic) in a project with FC7..I use ADC2 and ADC7 to measure the current with VL, VH..When Itot exceeds a imax then the flowcode will call a macro ( LOAD_OVERCURRENT1), to set off some inputs and write a warning message on lcd.... I was tried to use interrupt property to enable an interrupt with IOC(portb), B.6 pin ,but this is relative slow and not always work, because I must use a additional code to turn on B.6 when Imax...so, I need fast reaction when Imax, especially in short circuit to protect mosfet ....is that possible with interrupt on custom, and what code can I use to that case (properties) ? any idea to control the Imax before V+ slow down that goes pic to reset and destroy the mosfets?
Attachments
CCONTROL WITH PIC16F1937.pdf
(278.09 KiB) Downloaded 248 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: INTERRUPT FOR PIC 16F1937

Post by medelec35 »

If it was me, For rapid speed, I would forget about ADC.
Just use a low value fixed resistor that when a excess flows through it, the voltage drop across it will be high enough for logic 1 of interrupt.
Then within the interrupt place an output that when its logic 0 will cut the supply to the mosfet.
You can use INT and IOC or just IOC.
Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: INTERRUPT FOR PIC 16F1937

Post by SILVESTROS9 »

thanks medelec35...I was think that , but with the desired limit of 20A resistors must be 0.25ohm/5w, large enough,with heat dissipation ...I prefer to use 3 resistors 0.03ohm/1w in parallel (smd), so for 20A I have to handle 0.2V ...there are some problems ..i need some additional circuits to isolate voltage drop on resistor to prevent cpu damage if the current control fails...also the limit of 20A is critical and the logic 1 is wide enough for this current accuracy..the speed of current monitor is not critical..just only to work before +VCC of pic drops ....tolerance of Imax must be +-0.2A...it wil be useful for interrupt to run a small code with ADC , instead to set that many times in the main code....is that possible with custom interrupt using handler code with enable/disable codes ?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: INTERRUPT FOR PIC 16F1937

Post by medelec35 »

If you don't mind a bit of extra hardware,
Rather than using high wattage resistors, what about using the two comparators within PIC?
It just means using two extra pins for the two fixed resistors (connect both inverting pins together, unless different thresholds are required) to set threshold voltage e.g 0.2V
As trigger voltage is then lower, the chosen current sensing resistor can be a lower wattage.
Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: INTERRUPT FOR PIC 16F1937

Post by SILVESTROS9 »

unfortunately , I have no free pins in PIC , only E.2 (ADC7) and B.5 (ADC2) ....using a small code with ADC, then when Imax set a pin to 1 , and then use the IOC for that pin, that works some times, but because the main code has many time delays , I can't have permanent monitor of current...i think that If the small code that set a pin to 1, it possible to run in the background, maybe with interrupt , or another way, the current control wiil be more safe...

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: INTERRUPT FOR PIC 16F1937

Post by medelec35 »

SILVESTROS9 wrote:unfortunately , I have no free pins in PIC , only E.2 (ADC7) and B.5 (ADC2) .
What I would do in that case is swap E2 with any port B pin's so you have 2 portB pins free.
Add a dual comparator e.g LM293 with the correct bias resistors.
The outputs of the comparators can then go the port B pins which can be configured as IOC pins.

If time for fault detection was not an issue then ADC would have been the easiest route.
Martin

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: INTERRUPT FOR PIC 16F1937

Post by SILVESTROS9 »

good idea ...I'll test it....what if Imax must be total current IL + IH ? that's a puzzle because we need calculation therefore extra time....

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: INTERRUPT FOR PIC 16F1937

Post by QMESAR »

Hi
I agree with Martin using a comparator also are you aware that the 1937 has internal Comparitor module that possibly can do exactly what you need :D

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: INTERRUPT FOR PIC 16F1937

Post by SILVESTROS9 »

thanks QMESAR , I know that , but I have no free inputs....I 'll try with ext. comparator (LM339 or LM393).

SILVESTROS9
Posts: 115
Joined: Wed Aug 03, 2016 10:45 pm
Has thanked: 24 times
Been thanked: 11 times
Contact:

Re: INTERRUPT FOR PIC 16F1937

Post by SILVESTROS9 »

I tried with an external comparator LM 393 with IOC for output pin, , and works fine....many thanks for help...

Post Reply