Author Topic: Sensing 24vac signal with a micro  (Read 7356 times)

0 Members and 1 Guest are viewing this topic.

Offline Bluestreak66Topic starter

  • Regular Contributor
  • *
  • Posts: 51
Sensing 24vac signal with a micro
« on: June 10, 2013, 05:49:43 am »
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?
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Sensing 24vac signal with a micro
« Reply #1 on: June 10, 2013, 06:06:34 am »
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.
 

Offline Bluestreak66Topic starter

  • Regular Contributor
  • *
  • Posts: 51
Re: Sensing 24vac signal with a micro
« Reply #2 on: June 10, 2013, 06:38:26 am »
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?
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Sensing 24vac signal with a micro
« Reply #3 on: June 10, 2013, 07:02:52 am »
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.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: Sensing 24vac signal with a micro
« Reply #4 on: June 10, 2013, 08:01:09 am »
A simulator is definitely a boon for something like this.  You can tweak the parameters to nth degree.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Sensing 24vac signal with a micro
« Reply #5 on: June 10, 2013, 08:05:37 am »
The OP asked for isolated, hence my inclusion of the opto.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: Sensing 24vac signal with a micro
« Reply #6 on: June 10, 2013, 08:13:05 am »
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.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Sensing 24vac signal with a micro
« Reply #7 on: June 10, 2013, 08:48:48 am »
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.
 

Offline Bluestreak66Topic starter

  • Regular Contributor
  • *
  • Posts: 51
Re: Sensing 24vac signal with a micro
« Reply #8 on: June 10, 2013, 11:05:52 pm »
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.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: Sensing 24vac signal with a micro
« Reply #9 on: June 10, 2013, 11:11:36 pm »
That was simulated with Tina-TI.  Tina-TI is a free version of Tina--a commercial simulator.  Texas Instruments licenses it from DesignSoft.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9939
  • Country: nz
Re: Sensing 24vac signal with a micro
« Reply #10 on: June 11, 2013, 01:03:48 am »
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.

« Last Edit: June 11, 2013, 01:19:08 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Bluestreak66Topic starter

  • Regular Contributor
  • *
  • Posts: 51
Re: Sensing 24vac signal with a micro
« Reply #11 on: June 11, 2013, 01:14:41 am »
I need it to be isolated. I could just do that with an opto but as you said more code would be necessary.
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9939
  • Country: nz
Re: Sensing 24vac signal with a micro
« Reply #12 on: June 11, 2013, 01:16:22 am »
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.
« Last Edit: June 11, 2013, 01:21:28 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Bluestreak66Topic starter

  • Regular Contributor
  • *
  • Posts: 51
Re: Sensing 24vac signal with a micro
« Reply #13 on: June 11, 2013, 01:32:08 am »
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
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Sensing 24vac signal with a micro
« Reply #14 on: June 11, 2013, 01:35:37 am »
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.
 

Offline Bluestreak66Topic starter

  • Regular Contributor
  • *
  • Posts: 51
Re: Sensing 24vac signal with a micro
« Reply #15 on: June 11, 2013, 01:52:28 am »
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.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1310
  • Country: 00
Re: Sensing 24vac signal with a micro
« Reply #16 on: June 11, 2013, 02:33:13 am »
You might try LTspice.  It has optocouplers.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Sensing 24vac signal with a micro
« Reply #17 on: June 11, 2013, 06:11:43 am »
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.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Sensing 24vac signal with a micro
« Reply #18 on: June 11, 2013, 06:15:04 am »
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.
 

Offline Bluestreak66Topic starter

  • Regular Contributor
  • *
  • Posts: 51
Re: Sensing 24vac signal with a micro
« Reply #19 on: June 11, 2013, 10:32:20 pm »
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.
 

Offline David_AVD

  • Super Contributor
  • ***
  • Posts: 2806
  • Country: au
Re: Sensing 24vac signal with a micro
« Reply #20 on: June 11, 2013, 11:30:53 pm »
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf