#189

Ғылым және технология

A safe experiment in mains zero crossing with an Arduino using interrupts.
JLCPCB Only $2 for PCB Prototype any colour jlcpcb.com/
More information (sketch, circuit diagram etc) in my GitHub:
github.com/RalphBacon/189-Zer...
00:00 Welcome Back!
05:45 Exploded Capacitor
22:26 Smart Phone Charger Mini-Update
As part of my quest to replace the potentially dangerous electronics in a recently acquired fan speed controller, the first step is for the Arduino to know exactly when the mains AC waveform is at the zero point in its cycle.
Here we can see how easy it is to configure the Arduino with just a few lines of code to detect this using a simple interrupt routine.
We also have a 2 minute look at the progress on my Smart Phone Charger, as the PCB from JCLPCB has arrived and is looking good!
List of all my videos
(Special thanks to Michael Kurt Vogel for compiling this)
bit.ly/KZreadVideoList-RalphB...
More information (sketch, circuit diagram etc) in my GitHub:
github.com/RalphBacon/189-Zer...
In case you missed the links to these products:
Geekcreit® AC 60-500V 0-100A D18 Square LED Digital Dual Display Voltmeter Ammeter Voltage Gauge Current Meter
www.banggood.com/Geekcreit-AC...
Geekcreit® Large Size Rainbow Color Digital Tube DS3231 Clock DIY Kit
www.banggood.com/Geekcreit-La...
tal-Tube-DS3231-Clock-DIY-Kit-p-1323917.html?p=FQ040729393382015118&
SMD Component Soldering Practice Board from $2
www.banggood.com/DIY-SMD-Comp...
www.banggood.com/DIY-SMD-Rota...
THIS IS THE PRACTICE KIT I USED, WITH QUAD FLAT PACK CHIPS, only $3.15
www.banggood.com/DIY-Electron...
Desoldering braid 1.5mm 2mm 2.5mm 3mm 3.5mm Width 1.5M Length, $2.56 each
Essential for removing bridges and solder from the PCB
www.banggood.com/1_5mm-2mm-2_...
DANIU Heavy Duty Soldering Solder Iron Tip Cleaner $6.80 (What I use)
www.banggood.com/DANIU-Heavy-...
If you like this video please give it a thumbs up, share it and if you're not already subscribed please consider doing so and joining me on my Arduinite journey
More information (sketch, circuit diagram etc) in my GitHub:
github.com/RalphBacon/189-Zer...
My channel, GitHub and blog are here:
------------------------------------------------------------------
/ ralphbacon
ralphbacon.blog
github.com/RalphBacon
------------------------------------------------------------------

Пікірлер: 222

  • @adabill295
    @adabill2954 жыл бұрын

    Great video. You really bring it down to a level that even I can understand. Your timing is good, I just received my HC-05. I ordered it when you started your charger video series. Now I know what it means when they say "Slow Boat From China"!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Glad it was helpful! Don't get me started on slow delivery! Seems like the old days before planes were invented. Oh, I see, they are all parked up, sitting on runways at the moment. That would explain it.

  • @damianbutterworth2434
    @damianbutterworth24344 ай бұрын

    When I was a kid in the 1980`s I made some disco lights with a tape recorder, 555 timer, 4017 decade counter and 10 triacs. Don`t know how I did it without the internet lol. Now 50 years later I want to do the same. :)

  • @RalphBacon

    @RalphBacon

    4 ай бұрын

    I, too, made some disco lights when I was a teenager (yes, we had electricity and even running water back then) but I'm amazed I survived all that 240-volt stuff. No isolation in those days, direct connections to triacs. 😲

  • @patazertyui
    @patazertyui4 жыл бұрын

    I find your two projects very interesting, zero-crossing detector and smart charger!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Great stuff! Keep tuned for future updates.

  • @stevetobias4890
    @stevetobias48904 жыл бұрын

    Great explanation mate, thanks for the video. I was like WTF when I seen you attaching a transformer to an Arduino but it all makes perfect sense and has some merit. Looking forward to your next video

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Remember the rectified AC went through two resistors (potential divider) before hitting the Arduino, see the circuit diagram in my GitHub for full info.

  • @tomgeorge3726
    @tomgeorge37264 жыл бұрын

    Great instructional video for beginners about interrupts Ralph. I have noted the URL for any noobs on the Arduino Forum that is having problems with such functions..👍👍👍👌😊

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Glad it was helpful! And thanks for helping others in the forum!

  • @dl8cy
    @dl8cy4 жыл бұрын

    Nice to see that your eye got better! Nice vid by the way

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Hey, thanks! My eye is improving, we will see how it goes in a week's time at the post op checkup!

  • @raffyturc
    @raffyturc4 жыл бұрын

    we all make mistakes from time to time 😄 really liking your youtube setup! keep it up Ralph! stay safe. -Ralph

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Thanks! Will do!

  • @andymouse
    @andymouse4 жыл бұрын

    Hi Ralph, interesting stuff indeed, this is a good proof of concept I look forward to phase 2 and capturing the exact zero point, as an interrupt triggering on a falling edge is probably gonna be a bit early but i'm sure you've figured that out.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Well, 2-3 volts too early, probably, which we can correct in software (ie delay a bit more). I'll get the 'scope out and get it spot on!

  • @jerryeiting5367
    @jerryeiting53674 жыл бұрын

    I've been wanting to try the interrupt method as a means for providing a time base for a clock using the AC mains for the time base. Thanks for the inspiration!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Did it work, Jerry? This should be very accurate, it's how mains-operatied bedside clocks are often synchronised to keep good time.

  • @jerryeiting5367

    @jerryeiting5367

    4 жыл бұрын

    @@RalphBacon I haven't tried it yet, but have plans to do so. Too many projects... I agree about the accuracy, My 30 year old AC powered clock radio is very accurate!

  • @Marzec309
    @Marzec3094 жыл бұрын

    I've build similar projects before. One thing to keep in mind is forward voltage drop of the LED in the optocoupler. This can cause a timing issue when trying to run near 100 percent. The opto will switch off before the zero point and back on after the zero point happened. A simple solution is to only allow a maximum on percentage for the trac, say 90-95 percent. Otherwise you'll need to have a very critical time delay required from the trigger point to the actual zero cross. Trigger the trac slightly to soon and you'll miss a whole half cycle.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Indeed, timing will be critical but I hope software will allow me to adjust this. We shall see!

  • @wires4auto
    @wires4auto4 жыл бұрын

    🙈 the boom from a cap going bang 💥 makes you jump out your skin. Has happened twice to me. I liked the capacitor video, basic and straight to the point. 👍 I love all your puns and digs 😆 our friends from across the pond

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    It certainly made me jump, Gordon! I'm sure my viewers from across the pond do not take offense at any digs I might throw their way. All done in the best possible taste. (Now _there's_ a reference not many will remember).

  • @wires4auto

    @wires4auto

    4 жыл бұрын

    @@RalphBacon I am sure they won't take offense.

  • @0x8badbeef
    @0x8badbeef10 ай бұрын

    4:13 Thanks. This is the most important information I've heard in a long time. It explains all my USB problems. It does seem like they started when I replaced my USB 2.0 hubs with 3.0. My old 2.0's died so I replaced them with the latest and greatest.

  • @RalphBacon

    @RalphBacon

    10 ай бұрын

    Glad it helped!

  • @0x8badbeef

    @0x8badbeef

    10 ай бұрын

    @@RalphBacon ever since I replaced my 3.0 with 2.0 the other problems went away as well. I think 3.0 causes Windows to produce spurious interrupts.

  • @Taran72
    @Taran724 жыл бұрын

    Loved this tutorial on interrupts. It was a very nice example. The project is very interesting. I also had no idea about the volatile memory thing....good to know. Will be useful for my future projects. Bye from your ex colony where Ac is at 60Hz!! LOL LOL LOL.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Glad you enjoyed it! Ah yes, it's an EX colony isn't it, now. I keep forgetting that. You'll be wanting your independence next. Lol.

  • @Taran72

    @Taran72

    4 жыл бұрын

    @@RalphBacon LOL. Keep up the good work. Your videos are of great help. :)

  • @faidularcs
    @faidularcs4 жыл бұрын

    Thank you very much for this episode 💖💞

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    You're most welcome!

  • @obiwanjacobi
    @obiwanjacobi4 жыл бұрын

    I would be interested to see you toggle a pin on every interrupt and see how the edges line up with the actual zero-crossing. Because you're using digital voltage levels I suspect they may be off. Thanks for the video.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, indeed, they will most certainly be off, a bit, but we can correct that in the software by including more delay before switching on the TRIAC. I'll cover this in a future video, Marc, it will be useful for everyone to see. Thanks for raising this.

  • @andycrask3531
    @andycrask35314 жыл бұрын

    Ooh I like where this is going, I will need to wait for the next upload but I'm sure I can use this to reverse engineer a piece of equipment I have at work, It uses a triac to vary a 110vac supply to vary the rate of a vibrator coil, I need an Arduino to detect this and the map it to a pwm output. Good reason to get my first jlc PCBs done too Keep it up Ralph

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    If this inspires you, Andy then that is my work done here. Great to hear from you.

  • @andycrask3531

    @andycrask3531

    4 жыл бұрын

    @@RalphBacon it does you explain stuff in depth but without babbling on. I find it very helpful. I may need to pick your brains with my little project is there a way I can contact you? Thanks Andy

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    My email is in the About tab of my channel.

  • @naveengupta5242
    @naveengupta52423 жыл бұрын

    most amazing channel on YT

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Glad you think so!

  • @r1273m
    @r1273m4 жыл бұрын

    I have always avoided level triggered interrupts, use edge triggering whenever possible. In fact I cannot think of a reason to use level triggering. Your on screen comment "I suspect the pin is kept LOW too long by the signal" is quite correct. This ISR is very short, if you use level triggering, by the time you get back to the main programme the level will still be within the LOW parameter so another interrupt is generated. Using an edge triggered interrupt avoids this problem. No matter how quickly your ISR is serviced, another interrupt request will not be generated until the next falling edge, i.e. the next cycle. Bob

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, indeed, Bob. The pin is LOW once the voltage drops to about 2-3V and stays low until it goes above 3V again on the next (half) cycle. I can't work that out in my head but it is probably a millisecond or two which to the interrupt hardware is an eternity and just keeps triggering! Others have commented on using level triggering, usually with the word "Why?".

  • @TheSchneidItworld
    @TheSchneidItworld4 жыл бұрын

    wooow, that's gonna be useful, thanks!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Glad you think so!

  • @kamalhussain2977
    @kamalhussain29774 жыл бұрын

    Really love your work. How can I monitor the capacity of my 14.6v valence batteries ?Shud I use amp connector to logic level converter to rs485 to 4module relay to arduino? If so , how to connect?

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    I'm glad you like what I do, but voltage monitoring is not applicable to this video, is it, Kamal? If you watch video #160 (all about voltage monitoring) and if you still have a question please ask it there! Hint: read up on potential dividers!

  • @IvoBallie
    @IvoBallie4 жыл бұрын

    Hi Ralph Most domestic fan motors are split phase induction motors or shaded pole motors. While a “lamp dimmer” controller allows a certain amount of speed control, it is not linear and the torque the motor develops at low “speed” settings is sometimes too low to kick start the fan. A simple plan to overcome this, is to boost the speed to full on when initially starting for a few seconds and then revert to the set speed. Obviously with a little Arduino programming. The above motors are normally designed to run at a fixed speed determined by the number of poles and the mains frequency. They are best speed controlled with VFD controller, but these are horrifically expensive and not suited to the average hobbyist. Basically, for lowering the speed, the frequency and the voltage is reduced and vice versa to speed up. A lot of domestic pedestal and ceiling fans have a simple 3 speed control. This is done with a series connected capacitor of different values for the speed. Thanks for reading my ramblings Regards Ivo.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Indeed, Ivo, it is a complicated subject. My ceiling fan has 3 different tappings in the windings to give me 3 speed settings. Not something you can retrofit! But my workshop fan also stalls when I switch it on at low speed (the speed at which was last running quite comfortably) so I had thought about storing the last good speed in EEPROM, turning the fan on at a higher speed (not necessarily full speed) and then moving to the previously stored speed. Luckily, once the hardware is done, we can just about anything in software. Stay tuned for this project's progress over the coming weeks! Thanks for your post, most interesting.

  • @oleeide9763
    @oleeide97634 жыл бұрын

    Excellent video, nicely explained, as always from you. Quick suggestion, what if you use an ESP8266 in some form, then you can easily control your fan from remote via a phone app or easily connect it to your home automation system, shure you can do some remote control via bluetooth, but with wifi you have so much more possibilities :-).

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Great suggestion! It did occur to me (or just buy a SonOff dimmer switch) but I don't mind stretching out to adjust the fan speed - and it's all switched off by the kill switch when I leave the workshop anyway.

  • @vonries
    @vonries4 жыл бұрын

    Thanks Ralph

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    You're most welcome, Steven!

  • @electronicswithzee2565
    @electronicswithzee25654 жыл бұрын

    Hi Ralph. How difficult would it be to detect 2 separate AC input's zero crossing points to then be used to synchronize the one to the other, which then can be used to activate an automatic transfer switch?

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    You have two interrupts on an Arduino (pins 2, 3) so you could easily detect two different signals' zero point crossing. What you then do I'm not sure as I don't know what you mean by "synchronising" them. If the signals are at different frequencies and you are just waiting for them both to be at zero before you do something that would be feasible.

  • @Enigma758
    @Enigma758 Жыл бұрын

    I once used a single diode (half wave AC rectification) as input to an optocoupler. That gave me a square wave pulse for each cycle.

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Yes, that would work. The half sine wave could possibly be made squarer with the use of a Schmitt trigger but if it works as-is then it works!

  • @Enigma758

    @Enigma758

    Жыл бұрын

    @@RalphBacon Point taken, but it's only triggering a counter IC for a clock, so as long as it transitions low to high, it's fine. I don't think it has to be a perfect square wave for this application. In fact, I'd say that even if it was a sine wave, the counter would still count correctly as transition, not shape matters in this case.

  • @johnconrad5487
    @johnconrad54874 жыл бұрын

    Thanks for sharing. will you please put in a block diagram or maybe a flow diagram so we can follow the time line of what is happening. Thanks

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    I'll add in extra details when we come to driving a Triac (with a suitable, mains-isolated, low AC voltage) from that Arduino,John.

  • @grahamwise5719
    @grahamwise57194 жыл бұрын

    If an interrupt is repeated to many times your LOW setting, a trick is the test the time has pasted since the interrupt was last called. It is slow to real the time values and do a compare but not for your timescales. Since you have the signals in the Arduino then consider not a triac and a single delay but a high voltage MOSFET inside a bridge regulator pulse on/off several time in the time period to give a smoother control. Perhaps above hearing frequencies. Thanks for the video as always.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    I've used the time-test trick on my rotary encoder projects, Graham, as it would not work reliably using FALLING, would you believe? Not what I would consider ideal though (although it works perfectly). If I were to use MOSFETs then I would change this dimmer to be trailing edge to give smoother control and no exploding bulbs on switch on. But for induction motors (eg my fan) it is not ideal due to back-EMF.

  • @stephenwhite506
    @stephenwhite5064 жыл бұрын

    You can use zero crossing detection to detect the peeks if you use it on a differentiated signal created by feeding the original signal into a appropriately configured op amp. You can also use a comparator to detect the zero crossing if you don't want to use a microcontroller. These techniques were used in disk drives for reading floppy disks.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Hang on, Stephen, you say "if you _don't_ want to use a microcontroller". I'm sorry I just don't understand that sentence at all. "Don't want to?" You do know this channel is all about Arduinos and related devices? Ha ha! But seriously, I'm sure there are other ways to detect zero crossing but I definitely wanted to use a µController in this project.

  • @stephenwhite506

    @stephenwhite506

    4 жыл бұрын

    @@RalphBacon Yeah it is amazing that some microcontrollers are so cheap now that they can replace simple chips like comparators and 555 timers. Love the channel. Keep up the good work!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    With your last comment in mind, watch this week's coming video, #190!

  • @chrisarmstrong8198
    @chrisarmstrong81984 жыл бұрын

    Digitally-controlled DC variable-speed drives, which must also detect mains zero crossings in order to accurately fire their thyristors, have a lot more filtering of the signal than your simple detector. They typically have a 2ms RC filter on the digital input and use a digital phase-locked loop technique to accurately predict the zero crossings in the presence of mains harmonic distortion and noise. So, it would probably be a good idea to, at least, program some sort of sanity check on your detected zero crossing before using it.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    I'm sure you are correct, Chris, but this was a proof-of-concept demo not a finished design. As it stands, the "zero" crossing is detected too early (as soon as the AC cycle drops below the OFF level at about 3V not zero volts). We would have to correct that in code. Keep tuned for further videos that demo my fan speed controller!

  • @andyfraser5876
    @andyfraser58764 жыл бұрын

    In the diagram, there was a resistor missing in the collector of the opto-isolator transistor, otherwise the transistor shorts the supply and will fail.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, that was already pointed out to me! It was a virtual resistor, in my head. Which I occasionally do not screw on correctly.

  • @robinrixon5241
    @robinrixon52414 жыл бұрын

    Another great video! But why did you put a resistor on the live AND neutral sides of the optocoupler? I understand the need to limit current through the LED portion of the optocoupler, which can be achieved with one resistor - and I understand that there are two LEDs inside that version, allowing you to sense +/- voltages - but they're wired together, so why two resistors?

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Spreading the load, Robin. Those resistors are dropping a lot and need to be 1/2 or even 1W types so by splitting the load it should ensure they don't fail over time. They must also be capable of mains voltages (SMD resistors cannot do this, of course). If there is a neater way of doing it I'd choose that; for example if the non-mains part of the circuit was running of a low voltage transformer (as per the demo) to power the Arduino etc, we could use that to trigger the interrupt pin directly from the bridge rectifier again. We shall see.

  • @robinrixon5241

    @robinrixon5241

    4 жыл бұрын

    @@RalphBacon ​Ah - thanks for the clarification! I'm rather annoyed at myself that I was so busy wondering why the resistors were straddling the opto that power requirements never entered my head - having been so used to working with small voltage drops (5v/12v systems), power requirements are always low. However, assuming 240v supply, 1.5v LED voltage and your 2x 47K = 94K resistors, using the equation (240-1.5)/94000 we can see this provides 2.5mA to light the optoisolator - but sinks 0.6W to do it. You weren't wrong about needing 1W resistors! I'm wondering if a hall effect sensor might have been used to detect phase at lower power cost, in a similar way to the inductive probes on a clamp meter, measuring without even breaking the supply wire.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Maybe, but the "standard" is to use LEDs or direct connection (shock! literally).

  • @nguyenthuy9824
    @nguyenthuy98243 жыл бұрын

    Hi. I'm going to try a project wireless (AC dimmer) adjusting potentiometer to AC lamp. Components NRF24, potentiometer, arduino, BT136, MOC3021, 4N25. Have you ever done this yet? Honestty, I want to do this. Can you share/advise some? Thanks

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    I haven't done that (yet) but I do have all the parts to do in a box. So I might revisit this in due course. If you succeed, let me know!

  • @oilybrakes
    @oilybrakes4 жыл бұрын

    Correct me if I am wrong, but I belive that there is a misunderstanding involved, regarding the voltage on the blown capacitor. 15V•1.4=21V is what is said in the video ( 6:06 ). But that is not what the capacitor had to deal with, right? The capacitor dealt with peaks of our full wave rectified 15V. Not more. Considering the drops on the diodes, even less. At least, if what is written on the transformer (15V output) is true. Where does the factor of 1.4 come from? Well...if I'd want to heat up a resistor when using DC, by the same amount as I'd heat it up when using the 15V AC, I would need 15V / 1.4 ≈ 11V DC. But that has nothing to do with our situation, were the C ended up being blown up. It did not blow up because it could not decipate the heat. It blew up from overvoltage.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    The 15V from the transformer is AC, as you have stated, Anton. This is the _equivalent_ DC voltage when heating an element. So 15V AC and 15V DC heat an element to the same level. This is called the RMS value of the AC voltage; the peak-to-peak AC voltage is 1.414 times that amount. That's why when smoothed by a capacitor we get to see that. In this case, about 21.5V (allowing for the voltage drop across the diodes, which you also mention). The capacitor failed (rather spectacularly, it must be said) because it was not rated for anywhere near that voltage (just 6V). Kaboom. So you were on right lines but the 15V AC is the RMS value not the peak voltage. In the UK, our 240V AC has a peak-to-peak voltage value of about 340V (240 x 1.414). Quite a difference. I hope this clears this up.

  • @gwav1a
    @gwav1a3 жыл бұрын

    Have problems with using opto couplers for accurate zero point crossing-- the opto coupler needs the voltage high enough to drive about 10mA through it and this voltage is largely a function of the total resistance in series with the diodes. This won't be at the zero crossing. It's good for measuring frequency but not for applications say involving power factor measurement whereby one needs to generate pulses for the entire positive half of the waveforms-- current and voltage and further process them.

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    It won't be at _exactly_ the zero crossing point, correct, neither is mine, but the time difference is a known quantity so it's easy to compensate in software for that.

  • @conradsinsua7415
    @conradsinsua74154 жыл бұрын

    how would you go about doing a zero crossing detector on a Variable reluctor sensor(crank angle sensor or abs sensor) is ti possible to just copy this method?

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    If you are talking about a physical crank (eg a cog, or wheel as found in a motor or other machine) you could use a magnet secured onto the device and detected with a hall-effect sensor. If you are talking about something else then you will have to explain further, I'm afraid, Conrad.

  • @conradsinsua7415

    @conradsinsua7415

    4 жыл бұрын

    @@RalphBaconthe signal is a sine wave and has huge difference in amplitude depending on speed,and very noisy,I'm just trying to find a way of converting the signal to digital...they hv chips for this already though (max9926)

  • @misterkaye7796
    @misterkaye77962 жыл бұрын

    Hello, I would like to shed some light (pun intended), on the 60Hz vs 50Hz. 60Hz allows for synchronous motors put in clocks and timers to maintain perfect time. 50Hz benefits the poor sap who touches it, as it doesn't phase (stop) the heart like 60Hz does. However, running mains at 220V or 240V kinda offsets that safety. Hope this helps. Sorry, but puns are part of my sharing process. Cheers from (North) America.

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    As they say, Sharing is Caring. And boy, you really do care! 😁

  • @Bob_Burton
    @Bob_Burton4 жыл бұрын

    15:14 delay() would not work in an ISR anyway because it depends on interrupts being enabled, as does Serial printing, and they are automatically disabled when the ISR is being executed 18:29 "there is no more code" What about Arduino_Zero_Crossing_Detector.h that you have #included in your sketch ?

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Ah, yes, the header file is an automatically generated header file. You can find it in my GitHub as part of the sketch. Doesn't contain much this time. Regarding using a delay() within an ISR (not that I ever would) it can still work if it uses microseconds. And micros() updates. It always reads the hardware timer register. So delayMicroseconds() might work. But really you have to ask yourself what it is you are trying to achieve using a delay there! More reading (2nd answer on this thread): arduino.stackexchange.com/questions/22212/using-millis-and-micros-inside-an-interrupt-routine Best approach is never to use a delay within an ISR. If necessary exist and allow the program to re-enter the routine until conditions are right for you. I do that to prevent switch bounce in rotary encoders.

  • @dazh1722
    @dazh1722 Жыл бұрын

    Hi Ralph. Did you get around to finishing your fan controller? Brilliant channel by the way. 👍

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    Thanks, Daz. Now, I'm just trying to work out what you mean by "fan controller". If you mean, did I get it all working with a triac, the answer is no, but I did get it working very nicely with a Variac and has been running like that ever since, controlled (via IR) from my Smart Heater Controller (or manually from the IR remote control that came with it).

  • @dazh1722

    @dazh1722

    Жыл бұрын

    @Ralph S Bacon Hi Ralph, Thanks for the reply. Yes, the arduino controlled triac you mentioned in the video. I was curious to how you were going to accurately delay the firing of the triac after receiving the zero crossing signal?

  • @RalphBacon

    @RalphBacon

    Жыл бұрын

    OK, well, as I said I eventually didn't do it that way. But to accurately trigger the triac you "just" detect the incoming AC, and as it _approaches_ zero (trial and error) you turn on the triac so it actually turns on at zero (on the crossover). This can all be tested with a very low voltage transformer supply (eg 9v, certainly not mains) and put the output & input waveforms on a 'scope to get it spot on. Just to clarify, as the incoming waveform hits, say, 2v, fire the triac, and by the time it actually fires, the voltage will be as close to zero as makes no difference.

  • @dazh1722

    @dazh1722

    Жыл бұрын

    @Ralph S Bacon Thanks Ralph, that's great! Looking forward to your next video. All the best.👍

  • @davidtanner1419
    @davidtanner14194 жыл бұрын

    Perhaps, if you shielded your jumper wires from the transformer (or even just twisted them), you would have much less noise?

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Possibly, David. But given the voltage was 15V the noise level was, quite frankly, excessive! Some have suggested interference from fluorescent lights too. When I get it out again I will first check all these things that have been suggested - and thanks for your suggestion.

  • @Graham1904
    @Graham19044 жыл бұрын

    Can't join the collector to Vcc and the emitter to ground. Magic smoke will appear......

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, many have mentioned that. I just did that to see how many would spot it. No, really.

  • @MrEdwardhartmann
    @MrEdwardhartmann4 жыл бұрын

    Nice job of showing how the interrupts work. And I have never seen where the "zero level interrupt" had any use since according to the documentation, it continues to interrupt as long as the line stays at zero. And by zero, they mean a digital zero - not zero volts. That means the from the time that the line dropped below about 3 volts until it raised above 3 volts again, the interrupt service routine would just be entered over and over again as fast as the micro could process. If you ever find a practical use for this mode, please make a video on that. I am sure that the engineers has some good use for this or they would not have spent all the time and money to build it into the chip, but I sure can't figure out what it is use for.

  • @whitefields5595

    @whitefields5595

    4 жыл бұрын

    Edward, his next video will use a MOC3041 (or similar) which is a dedicated triac driver with zero-crossing built in. This chip gives a crisper 'true zero' crossing point that the Arduino can use. You are right, if he uses this set up he will get a digital zero trigger that may wander around. However, as soon as he installs the MOC the subtlety of your point will be lost!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, it does seem odd, repeatedly triggering an interrupt on LOW. I got around this previously by disabling the interrupt as the first statement in the ISR. A bit counter intuitive!

  • @MrEdwardhartmann

    @MrEdwardhartmann

    4 жыл бұрын

    @@RalphBacon I did that too once, disabled the interrupt in the ISR and then later, once the line went high, I re-enabled the ISR. But, I realized that I had just built a very complex and time intensive alternative to the built in high to low transition interrupt. So, I junked the whole thing and just used the transition interrupts.

  • @MrEdwardhartmann

    @MrEdwardhartmann

    4 жыл бұрын

    @@whitefields5595 Yes, I am quite familiar with the MOC3041 and have used them on a couple of solenoid driver projects. But, I wasn't really commenting on his little demo here - I assumed that this was just be a little training exercise to show people how interrupts work and why it is important to find the zero crossing when using triacs. I was commenting on the Arduino "LOW" mode interrupt operation. The Arduino family has the following modes: LOW, CHANGE, RISING, FALLING, and some have HIGH. I have never seen an application for the LOW or HIGH modes. Why do these modes even exist? If you have set a Low mode interrupt, and the line is low, the interrupt triggers over and over and you can't do anything else until the line goes high. So, the only way I see to use it is to disable the interrupt inside the ISR. But if you do that, it would have been simpler to just use the Falling mode which only triggers once per falling edge and you don't have to worry about disabling the ISR.

  • @whitefields5595

    @whitefields5595

    4 жыл бұрын

    @@MrEdwardhartmann Edward, I have always tended to use attach and detach interrupts as a pair, avoiding multiple triggering. One example of a LOW is a debounce routine for a pushbutton. I have used HIGH in peak detector circuits. I suppose what is going on here is the old software vs hardware (discrete components) issue that I keep bending Ralph's ear about. The later microprocessors have been great in popularising our hobby, but it always needs to be backed up by a thorough understanding of electronics. Many folk will try to do many things in software that really should be done with discrete passive components. HW interrupts could easily, more reliably and without repeat triggers be fed from an op amp, schottky diodes and other (logic) devices. In this AC example Ralph should (and hopefully will) use a dedicated zero crossing chip that only gives a single pulse.This would then leave the processor to do what it it good at rather than trying to 'catch' interrupts. Its a grey area, and always has been, but we ignore the basics at our peril as we force the processor to over-rotate.

  • @drescherjm
    @drescherjm4 жыл бұрын

    I thought the capacitor looked like it had a bulge from early in the video. I was going to comment on that but you cleared it up at 6:20 or so.

  • @TuttleScott

    @TuttleScott

    4 жыл бұрын

    me too, couldnt take my eyes off it. fixed a few motherboards with asploded caps in them. few tvs too.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    I'm tempted to do it again live on video! Just as a warning, of course!

  • @SteveBrace
    @SteveBrace4 жыл бұрын

    Zero Point Module! Get it over to Atlantis, quick! :)

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Theirs is nearly depleted, I understand, such a shame. Only enough power left to run a small city for a year...

  • @WhoWantsToKnow81

    @WhoWantsToKnow81

    3 жыл бұрын

    Thumbs up for the Stargate reference

  • @TOMTOM-nh3nl
    @TOMTOM-nh3nl3 жыл бұрын

    Thank You

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    You're welcome!

  • @asagk
    @asagk4 жыл бұрын

    Watch out not to accidentally open a worm hole with this flux-zero-point-crossing-hyper-mega-crontroller-thingy, Ralph! Btw.: Happy holydays (pentecost) !

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Too late, I opened a wormhole to a parallel universe where Arduinos had not been invented. It was a nightmare! And gleichfalls for the holiday wishes even though we do not celebrate Pfingsten here in the UK so much. We don't even get a public holiday on Pfingstmontag although Eire do.

  • @kennmossman8701
    @kennmossman87014 жыл бұрын

    Is it really getting the zero crossing point? 21:12 The LEDs would offset it surely? A LED would not conduct once Vac dropped below Vf [and the other LED would not be conducting either until the corresponding Vac rose beyond its Vf] which isn't the same as zero. Maybe I missed it but the code would have to delay the detected 'zero' point.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    You are on the right lines, Kenn. As the mains voltage drops to below 3v (what the Arduino will consider LOW), the interrupt triggers. The rectifier diode (or opto-isolator LED) will still be conducting at that point. But the mains sine wave is not actually at zero yet, a couple of volts above that. It should be straightforward to delay any switch on a millisecond or two until we know that zero has been reached - the oscilloscope will help me get the actual delay right for this. Keep tuned!

  • @ismzaxxon
    @ismzaxxon4 жыл бұрын

    Sorry to say, your logo output circuit is wrong. You will burn out your opto that way...shorting the to pos to the neg. What you need is ground and pos via a resistor to pos. Take the tapping at the logo. Or, if you use the internal pull-up, only connect the ground.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, you're not the first to spot this, Terry, I rushed it. don't worry, the final circuit will be fine. Well, fine-ish.

  • @nikhilsaseendranphotograph517
    @nikhilsaseendranphotograph5174 жыл бұрын

    Thanks sir

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    You're most welcome!

  • @dimasbagus76
    @dimasbagus762 жыл бұрын

    Work for induction motor?

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    As this gives a trailing edge control, I think that should be suitable for any induction motor.

  • @gpTeacher
    @gpTeacher4 жыл бұрын

    Yet more pearls Ralph! And I hope you’ll differentiate we 60Hz Commonwealth folks from those ‘colonials’ as you refer to thems who live south of the 49th😎😎. Thanks for another great lesson!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    It's interesting, Gord, that whilst a significant minority of countries use 60Hz, the vast majority use 50Hz. Keeps things interesting, I suppose. en.wikipedia.org/wiki/Mains_electricity_by_country

  • @gpTeacher

    @gpTeacher

    4 жыл бұрын

    Well, at least we took the Metric System and “behaviour”, “colour” and “neighbour”. But I stand firm on “aluminum”!!

  • @EmmittBrownBTTF1
    @EmmittBrownBTTF14 жыл бұрын

    This is just a hint from a coding geek, it may not mean anything. If the zpCounter hits 100 while beeping(longer beep, or higher frequency), the next event may be missed. Here's how to avoid that: volatile int zpPending = 0; void zeroPointDetect(){ if(zpCounter++)>99){ zpCount=0; ++zpPending; } } void loop(){ if(zpPending!=0){ --zpPending; beep(); } } increment and decrement are assumed here to be atomic. Interesting project, thanks for making me think.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Thanks for the suggestion. There was another comment about using integers, that the update would not be atomic which I believe is not true. As it is marked as volatile any ONE action (eg read, write on both bytes of the integer) is carried out atomically. But an update requires a read AND a write so it could cause problems inasmuch that it could be updated between the two actions. Back to your comment, regarding potential missing pulses. I don't believe this is the case, as the interrupt will run regardless of whatever else is happening in the loop, be that a beep or delay or whatever. For example, if I beeped on the 100 count for a whole 500mS then that beep routine would be interrupted 50 times (every 10mS). If I beeped for a full second the beeping would never stop! Thoughts?

  • @EmmittBrownBTTF1

    @EmmittBrownBTTF1

    4 жыл бұрын

    @@RalphBacon Whether an int decrement or increment is atomic depends on the processor, i386 can increment a 32bit value at a memory location in a single instruction which is atomic. In your application, or any application with steady events frequency and short handling, probably never going to see endless beeping. The suggestion is suited for more stochastic event processing.

  • @borayurt66
    @borayurt664 жыл бұрын

    I see that you have the digital current sensing on the phone charger, so I am assuming the analog one still isn't cooperating? Zero crossing detection with an Arduino project is interesting and educational. In the circuit you drew, you have two 47K resistors to drive the LED's in the optocoupler. That would work, but the power dissipated on the resistors would be higher than 500mW at 240VAC, so regular 1/4W resistors will burn out rather quickly. You may consider using 1W resistors, or better yet, a capacitive dropper there. Also you'll need a current limiting resistor on the transistor side of it where you tap your sense wire, otherwise each time that transistor turns on, it will be shorting the 5V rail. But, I know that you know all of these, so I believe that circuit was just a sketch to explain the concept, not an implementation version. :-) Great video as always!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, yes, and yes! I assumed 1W resistors would be used except my solution is an off-the-shelf device now (it costs more to buy the components). Wait for the update video in due course! I still want to demo a discrete component version though.

  • @fredflintstone1
    @fredflintstone14 жыл бұрын

    Shame we missed the magic smoke, someone did a video about caps the otherday with the arduino, I can't remember who it was;-) but best check it out :-)

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    I'm sure it was a very tasty introduction, wish I could remember the name.

  • @fredflintstone1

    @fredflintstone1

    4 жыл бұрын

    @@RalphBacon The name is on the tip of my tongue but being old my brain is not always connected to my memory bank :-)

  • @vogonjelc
    @vogonjelc4 жыл бұрын

    Fun fact ac is not pure sinus. Somet6to do with generator not being a single coil at poles but bunch of them. It's kind of flat when generator rotor poles hit the stator coils.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    It's difficult to measure mains directly on a scope, not to mention risky, but an opto across the mains in the way I showed might give me better idea what it looks like. Pretty noisy too.

  • @vogonjelc

    @vogonjelc

    4 жыл бұрын

    @@RalphBacon I was quite stunned when I saw AC maines on oscilloscope on 2and semester of university. It's not perfect sinus wave form. And then we got explanation from our professor who actually worked on hydro damn construction why it sort of flattens out. So noise is probably expected. As for 0 (low) detection maybe some comparator circuit? To generate impulse when AC is going through 0?

  • @vogonjelc

    @vogonjelc

    4 жыл бұрын

    @@RalphBacon And btw could you consider doing a video on for instance max4080 and arduino analogread. CIrcuitry and other stuff. :) Might help people when connecting analog sensors straight to arduino pins.

  • @SodAlmighty
    @SodAlmighty3 жыл бұрын

    Ralph, you are confusing Interrupts with Windows Events. The Intel-based CPU has hardware interrupts, and they work exactly the same as the Arduino ones. Mouse movements and the like are Events, which are an entirely different affair. Any mouse-based *interrupts* that occur are dealt with *immediately*, as the Arduino would. But mouse events aren't important, so they're just added to a queue at that point, to be handled later when the system isn't busy. Events are essentially the opposite of interrupts. They must wait until a unit of computation is complete. This is why programs are often "Not Responding".

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Good to know.

  • @clems6989
    @clems69892 жыл бұрын

    @ 2:45 . You mean the ones who walked on the moon ?

  • @RalphBacon

    @RalphBacon

    2 жыл бұрын

    Did they? Are you sure? I'm almost convinced it was a Frenchman who got to the moon first - I've read Jules Verne's De la Terre à la Lune (From Earth to the Moon) 😜

  • @7Sommerville
    @7Sommerville3 жыл бұрын

    Hi Ralph S Bacon, I have used your content in the videos to help me through and arduino project and now I have come to a stop. I thought to reach out to you.

  • @7Sommerville

    @7Sommerville

    3 жыл бұрын

    I have an arduino mega and a sketch that controls a 4 channel zrc dimmer via a rotary encoder. The problem I have is when the arduino powers up with the dimmer it is set at a default state set by the code. The problem comes when I try to adjust the brightness of the dimmers using the encoder as an input, the dimmer blinks every time it see an input from the encoder. I don’t understand how I can control the dimmer via an input if it interrupts the dimmer task(constantly looking for the zero crossing) everytime it receives an input from the encoder. I’m left scratching my head of what to do ? I would appreciate any help/advice

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Hmm, I suspect that your interrupt routine (ISR), used by your Rotary Encoder routine, is doing far too much work. Whilst the interrupt service routine is running, nothing else is (hence the flicker, I suspect). And the Timer0 interrupt is no longer running so millis() will be unavailable too (frozen at the last value). All the ISR _should_ be doing is setting a global variable to true, for example. Then your main loop can detect that value, do what is necessary alongside other work it is doing and then reset the global variable to false. See if doing what I suggested cures the fault before we think of other things.

  • @7Sommerville

    @7Sommerville

    3 жыл бұрын

    @@RalphBacon thanks , I have a look into your suggestion. I noticed I also that when the arduino reads temperature and humidity every few seconds the dimmer blinks. I’m not sure if the issue is with the dimmer code

  • @flemmingchristiansen2462
    @flemmingchristiansen24624 жыл бұрын

    What's cooking. is that capacitor? - I got sauce in my pocket. Lucky it didn't just explode - usually does for me. New project? could be very interesting, have to get coffe ready next time. Phone charger looking good, a bit surprising though. You took the time to make a PCB and then throwing "test boards" on it? I was hoping for a bit more from you -but it is working and it is cheap and easy - as you said a few times in the past "I am a programmer" - it shows. LoL (no disrespect intended)

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Oh dear, I feel so bad now. "I was hoping for a bit more from you". Oh dear. This feels the same as when my school teacher wrote on my work "Can do better". But.. But seriously, I thought about putting more native components on the PCB but I'm not going to do that for the BT module, and whilst I suppose I could have done it with the current detector, what purpose would that solve (unless I was after a very small PCB). We will have to be satisfied with the dual MOSFET chip and TH resistors (no SMD because many hobbyists don't like them). So in the end it's mostly a collection of pluggable components which makes is so much easier for me to assemble and every one else to construct, does it not? Wait for the final product before passing judgement, Flemming!

  • @flemmingchristiansen2462

    @flemmingchristiansen2462

    4 жыл бұрын

    ​@@RalphBacon LoL -"can do better" 😂 -can't we all -did I miss something?, I thought the Smart Phone Charge was done? -Judgement? noo not me. I do believe that critisism must be somewhat kunstructive, anything else is worthless.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Smart phone charger PCB done, not yet fully assembled.

  • @datawolk
    @datawolk3 жыл бұрын

    Maybe the noise on the AC signal comes from your light bulbs

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    Quite likely. My workshop is full of electronic equipment, specifically designed to cause the maximum amount of electrical interference!

  • @tim_bbq1008
    @tim_bbq10084 жыл бұрын

    0:10 Oh no, the last diode is drawn backwards

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Well spotted. I hadn't noticed. Nor anyone else, Tim. But you have to go and spoil it by mentioning it. Sigh. Now how do I get you onto that blacklist... Drat. There isn't one. Well, just take this as stern warning. No BBQ for you today.

  • @z08840
    @z088404 жыл бұрын

    type int is not atomic in atmega328p, so it's a bad practice to use it to transfer data between interrupts and main execution without some atomic guard. You better use byte or (unsigned) char here.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Not sure about that. The only non-atomic operation is the ISR incrementing the variable (so a read followed by a write) but that happens in the ISR which cannot be interrupted. The loop _reads_ the variable to test it, then _writes_ to it to zeroise it (which can, and probably is, interrupted) but that's it. I could have included the construct: ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { update the variable here in ISR } but I'm not convinced it's required. Your thoughts?

  • @z08840

    @z08840

    4 жыл бұрын

    @@RalphBacon first - it's all technicalities - in some cases you will have no issues and in others - you will - to determine this it will require complex analysis of u-controller hardware and code produced by compiler, so as a rule - just don't do this to avoid almost not-debugable bugs. Second, in the main code you are zeroing counter - this operation can be interrupted and garbled - heavily depends on hardware and compiler implementation - it can work for you now and stop working later or/and for somebody else. You don't need any atomic guards here - just use byte instead of int - this size is sufficient for this program - byte is atomic, and worst case scenario - you will lose just one increment - if zeroing was interrupted.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, you are right, I could use a byte variable to avoid the situation, but what if really wanted to count up to 1,000 before zeroising anything? I think then an atomic guard would be required in the loop (not the ISR) so the zeroising of the counter could be made atomically, right? So, no interrupts whilst it (each byte of the int) was being zeroised. Tricky to remember this! Harder to debug too. Edit: found this interesting example: www.nongnu.org/avr-libc/user-manual/group__util__atomic.html

  • @z08840

    @z08840

    4 жыл бұрын

    @@RalphBacon if you need count more, then you need an atomic guard (usually called synchronization primitives) - I've never used ATOMIC_BLOCK you mentioned above (and I don't program uC much), but for my electronic leadscrew project I used just bool flag (which is byte and therefore atomic) as a guard. But you should be careful using even atomics, because changing variable is anyway 3-step process - fetch-compare/change-write, so it's a good idea to use existing library primitives - implementing your own may be quite tricky and requires knowledge of hardware implementation of particular platform.

  • @z08840

    @z08840

    4 жыл бұрын

    @@RalphBacon and I took a look at mega328p instruction set - there is an op XCH - exchange - at first look it can be used to make atomic guards and even better - such cool thing as non-blocking queue and similar structures. But again - it's all tricky and not for every day application programming... so, just use libraries, I think...

  • @Graham1904
    @Graham19044 жыл бұрын

    I bet the noise is from the fluorescent tubes :)

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Could be, I have several here in the workshop. I certainly would like the find the cause (in good time).

  • @nisargshukla6382
    @nisargshukla63824 жыл бұрын

    Can we use it with esp8266 ?

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, but change the potential divider resistors so that you only get a max of 3V on your chosen interrupt pin. Interrupts may be attached on all the GPIOs of the ESP8266, except for GPIO16.

  • @nisargshukla6382

    @nisargshukla6382

    4 жыл бұрын

    @@RalphBacon Thanks for the reply, but my esp8266 keeps on crashing.

  • @boblewis5558
    @boblewis55584 жыл бұрын

    It's Covid-19 Ralph! No people on the streets ... Zero crossing! 😂😂😂

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    I'n debating whether to permanently ban you from my channel or to elevate you to senior member. 50-50 at the moment, Bob. 🤔

  • @boblewis5558

    @boblewis5558

    4 жыл бұрын

    @@RalphBacon Ouch! 😂😂

  • @boblewis5558
    @boblewis55584 жыл бұрын

    Highly technical solution to Windoze is not USB-2 Ralph! It MAY be "technical" but it's called Linux! 😂😂😂

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Let's start a religious war between Windoze and Linux, Bob! After all, Linux is to operating systems what McDonalds is to gourmet cooking. Ha ha, just kidding. But to be fair, Linux is 90% of the way there -- but getting the final 10% of the way requires a level of money, effort and fascism that doesn't exist in the Linux community. 😂

  • @stanislavpetkov7408
    @stanislavpetkov74084 жыл бұрын

    Instead zpCounter=0, shouldnt we zpCounter-=100, so in case we had for example 102, 2 will stay for the next time

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Good point, Stanislav. If we think there is a chance of another cycle arriving whilst "doing stuff" in the loop (which we will in the full project) we don't want to lose cycles. I might change the code to do that if I discover we might miss a cycle. Thanks for the suggestion.

  • @melkiorwiseman5234
    @melkiorwiseman52344 жыл бұрын

    "It was triggering a thousand times a second for some reason" The pin is low. It triggers an interrupt. The interrupt is serviced. The service routine ends and the interrupt is re-enabled, but the pin is still low so it triggers another immediate interrupt... Simple, when you think about it. That's why you use "falling" instead of "low" as the trigger, since it only triggers when the pin voltage passes through that particular high-to-low threshold on the way down. If the voltage is still falling when the interrupt is re-enabled, it won't trigger again because the "high-to-low" transition has already been recorded and won't be recorded again until after the voltage rises above the threshold voltage and then falls below it again. The devil is in the details, as with many computer and programming related problems.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, indeed. I think I alluded to this in the actual video and it has been mentioned a "few" times by others too! Amazing how quickly the Arduino can execute interrupts during that millisecond of "low"- ness. The main reason I was a bit baffled is because I never got my rotary encoder working with FALLING only with LOW. Go figure!

  • @melkiorwiseman5234

    @melkiorwiseman5234

    4 жыл бұрын

    @@RalphBacon I noticed that several other people mentioned it after I posted my message. I'm guessing everyone who posted about it did the same as me. It's a human flaw, I suppose. :) But I just noticed that your loop isn't quite right. It should work most of the time, but as a general thing you shouldn't say "if counter is greater than limit, then reset counter to zero" when you're dealing with the results of an interrupt. Instead, you should say "if counter is greater than limit, then subtract limit+1 from counter." The former works fine so long as it's impossible for the counter to count twice before being checked, but the latter is necessary if it ever becomes possible for the counter to count more than once before being checked, otherwise the counter will get "out of step" and the timing of the event will be "off" slightly and will "drift" over time.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Yes, that point was also mentioned a "few" times by your fellow viewers. My bad. I just hope my production code is better than the demo stuff I knock out!

  • @Hasitier
    @Hasitier4 жыл бұрын

    I was about to ask what had happened to this poor little electrolytic capacitor but then you explained..... 😅

  • @Hasitier

    @Hasitier

    4 жыл бұрын

    BTW you should add a resistor to the low voltage side of your optocoupler because otherwise the transistor inside the optocoupler will nearly short out your supply rail. And that might crash your arduino 100 times a second 😅

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Oh, that was just a rough diagram, it will be fine in the real circuit. The resistor will be in the high side though I think, so we detect drops to (near) zero on the collector side as it conducts. Or something. We shall see.

  • @drescherjm
    @drescherjm4 жыл бұрын

    I remember having to do this create a zero crossing detector circuit in my EE senior design microprocessor design course in the 1990s. Then we used a Motorola 68000 series CPU of 8 or 16MHz ( I can't remember). The triac was used to control the speed of AC Lionel Trains. Not sure what happened to my wire wrap tools. I have not used that in so long.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Your wire wrap tools are on eBay under Tools, Vintage, Expensive! Do you think that a zero crossing detector is easier with a µController rather than a µProcessor? Or does it make no difference to a bona fide Electronics Engineer?

  • @drescherjm

    @drescherjm

    4 жыл бұрын

    @@RalphBacon I am going to say the Arduino is easier and more forgiving in interfacing however this was too long ago for me to remember the details.

  • @joopterwijn
    @joopterwijn4 жыл бұрын

    Beep,.... having tinnitus, well I do not hear this beep,... instead internally it is non volatile overwritten by a constant beep... 🥴 but still enjoy your vid! Thx

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Sorry to hear that Joop, I will remember this and use both beep and LED in future videos! Take it from me, it was just very annoying (but very accurate too).

  • @joopterwijn

    @joopterwijn

    4 жыл бұрын

    Ralph, I must be very relaxed to be able to process the ‘beep’ all the time (haha 😂) for instance the multimeter beep, and beside that - washmachine-beep, dishwasher-beep..... never notice them because the overriding in my internal circuits. I hear it alway. But don’t worry I will survive 🙃!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Next video has a flashing LED, no beeps. Joy!

  • @whitefields5595
    @whitefields55954 жыл бұрын

    Ralph, why did you rectify the AC for this demo? Your triac controller needs full wave AC cycle so you may confuse the viewers. You would have most likely had a less noisy waveform too. Also worth giving a brief description of peak-to-peak vs RMS at some point. Finally don't forget a reminder on your isolation transformer - point to one of the many vids on this subject don't do it yourself. Folk are going to copy this and you don't want their mothers coming after you!

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    The AC was rectified purely for the zero crossing interrupt circuit so we can detect both halves of the cycle (AC goes too low - below 0.5V from GND - and would kill the pin). In the real circuit (as you saw) the same effect is achieved by an optocoupler with two LEDs inside, one for each half cycle. But the final circuit is safe, and I'm not building it. No more spoilers.

  • @cmuller1441
    @cmuller14414 жыл бұрын

    It's a pity you didn't really talked about what is on the breadboard. It seems that you are using a resistor divisor behind the bridge rectifier to divide the voltage (the Arduino doesn't like 20V on an input). The coefficient is probably arround 1:4 . The first problem is zero crossing. The pin is considered low even if it's not actually zero. Typically you'll get the interrupt too soon at 1 or 2 volts. It's probably 30 degrees too soon. The second problem is noise. The oscilloscope clearly shows it. If there are spikes arround the trigger point you could get multiple interrups for a single crossing. Adding a small capacitor on the input pin could help. To get a better detection and have a behavior similar to the optoisolator you can instead send the signal to the base of a transistor that pulls the input low for any voltage above 0.6V and have a pull-up resistor on the input pin if the Arduino. Zero crossing will be detected when the voltage raises.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    I've put the circuit diagram in my GitHub (link in the video description) which should help. Yes, the zero crossing is detected a bit too early (what a volt or two between logic circuits?) but that's no problem for software correction later down the line. I'm not sure using a transistor would help this circuit - but it won't be the one used in the final project anyway, as I mentioned!

  • @cmuller1441

    @cmuller1441

    4 жыл бұрын

    @@RalphBacon for Atmega chips, according to the datasheet, for 5V supply the threshold to be seen as a zero is 1.5V (0.3*Vcc). The threshold to be seen as a one is 3V (0.6*Vcc). Everything in between is undetermined. The actual limit is not fixed (temperature dependant) and there's some hysteresis to avoid problems near the limit. forum.arduino.cc/index.php?topic=54932.0 With a transistor acting like a not gate the threshold is down to 0.6V. With a little bit of low pass filtering it should be better. PS: don't forget that you divide the original signal from the transformer so the actual voltage is much higher.

  • @ShopperPlug
    @ShopperPlug3 жыл бұрын

    2:40 - Its funny how Americans think the same as for UK people lol In USA our voltage is 120V while UK voltage is meaningless 220V which is much more lethal. What will even confuse you more is that in the U.S, there are places where the electrical supply is 50Hz or 60Hz. Video would be more helpful if you should how you used the triac to dim an AC stuff like a light or what not.

  • @RalphBacon

    @RalphBacon

    3 жыл бұрын

    The next part of that project was to control the motor speed (or incandescent light brightness) but I never got it done before I moved house. But, I still have all the parts in a box so I will probably resurrect this later this year. Probably.

  • @TheSchneidItworld
    @TheSchneidItworld4 жыл бұрын

    ohhh

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    Qu'est-ce que tu essayes de dire?

  • @isettech
    @isettech4 жыл бұрын

    I think opto couplers are less expensive than programming and powering a micro controller IC. bristolwatch.com/ele2/zero_crossing.htm

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    But my demo showed that I would be using an optocoupler, right? And a µController, of course, we gotta have fun!

  • @isettech

    @isettech

    4 жыл бұрын

    @@RalphBacon Absolutely. It is fun. Currently working on an old school project from my youth. Was given a bag of NE2 bulbs. Adding caps, resistors, and mounting in a frame with 10 9V batteries. Original design used a portable radio B battery. See how many have to look that up! Putting a 10X10 matrix in it. Original design used a ring of 8. Caps between lamps and caps to ground ensured an almost predictable pattern. Besides a B battery, some newbs may have to look up relaxation oscillator to get an ides of the project. If you like blinky lights..

  • @BiddutMitra
    @BiddutMitra4 жыл бұрын

    use UBUNTU instead of Window.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    I'm sure Ubuntu (and all other *nix flavours) have their own share of problems!

  • @sortofsmarter
    @sortofsmarter4 жыл бұрын

    "Merica"...lol

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    The colonies is a better term. When you were part of the great British Empire. One day we will strike back. Until then, Gene, may the force be with you.

  • @sortofsmarter

    @sortofsmarter

    4 жыл бұрын

    @@RalphBacon Ha..lol the rate there going now I dont thing anything will be left.Some seemed to forget how to talk things out. Soon it will be people like us left in caves with are Arduino's sending long distance Lora communications

  • @electronicsmokeUK
    @electronicsmokeUK4 жыл бұрын

    That is NOT an Arduino. It's a copy or fake, at best it is a clone based on an Arduino. Don't use brand names for non brand product.

  • @pintokitkat

    @pintokitkat

    4 жыл бұрын

    It must be difficult saying 'I'm doing the Electroluxing.' because you don't have a Hoover. And telling people you used hook and loop tape instead of Velcro must make them say 'Oh, you mean Velcro? '. Yes, technically you are correct, but is it really worth confusing people just got show how smart you are?

  • @oilybrakes

    @oilybrakes

    4 жыл бұрын

    @@pintokitkat Reminds me of people that claim that an Iphone is not a smartphone, and a MacBook is not a computer. And that is why you gotta go to the "genius bar" to have them "repaired", and can not go to a normal technician that offers repairing apple products. Yeah, right...

  • @andymouse

    @andymouse

    4 жыл бұрын

    @@pintokitkat Exactly.

  • @andymouse

    @andymouse

    4 жыл бұрын

    Really ?...You are that pedantic ? I no we are all on lockdown at the moment and tensions are high and perhaps a little bored, but thats all you got out of the video ?....oh dear.

  • @RalphBacon

    @RalphBacon

    4 жыл бұрын

    The Arduino design (but not the name) is Open Source. So we can have (exact or different) copies of the Arduino board produced by others. The are not fakes. No such thing unless it has Arduino printed on it. It is an Open Source alternative. I don't think Arduino.cc is losing any sleep over this!

Келесі