Sensing 24vac signal with a micro - Page 1
Forum section: electronics / beginners

author: Bluestreak66
author_rank: Regular Contributor
timestamp: June 10, 2013, 05:49:43 am
content: What would be a good way to sense a 24vac signal with a micro? I'm trying to use the least amount of components possible and have it isolated. I played around with using optos but would like a clean 3volt signal into the micro. I don't want to use relays. Any ideas?

author: David_AVD
author_rank: Super Contributor
timestamp: June 10, 2013, 06:06:34 am
content: AC goes to opto input via series resistor. Opto emitter to Vss. Opto collector to micro and a pull-up to 3V. Cap across opto output to smooth out the ripple. Use an opto with back to back LEDs for less ripple to deal with.

author: Bluestreak66
author_rank: Regular Contributor
timestamp: June 10, 2013, 06:38:26 am
content: That's the same setup I had. How would I determine the size of the cap to filter the ripple without adding a delay in the signal?

author: David_AVD
author_rank: Super Contributor
timestamp: June 10, 2013, 07:02:52 am
content: It will depend on the pull-up value and ripple frequency. You could simulate it, or just build it and test. Start with 1uf and go from there.

author: TerminalJack505
author_rank: Super Contributor
timestamp: June 10, 2013, 08:01:09 am
content: A simulator is definitely a boon for something like this. You can tweak the parameters to nth degree.

author: David_AVD
author_rank: Super Contributor
timestamp: June 10, 2013, 08:05:37 am
content: The OP asked for isolated, hence my inclusion of the opto.

author: TerminalJack505
author_rank: Super Contributor
timestamp: June 10, 2013, 08:13:05 am
content: Mine's got an opto too. It is just being simulated with an LED. I don't think my simulator has a model for an optocoupler. I also didn't show the MCU-side but that's easy enough.Anyway, I was working on a similar circuit (zero-crossing detector) in the simulator and so modified it. Which is what I posted.

author: David_AVD
author_rank: Super Contributor
timestamp: June 10, 2013, 08:48:48 am
content: Ah, my mistake. I didn't see the opto as such.How you approach the solution depends on whether you want to smooth the AC before or after the opto. I chose after as the currents are smaller so can have a smaller cap.

author: Bluestreak66
author_rank: Regular Contributor
timestamp: June 10, 2013, 11:05:52 pm
content: Thanks for the input it's much appreciated. I like the idea of using the back to back led opto to rectify the ac then smooth with a cap that way there is less components. This is going to be on a small pcb with several relays so fewer components are better. Even though I do think a full rectifier and cap before the opto would result in a faster repose time, I'm not sure there will be enough room on the board as there will be 4 of these circuits. What are you using for a circuit simulater? I've tried a few with not very good results but its probably more to do with lack of experience than the software.

author: TerminalJack505
author_rank: Super Contributor
timestamp: June 10, 2013, 11:11:36 pm
content: That was simulated withTina-TI. Tina-TI is a free version of Tina--a commercial simulator. Texas Instruments licenses it from DesignSoft.

author: Psi
author_rank: Super Contributor
timestamp: June 11, 2013, 01:03:48 am
content: Do you need to measure the voltage of this 24V signal or just detect if its present or not?and does it HAVE to be isolated? or just able to withstand spikes?Thinking of the the lowest component count possible...On micros with clamp diodes intended for this purpose (eg AVR) you can use only a large resistor to an AC source.Then you use the micro to detect if the input pin is toggling from the AC or not.The trade-off for having a component count of 1 is more complicated MCU code to do the freq detection.One of the Atmel appnotes shows 230VAC phase and netural being connected to a micro through 1Meg resistors. The micro can then detect the 50Hz phase of the mains by timing the pins logic changes. 1Meg is high enough no mains voltages spikes can push enough current to damage the IC.You would use less than 1Meg for 24VAC, I would try 100K to start with and if your micro doesnt have clamp diodes that can handle this you can always add them externally then you're component count would just be the resistor and two diodes.With just the 100K resistor... 30mA max port current * 100,000R = ok to 3kV spikes.Or you could raise the component count by 1 by adding a TVS diode, then it would be able to withstand pretty much anything.

author: Bluestreak66
author_rank: Regular Contributor
timestamp: June 11, 2013, 01:14:41 am
content: I need it to be isolated. I could just do that with an opto but as you said more code would be necessary.

author: Psi
author_rank: Super Contributor
timestamp: June 11, 2013, 01:16:22 am
content: ok,Is the 24VAC coming in referenced to MCU ground or floating?If you replace the regular opto with a logic opto its just logic level in logic level out.So you don't need a led resistor or a transistor pullup resistor.

author: Bluestreak66
author_rank: Regular Contributor
timestamp: June 11, 2013, 01:32:08 am
content: The 3v supply will be generated from a switching regulator off the 24vac supply so it will most likely be all referenced to ground. There will be a constant 24vac and 4 24vac signals that will be interfacing with HVAC equipment. What I might do is connect a dual led opto though a resistor to the 24vac signal then connect the other side to a micro with a pull up resistor and a cap. I'll have a few boards made and test it with different value caps. If I don't like the result I can just leave out the cap when I solder the board and add some extra code. Unless there is a better soloution

author: David_AVD
author_rank: Super Contributor
timestamp: June 11, 2013, 01:35:37 am
content: In one recent AC sense application, I fed the opto output into an interrupt pin on the PIC. It all depends on how you want to implement the code.

author: Bluestreak66
author_rank: Regular Contributor
timestamp: June 11, 2013, 01:52:28 am
content: Id like to make the code as simple as possible, but for now i'm just trying to get the hardware finished so I can get some prototype boards made and write the code. I tried the Tina-ti circuit simulator but there isn't and opto which makes it hard to simulate.

author: TerminalJack505
author_rank: Super Contributor
timestamp: June 11, 2013, 02:33:13 am
content: You might try LTspice. It has optocouplers.

author: westfw
author_rank: Super Contributor
timestamp: June 11, 2013, 06:11:43 am
content: A Relay? It sounds like you're looking for a higher-speed response, but if you're trying to convert a classic door chime controller to modern electronics and need to interface that 24vac doorbell button to a 200MHz ARM chip, a simple electromechanical relay might be the easiest solution.

author: David_AVD
author_rank: Super Contributor
timestamp: June 11, 2013, 06:15:04 am
content: I don't think the OP has quantified what a "fast response time" is yet. If a couple of hundred milliseconds is ok, the simple resistor + opto + capacitor will be fine. Much faster than that and you're back to using the unfiltered pulses to trigger an interrupt.

author: Bluestreak66
author_rank: Regular Contributor
timestamp: June 11, 2013, 10:32:20 pm
content: I used LTspice and it looks like and opto with a filter cap will work. Would there be any difference if I used the internal pull-up on the micro vs a resistor? The internal pull-up is 20k and with a 1uf cap that looks to be what I would need.

author: David_AVD
author_rank: Super Contributor
timestamp: June 11, 2013, 11:30:53 pm
content: I didn't assume there was a pull-up available. The internal pull-up should be fine, though some are specified as weak current sources so you may need to fiddle with the capacitor value.