|
|
View previous topic :: View next topic |
Author |
Message |
tienchuan
Joined: 25 Aug 2009 Posts: 175
|
Problem PIC reset when interrupts RB |
Posted: Sat Jun 14, 2014 5:44 am |
|
|
Hi.
I have a problem when try using RB interrupt to detect AC signal.
Here is my circuit to detect AC 220V-50Hz:
When I plugged in AC 220V, the PIC will reset.
In my schematic, because I want to capacitor discharge faster, so that I put serial with resistor,can it make a problem ?
In my program, I used RB interrupt to detect signal from optocoupler.
Code: |
int8 input_state_b(void)
{
#byte PortB = getenv("SFR:PORTB")
return(PortB);
}
#int_rb
void ngat_rb()
{
delay_ms(50);
check_so_sa=1;
temp_read=input_state_b();
clear_interrupt(int_rb);
}
|
and here's configs of fuses:
Code: |
#include <18F4680.h>
#fuses H4,PUT,NOPROTECT,NODEBUG,NOLVP,NOWDT,NOPBADEN,MCLR,BROWNOUT,BORV21,NOSTVREN
#use delay(clock=40000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, errors)
|
I'm used PIC18F4680, CCS C complier 5.025.
Thanks all. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sat Jun 14, 2014 6:49 am |
|
|
hardware....
Those on your 'side of the pond' can help with a better 'front end'. I prefer to use a small 220-5V step down transformer instead of having 330VDC entering an optocoupler on MY PCB ! It's a safety issue for me and my PIC.
A series resistor with a capacitor will really slow response.
Since the name of the input is 'count_ac' , is the PIC supposed to count pulses? If so..then a capacitor will slow things down as well!
There are commercial devices available like the IAC5.If you Google that, you may see a schematic of what's 'inside the box'.
software...
You do not need to clear the interrupt, inside the ISR. The compiler does that for you automatically.
Also delete the delay-ms(50); from the ISR. You do NOT require it.The ISR was triggered by an 'event'. ISRs are supposed to be FAST, get in...do 1 or 2 simple things(like flags,or set variables) then get out fast.
hth
jay |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Jun 14, 2014 2:13 pm |
|
|
Temtronic is right. On my home energy monitoring system I use 110v to
3v step down transformers and feed that via isolation resistors to
the PIC input(s) (I monitor both halves of single phase 220 to neutral so I
have two transformers and two inputs). I mounted the transformers in the
circuit panel so the only voltage that leaves is the 3VAC to the PIC circuit.
I attached a good quality DVM on the 110VAC input then scaled the
resulting conversion to match the actual AC input.
BTW, be sure and fuse the xfrmr inputs and outputs!
I fused mine at 750ma...on both sides _________________ Google and Forum Search are some of your best tools!!!! |
|
|
tienchuan
Joined: 25 Aug 2009 Posts: 175
|
|
Posted: Sun Jun 15, 2014 1:29 am |
|
|
temtronic wrote: | hardware....
Those on your 'side of the pond' can help with a better 'front end'. I prefer to use a small 220-5V step down transformer instead of having 330VDC entering an optocoupler on MY PCB ! It's a safety issue for me and my PIC.
A series resistor with a capacitor will really slow response.
Since the name of the input is 'count_ac' , is the PIC supposed to count pulses? If so..then a capacitor will slow things down as well!
There are commercial devices available like the IAC5.If you Google that, you may see a schematic of what's 'inside the box'.
software...
You do not need to clear the interrupt, inside the ISR. The compiler does that for you automatically.
Also delete the delay-ms(50); from the ISR. You do NOT require it.The ISR was triggered by an 'event'. ISRs are supposed to be FAST, get in...do 1 or 2 simple things(like flags,or set variables) then get out fast.
hth
jay |
Thanks u.
In this project, I don't want to use transformer down voltage 220-5V, because it make PCB large and not good low cost solution.
In the last, I tested with 110V AC- with this circuit, but when i change plug 220VAC, the resistor is so hot, I can't understand why it wrong because flw caculated the resistor only 2W, but I put resistor 5W, but it still hot.
Sorry, It right to detect signal AC, not count AC, because I haven't fix this schematic.
In my interrupt RB, I know it auto clear interrupt flag but I want to ensure it's cleared, because i don't read ASM code.
Thanks for your reply, I'll repair this circuit and update to you.
Thanks _________________ Begin Begin Begin !!! |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Sun Jun 15, 2014 6:11 am |
|
|
tienchuan wrote: |
In this project, I don't want to use transformer down voltage 220-5V, because it make PCB large and not good low cost solution.
In the last, I tested with 110V AC- with this circuit, but when i change plug 220VAC, the resistor is so hot, I can't understand why it wrong because flw caculated the resistor only 2W, but I put resistor 5W, but it still hot.
Sorry, It right to detect signal AC, not count AC, because I haven't fix this schematic.
In my interrupt RB, I know it auto clear interrupt flag but I want to ensure it's cleared, because i don't read ASM code.
Thanks for your reply, I'll repair this circuit and update to you.
Thanks |
Running a 5W resistor @ 2W it WILL get hot.
I've just looked up the data sheet for a typical 5W part.
It's derated 5W to 0W from 25C to 350C.
Therefore you can expect it to rise roughly 65C per W.
That's a 130C rise for your 2W case.
As an aside, the effect of the capacitor in your circuit is to almost completely remove the ability detect 50Hz AC.
Mike |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sun Jun 15, 2014 7:17 am |
|
|
The resistor, will probably be larger than the transformer...
(Once you allow for some cooling area.)
You can get PCB mount transformers that are under one cubic inch.
Have a look at:
<http://www.nordtek.com/index.php?m=products&id=81>
2W of heat still has to go somewhere. A '5W' resistor is typically rated at a temperature like 110C _in free air_. So resistor sitting well off the board, with a good airflow around it. Stick it tight to the board, with restricted airflow, and it's rating plummets, and it'll run _hot_.....
A solution is a whole set of parts, including things like 'where the heat goes'. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sun Jun 15, 2014 7:48 am |
|
|
Since you're drawing over 2 watts, the resistor should have at least a 10W rating to NOT heat up. Over time a hot resistor will fail, usually at 3 in the morning on a cold Winter's night! You could use 2 or more resistors in series to reduce the power loss per resistor. Adds more cost, bigger PCB, 2X the failure possible.
You could 'cheat' and use a capacitor to reduce the 330VDC down to 5-ish volts...well known in some products.
But....it still means there's MAINS voltage on the PIC PCB. Never a good idea, especially for a commercial product. If that's the case you MUST get 'approval' from some regulatory body. That's WHY 'wallwarts' were invented ! They're pre-approved and allow SAFE levels of electrons to flow all over your project.
I'm still in favour of a small transformer solution. Cheap, safe, reliable and OFF the PCB.
Doesn't matter if this is a one-off or batch of 1,000 units; parts cost is minimal per unit compared to R&D time.
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sun Jun 15, 2014 2:44 pm |
|
|
As a separate comment, look carefully at the voltage rating of any resistor used like this. With a 230v input, the peak voltage will be nearly 330v. Allow then for the over-voltage that a supply can have, and you need resistors with perhaps a 500v rating. Many types do not offer this.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|