Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Schmitt Trigger for 'counting' the time

Status
Not open for further replies.

Odysseas

Member
Hi there,

I want to count the time with a µController (counting the 50 Hz power line freq). For this, I need to turn the sine-wave into a square signal with a schmitt trigger.

Now I have no idea what values to use for the hysteresis resistors. I'd have guessed the pre-resistor to be, say 1k, and the feedback-loop resistor 10 Ohms??? Would that work? And btw, can I use the LM 358 (using only one channel), it's the cheapest Op-Amp I've found. I want to use the 6 Volt out from a simple transformer. Will I need a galvanic isolation between the input signal for the Op-Amp and it's power supply??

Sorry for being so unexperienced with Schmitt Triggers...

Many thanx
 
why complicate things, use an npn transistor and a couple of resistors before the capacitive filter in your power supply, and a pull up resistor to your uC supply rail.
 
Why complicate things with transistors, caps and some resistors? here is a microchip app note that uses just a 5M resistor directly into a PIC pin. https://ww1.microchip.com/downloads/en/AppNotes/00521c.pdf
it relies on the internal clamping diodes and low current. If you are using a uC without internal clamping diodes, you can add them externally.

Note, none of the above solutions provide isolation. I'd use an AC opto isolator (+ 2 resistors) if that's important to you (and it should be).
 
If you are using a PIC microcontroller, usually at least one port incorporates a schmitt trigger. (eg. RA,4 on a 16f84). (Check the data sheet for ports marked ST)
You need to connect via about 22-33K series resistor to the output of your low voltage (eg. 9v ac supply (before the bridge rectifier) and use a 5v zener and 0.1uf capacitor across the port pin to protect the controller from any voltage above +5v and suppress supply noise.
 
philba said:
Note, none of the above solutions provide isolation. I'd use an AC opto isolator (+ 2 resistors) if that's important to you (and it should be).
I wouldn't worry, 32uA is too low to shock you, even if you're running it from a transformer I bet the coupling capacitance will allow this small current to flow.
 
Hero999 said:
I wouldn't worry, 32uA is too low to shock you, even if you're running it from a transformer I bet the coupling capacitance will allow this small current to flow.

yes but you still are bringing 120/240 VAC onto a circuit board. I'm not at all worried about the circuit when it works properly. A surge can do a number on a cap/resistor. At least with an opto, you've got several KV of isolation at a minimum. a transformer provides better isolation. probabilities of failure of an opto or transformer are pretty low. UL seems to agree...
 
I'll be using an Atmega16 - there is some mention of a Schmitt Trigger in the datasheet, but it doesn't say which pin to use. Can anyone help me with this??
 
look at pg 50 and 51 of the atmega16(L) datasheet (doc2466). you will see 2 schematic diagrams that answer your questions.
 
tunedwolf said:
why complicate things, use an npn transistor and a couple of resistors before the capacitive filter in your power supply, and a pull up resistor to your uC supply rail.

How does this work? Please explain.
 
Now here's another idea, but I'm not sure if that would work. I think this could probably create a short circuit along Ground, frying the bridge rectifier, but I'm not sure of that. Please verify this schematic or declare it as rubbish ;)
 

Attachments

  • schem.gif
    schem.gif
    31.3 KB · Views: 264
Here's what you are proposing. see anything odd about it?
 

Attachments

  • bridgeshort.gif
    bridgeshort.gif
    2.6 KB · Views: 175
Would placing a galvanic isolation (1:1 transformer) before the resistor and the zener-diode help? It should work then, shouldn't it?
 
The grounds at either side of the rectifier shouldn't be connected, it will short circuit two of the rectifiers!
 
Yes, I know (at least, I do now). But that's what I mean: If I put a galvanic isolation between those two - the problem should be solved, rite?
 
since you want to use a bridge (and thus no common ground), use an opto isolator and drive the led from the AC side. The H11AA814 https://www.fairchildsemi.com/ds/H1/H11AA814A.pdf is exactly what you would need - $.49 from mouser. Use a dropping resistor to limit the current to the dual LEDs. the photo transistor collector should be pulled to +V via a 10K resistor and the emitter connected to ground. Take the output from the collector as input to the ATMega. You will see pulses at 120 hz.

the top test circuit on page 6 of the datasheet shows the basic hookup. edit: to be clear, connect the LEDs leads to the 2 legs of the transformer output, though the dropping resistor. resistor value is calculated just like you would for a regular LED
 
Last edited:
Well, of course, my favourite surplus doesn't do that one. I've looked out for any other AC-capable optocoupler, successless ;)

However, if I'd use a conventional optocoupler, I should still receive a clean 50 Hz signal (I live in a country with 50 Hz line frequency), which I could be content with. How about this one: https://pdf1.alldatasheet.com/datasheet-pdf/view/2846/MOTOROLA/4N25.html? Would that work??
 
yeah, that could work. note that the 4n25 has a Vr max of 3V - I'd use a diode in series with the LED as well as the dropping resistor. easy enough to try.
 
Alrite, this is what I've developed. Please verify that this works or does not. Is it possible, that I need to swap collector and the emitter?
 

Attachments

  • schem2.gif
    schem2.gif
    18.7 KB · Views: 171
nope, that won't do it on several fronts.

first, your photo transistor is wired wrong. emitter to gnd, collector connected to +V via a 10K resistor (you can play with this value for more sensitivity). input to the avr is from the collector. It acts like a switch. when it's off (darkness), the collector to gnd voltage is close to +V. When its on (light), the collector to gnd voltage is very low because the transistor is conducting. it's just like a pulled high switch, in that regard.

secondly, your led resistor seems a bit low. your 6VAC is going to peak at 1.414*6 or 8.5V. The 14001 will take a .7 forward drop and the LED has a max Vf of 1.4. That leaves 6.4V. I would target an If of 10 mA so that means a 640 ohm resistor. next standard size up is 680. If you want 20 mA If, use a 330 resistor. While the led can handle higher, I wouldn't push it.
 
Last edited:
now, second try. I don't want to go too high with the preresistor, because the LED is specified to survive up to 60 mA continous. 390 Ohms should do, rite? Btw, what am I supposed to do with this base? Do I actually need that at all in an optotransistor?
 

Attachments

  • schem3.gif
    schem3.gif
    18.8 KB · Views: 147
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top