PDA

View Full Version : AC Signal...



Tear
- 6th July 2005, 19:55
Today I am looking at starting a new "simple" project to continue playing with the PIC16F84. What I would like to do is use an AC Power Source as an input and then have the microcontroller turn on a LED for an output.

I am assuming that I need to use the PIC16F84 on chip A/D converter, but I am not sure if this is true as I am new to the microcontroller world and have not played with this.

Any help concerning how to use an AC source as input to a microcontroller would be very helpful.

Thank you,
Michael Schmidt

Melanie
- 6th July 2005, 20:23
You obviously have a death wish.

The 16F84 has no A/D... and even if it did, it wouldn't help you.

The attached schematic might increase your life expenctancy (or that of your PICs). C1 is a 10nF 1kV Disc Ceramic (good for 110-240vAC). It's there to limit the current going through IC1 which is an opto isolator like Cosmo's K1010. D1 a 1N4007 is there to stop the reverse-bias voltage killing the opto's LED emitter. The PIC's pin needs a pull-up to +Vdd, or use one of the weak-pull-up's on PortB. Add your own Fuses (if required and as appropriate to your application) on the AC Input line. 50mA is more than adequate.

The PIC will see a pulse at the frequency of your AC supply. Check for it using COUNT or PULSIN or whatever method you prefer. No Pulse, No AC. I use this method (or variations of it) to detect AC Supply Phase Failure, Fuses Blown etc etc.

Tear
- 6th July 2005, 21:23
After posting this morning I was looking at the data sheet for the PIC16F84 and came to the same conclusion that the PIC16F84 doesn't have an A/D converter. However, even if I went to a pic that did have a A/D converter that still wouldn't do anything for me then? I am not sure how the A/D converter works and I am going to look into this this afternoon.

I am also having a little bit of trouble understanding your circuit schematic. From what I understand it looks like the diode goes across terminals 1 (L) and 2 (N) of the IC1. (L) I am guessing is the AC Voltage coming in through the capacitor and then into terminal 1 of the IC1. Pin 4 goes to the input pin of the microcontroller, and pin 3 goes to ground. What is the (N) or what I am guessing is pin 2 to IC1?

Thanks for the help and sorry for the confusion on my part.

Michael

NavMicroSystems
- 6th July 2005, 22:05
Tear,

before we continue our guessing session,
would you tell us a bit more in detail what you are actually trying to achive?

(At least to me t is not really clear)

Your initial posting on this thread sounds a bit like you would like AC to supply your PIC.

Melanie
- 6th July 2005, 22:08
The L and N are Live and Neutral from your high-voltage AC Supply Input.

Warrier
- 7th July 2005, 00:07
Ms. Newman,
don't you think you need to provide a DC path for the LEDs in the opto coupler to conduct? - even a 100k would be sufficeint as the voltage across the diodes is clamped to about +/-1.7volts.

I think Mr. Schmidt should be warned of potential shock hazards! If he is aware of it then he could even use a series resistor (1Meg or more) to any input as the internal clamping diodes will limit this to Gnd and Vdd.

But then Ralph's question is also valid... Is Mr. Schmidt trying to use an AC power source? Hope not since he has used the title "AC Signal" and refers to internal ADC for the F84!

-warrier

NavMicroSystems
- 7th July 2005, 00:41
...a 100k would be sufficeint as the voltage across the diodes is clamped to about +/-1.7volts.


Well, in general this is correct, but:
lets's assume the Opto's LED current is as low as 10mA,
even at that low current at a voltage of 120 or 240 V the resistor would have to be quite large (in size) and dissipate a lot of heat,
would you really like this?

Warrier
- 7th July 2005, 01:05
Ralph:

Sorry I didn't make it clear, I guess. When using the optocoupler, the resistor would be across the two back to back LEDs inside the opto coupler. So the voltage across the resistor would only be +/- 1.7volts (the LED drop). Wattage is thus not an issue...

The series resistor of say 1Meg is INSTEAD of the opto coupler and need not carry the LED currents. It would be connected in series with the input pin of the PIC and is to limit the current through the clamping diodes provided on all I/O pins with a max current limit of +/-20mA.

With a 1 M resistor, the I/O current is safely limited to 240uA and the wattage would be about 0.06watts for the 240VAC. My concern was that Mr. Schmidt may accidentally come in contact with the live AC line with a "shocking" experience**** There might be some fire-works also.

-warrier

-warrier

Melanie
- 7th July 2005, 03:05
>> don't you think you need to provide a DC path for the LEDs in the opto coupler to conduct?

No. Think outside the box. Look at what C1 is doing at the supply frequency.

>> the resistor would be across the two back to back LEDs inside the opto coupler

Again no. This particular opto only has one LED.

>> even use a series resistor (1Meg or more) to any input as the internal clamping diodes will limit this to Gnd and Vdd.

You really want to rely on a Resistor and the PICs clamping diodes to stand between you and oblivion?

In my circuit the LIVE AC is on the primary (input) side of the opto. No LIVE circuitry (nope not even 240uA of it) ever touches the PIC. If your Resistor failed, the PIC would become LIVE at supply potential. In my circuit, if either C1, D1 or the opto failed, you would still be insulated by the ISOLATION characteristics of the opto (usually 5kV breakdown or more).

This is not a 'Theoretical' circuit plucked out of the air... it actually works and is in use in thousands of products every day. In the snapshot appended, here is the very circuit where the PIC is monitoring the state of two totally separate but critical AC Supply fuses.

Tear
- 7th July 2005, 15:47
Hi,

What I am trying to accomplish is to build a delay device that turns on your amp a few secs after the radio is turned on. I have already built this using the amp turn on line from the stereo which is DC Voltage line. However for my brother's car, that I also would like to put this in, his stereo doesn't have an amp turn on. Due to this I need to use the speaker lead which is an AC voltage signal.

Orginally I thought that using a AC/DC converter on a microcontroller might do the trick, but on further inspection it turns out this is not the case. I am now thinking about building a simple PNP Transistor Switching Circuit where the AC Voltage signal (line) would be connected to the base and control the switching with a +5V DC voltage following to the PIC when the switch is closed. However, I am not sure if this will work.

Essentially the easiest way to characterize what I need to do is somehow have the PIC dectect when the AC signal is HIGH either directly or maybe through some circuit like a PNP Transistor switch. Once the PIC detects the line as being HIGH then it will delay and set the output HIGH.

I hope that this explains what I am trying to do a little better, and thanks for the help.

~Michael

Melanie
- 7th July 2005, 18:21
Hmmm not quite an 'AC Power Source' ...

So you're telling us that the AC is really a dinky Audio Signal from a car radio and not a High-Voltage 'Power Source' ?

Tear
- 7th July 2005, 19:04
Well I havent measured so I dont know the exact voltage of the AC signal, but it is AC voltage signal that also powers the car speaker that it would feed off of.

~Michael

Sharky
- 7th July 2005, 19:15
Hi Tear,

Sorry to say it, but I think your on a slippery slope.

I agree that it is really fun to play and work with PIC's but I really think that there most be an easier way for you than to use a PIC for this job.

Are you sure that there is'nt a signal out from the car stereo for an electrical antenna or for the amplifier, this is quite normal when you have a lineout signal from the car stereo.

Sorry this is getting OT ! :(

Sharky

Ps. Thanks Melanie your circuit is really something I can use, normally I use a two-coulor LED to check if a fuse it blown, but it will be very cool :cool: to let a PIC do something to indicate that a fuse is blown

Tear
- 7th July 2005, 21:19
Well there is the antena lead off of the head unit (stereo) but the problem when using it is that if you play CD's instead of listening to the radio using the antena the line will be low and turn the amp off. This is due to the fact that the antena only has power when listening to the radio.... as far as I know.

~Michael

mister_e
- 8th July 2005, 03:23
If it's the factory radio this is probably the an HONDA, or NISSAN.... and most of them will cut the power on the electric antenna wire when switching to CD, tape deck.

Well there's another way... just use the accessory wire at the ignition switch, then do a delay... or not. Many time i did it in the past.

As far as i remind, DEI do something like the unit you want to do.

Usually, 6V is present between each speaker lead and ground(drive BTL by TDA73XXXX amp or equiv). Easy way, use capacitor to remove the DC, pass it thru an OP-AMP/Voltage comparator/ADC and then activate/disable you Amplifier remote lead.

Many car have also external amplifier, if you give me the car model/year i can see if there's any possibility of external amplifier.

EDIT: Is the unit the original or aftermarket?? If it's an aftermarket, as previoulsy mention... many chances are that the Power Antenna wire will also send DC while the CD is running... case not you must have 2 of thes blue wire back to this unit...

Tear
- 8th July 2005, 19:48
what is an ADC? I tried googling it and couldnt find anything valid as to what this is.

~Michael

NavMicroSystems
- 8th July 2005, 23:23
what is an ADC? I tried googling it and couldnt find anything valid as to what this is.

~Michael
Analog to Digital Converter

BTW
Are you really willing to use a PIC 16F84 for this simple task?
any 8 pin 12F or even a 10F could do this.

Or even simpler: somethimg like the NE555
(does not even require any programming at all)


This thread is a good example of what you end up with if you don't give sufficient details in the first place.

EDWARD
- 8th July 2005, 23:27
you dude, ADC means Anologue to Digital Comparator or something. it basically will give you a decimal readout of a signal (usually 0 to 255) rather then 1 or 0. it it can be hard to set up beacuse you would likely need to build a transforming circuit.

do you even know what type of signal must be sent out the amp siganl line? is it 5 or 12 volts DC? does it stay at 5-12 volts dc or does it just sent a pulse?

this could be made without a pic. but if you must these are things to consider.

sound to me like all you need is a zener diode and resistor connected between the ac sound signal and a pics input. not sure how much power a deck can produce and not really sure the value or the components, but get one that wont allow more then 5volts and limited current. if the current is higher then extepcted then i would use an isolation relay like the one posted at the top, this will prevent frying the pic. if all you can find is a standard relay that should work too but will be clicking like crazy.


just write a code that is like this:

if pic recives pulse on input line then
turn on amp
endif


the pics input pin will be reciving random pulses as the music plays so youll ne ed to write a workaround like:

if no pulse is recived within 1 minutes then
shut off amp
endif

how do you plan on powering the pic?


google search zener diode, optical isolation relay, rectification

also, using you meter, meaure the ac signal out the deck with the volume all theway up. also measure the amp signal on your car. im not 100% sure but when you meause the amp signal line go from that wire to ground in dc mode. but when measuring the speakers go from speaker LF + to speaker LF - (left front ) in ac mode.

mister_e
- 9th July 2005, 11:30
That's an area i'm really experienced with. I did installation for more than 10 years as now. Still do some times..


do you even know what type of signal must be sent out the amp siganl line? is it 5 or 12 volts DC? does it stay at 5-12 volts dc or does it just sent a pulse?

100% of the aftermarket amplifier need a constant 12 volt to turn them on. Usally called PCon, Remote or Turn-on Lead. The amplifier will stay on as long as you send him a 12volt on the remote terminal.


not sure how much power a deck can produce and not really sure the value or the components, but get one that wont allow more then 5volts and limited current.

Those deck work on 12Volts and never use internal voltage shifter to raise te voltage. So a MAX of 14Volts amplitude will be on the Speaker terminal when the car is running. Simple Voltage divider built with 2 resistor will do the job. Let's say 10K in serie between PIC and Speaker, 5.1k(or a few less) between PIC input and gnd. We can skip the capacitor in serie.