Це відео не доступне.
Перепрошуємо.

#209

Поділитися
Вставка
  • Опубліковано 7 сер 2024
  • What! Timer Interrupts? So easy and so useful.
    PCBWay Big Sale Christmas 2020 pcbway.com $5 for 10 PCBs
    I had to show you how to do this on an Arduino (Uno/Nano/Mini) as it's a very useful technique for offloading some processes, even though I tried to use the same technique on an ESP32 - and failed, as it was not the right way to do what I wanted. But here it is!
    If you need a regularly triggered function (from every few microseconds to every few milliseconds) then this is a possible solution.
    Not only that, I have an important (but sad) announcement about my future videos as well as a quick, 5-minute update on the Internet Web Radio (working so very well!)
    Sketches in my GitHub:
    github.com/RalphBacon/Arduino...
    Timer 2 Interrupt Info from Nick Gammon (no, not related)
    www.gammon.com.au/images/Ardui...
    List of all my videos
    (Special thanks to Michael Kurt Vogel for compiling this)
    bit.ly/UA-camVideoList-RalphB...
    --------
    PRODUCTS
    --------
    You can help my channel by clicking on an affiliate link before purchasing anything from that supplier.
    The 2.8" TFT touch screen used in my demo for just $6.66 (plus $2.05 shipping) or from USA & UK direct:
    2.8 Inch ILI9341 240x320 SPI TFT LCD Display Touch Panel SPI Serial Port Module
    www.banggood.com/custlink/v33...
    38-pin ESP32 with headers for just $4.99 plus $2.25 shipping ($9.00 plus 0.99 shipping if ordered from USA):
    www.banggood.com/custlink/KGK...
    Amazon UK sell this 2.8" screen (in the UK) for just £10.59 next day delivery!
    amzn.to/2HHFYue
    Amazon UK also sell the 38-pin ESP32 DEv Kit for just £5.55 in the UK:
    amzn.to/3mFhy30
    AliExpress offer both 30-pin and 38-pin ($3.36 + $1.04 shipping) of the ESP32 Dev Kit:
    www.aliexpress.com/item/32959...
    I couldn't get an affiliate link for above, click here first: s.click.aliexpress.com/e/_ADe0jl
    That's a link for a bare ESP32 with a whopping 16Mb on board! But needs an expansion board/PCB.
    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
    Sketches in my GitHub:
    github.com/RalphBacon/Arduino...
    My channel, GitHub and blog are here:
    ------------------------------------------------------------------
    / ralphbacon
    ralphbacon.blog
    github.com/RalphBacon
    ------------------------------------------------------------------

КОМЕНТАРІ • 189

  • @markday3145
    @markday3145 3 роки тому

    You know it's an excellent video when you get me digging into the data sheet before I've even finished the video.

  • @AtlantaTerry
    @AtlantaTerry 3 роки тому +2

    Ralph, thank you for taking the time and effort to put this together.

  • @aryeguetta8592
    @aryeguetta8592 3 роки тому

    Good luck Ralph with the move and the new house. That PCB looks very good and I know that it will take time till you will talk about it - can't wait to see all in the work and hopefully be able to do one by myself using your guide. Will be waiting for a workshop tour in the new house. Bye and thanks for everything.

  • @philowen2755
    @philowen2755 3 роки тому +1

    I love these bit bashing videos. Good luck with the house move. Merry Christmas from Wales Ralph.

  • @srfsupyo3134
    @srfsupyo3134 3 роки тому

    I initially thought your channel was just beginner level stuff based on the first few videos I happened to watch. My first impression was wrong! I've seen that you get pretty in depth with programming related things and I appreciate that. Thanks for taking the time to do these excellent videos and I'm enjoying the content of your channel!
    I'm a hardware guy, looking at embedded design and I sometimes think it would have been easier if I studied software first and did hardware afterwards!

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Great to hear! I try and do beginner stuff because it can be daunting to start this Arduino lark, but eventually we have to move beyond that and into more detailed programming, so I'm glad you're finding all this useful. Built my ESP32 Web Radio yet?

  • @OsoPolarClone
    @OsoPolarClone 3 роки тому

    Have a Merry Christmas Ralph and hope the move goes well. Great video and VERY informative as always. I love your videos.

    • @RalphBacon
      @RalphBacon  3 роки тому

      Happy holidays! See you in the new year if not before, Bruce.

  • @thisoldjeepcj5
    @thisoldjeepcj5 3 роки тому

    Merry Christmas
    Look forward to seeing you from your new place.

    • @RalphBacon
      @RalphBacon  3 роки тому

      Happy holidays! Yes, when the time comes I'll do the "Workshop Tour".

  • @stevehallam0850
    @stevehallam0850 3 роки тому +1

    Thanks Ralph, hope all goes as well as can be expected with the move...

    • @RalphBacon
      @RalphBacon  3 роки тому +2

      Thanks Steve, Christmas has got in the way of the whole process but after that it should be plain sail---- what? What lockdown?

  • @ElieWar
    @ElieWar 3 роки тому

    Thank you, I learned a lot. Merry Christmas and good luck with your move.

  • @johnramsay1827
    @johnramsay1827 3 роки тому

    Best of luck with the move. Looking forward to your return.

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Much appreciated! Last video on Xmas day!

  • @newburypi
    @newburypi 3 роки тому

    You had me at "interrupts"
    You've mentioned this Gammon fellow before and I was about to say that I'd never looked into him. However I now realize that his site was responsible for me getting a needed leg up on a project, implementing SPI communications between Arduino and RPi's. In any case, I have now booked some time to look over his entire site.
    Here's hoping your move goes smoothly. I've just finished re-building my work space and hope to be back looking at implementing ROS on ARDVARC (and all the minutia that goes with it).

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Sounds like you will be busy, Dale! I'm glad you've (re-)discovered Nick Gammon's site, it truly is a joy to read and he knows more than Arduino know themselves about this device!

  • @IanSlothieRolfe
    @IanSlothieRolfe 3 роки тому +4

    Well thats spooky! I only at the beginning of the week played around with Timer2 interrupts to scan a 7 segment display on my arduino project! You've made a slight error here, the ISR gets called when the timer overflows every 256 timer clocks, which will be 16000000/1024/256 or 61.03515625 times a second. Its the timer that gets clocked at 15625 times a second.. thats why when you slow the clock 16 times to 1Mhz and flash every other interrupt you get a 61/32 ~= 2Hz flash.
    Other than this minor technicality, great video!

    • @RalphBacon
      @RalphBacon  3 роки тому

      Timer ticks vs Overflow ticks - what you say is true. Glad you liked it, and you have just reminded me to set my Arduino back to 16MHz.

    • @IanSlothieRolfe
      @IanSlothieRolfe 3 роки тому

      @@RalphBacon I also noted that you're writing to the PINx register to toggle it, I thought it was read-only but on investigation writing 1's to it does toggle the pin - I never knew that, so once again I have learnt something new!

    • @RalphBacon
      @RalphBacon  3 роки тому

      Indeed, it's a (I was going to say well-known) useful trick but maybe not so well known! Glad it's helped you, Ian.

  • @eligijuspranskunas3509
    @eligijuspranskunas3509 Рік тому

    Thats will be very usefull to detect zero cross and control hot plate sine wave timing, great video!

    • @RalphBacon
      @RalphBacon  Рік тому +1

      Glad you found it useful, Eligijus!

  • @Ancipital_
    @Ancipital_ Місяць тому

    Thanks for the tutorial, really happy with it.

  • @omkarkhade4602
    @omkarkhade4602 3 роки тому

    Thank you very much for this tutorial. The way you explain things is great.

  • @andymouse
    @andymouse 3 роки тому

    Good luck for your move, hopefully no major interruptions and the process is not interrupted in anyway ! and all goes smoothly, nice tutorial on interrupts, I would like to add when using interrupts to be careful with delays, as this can cause interrupts to behave badly and actually interrupt the normal operation of the CPU, which interrupts the expected flow of data and interrupting what could have been a nice day......thats it Im done ! ...cheers Ralph !

    • @RalphBacon
      @RalphBacon  3 роки тому

      If you had continued that long post, I would have interrupted you but you finished just before the WDT jumped in! Ha ha! Thanks Andy, have a great Christmas.

  • @geralltgriffiths7772
    @geralltgriffiths7772 3 роки тому

    Ralph, you asked what we've used RTIs for... I used a real-time interrupt for sampling a received radio signal for an MFT (formerly "Rugby time signal") receiver/decoder. Yes, I know, there are libraries out there, but I just fancied rolling my sleeves up and exploring filtering and oversampling, to try to recover a more robust time waveform from a variable (and sometimes weak) radio signal. I really must dig that project out and finish it. The state-machine bit needs rethinking (hint for another video, pretty please!).
    Happy Christmas and good luck with the move!

    • @RalphBacon
      @RalphBacon  3 роки тому

      I'm encouraged that you "rolled up your sleeves" and wrote your own code for that project (even if the state machine needs a bit of tidying up). Merry Xmas to you too, Gerallt and let's hope the move goes smoothly in January.

    • @geralltgriffiths7772
      @geralltgriffiths7772 3 роки тому +1

      @@RalphBacon Thanks so much for the reply, Ralph. Yes, I am "that" kind of engineer -- never happy until I "understand how things work".
      Just to explain, my design included a real-time clock chip, so without recourse to anything external, should it display the "clock-chip" time or decoded "radio" time (parity checks aren't reliable) -- and how could I be confident that chip time should be synchronised with the MFT signal. I had hoped that a state machine would cover that, but my brain exploded trying to decide which states to use and what would cause the state changes.
      Somehow, building an ESP32-based weather station (with MQTT and Node Red) seemed easier, so the MFT clock went on the back burner. Ultimately, I'd like MFT MQTT feed into my IoT rig, so the project will get picked-up again in the New Year, and maybe moved onto ESP32 (it's currently on an Arduino Mega).
      I hope that the new tier4 restrictions don't impact your move. The important thing is to stay safe. Take care.

  • @tonyfremont
    @tonyfremont 3 роки тому

    The input capture feature of the 328p is awesome for getting perfect submicrosecond pulse width measurements.

    • @RalphBacon
      @RalphBacon  3 роки тому

      Something I really need to explore further, so I will bear it in mind.

  • @michaelhyde9971
    @michaelhyde9971 3 роки тому

    Good luck with the move. Hope all goes well.

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Thanks, Michael, second in stress to divorce, they say. I'd rather get divorced, much simpler. But don't tell the wife!

  • @iot_enthusiast
    @iot_enthusiast 3 роки тому

    Catchy title, can't wait to watch the content :)

    • @RalphBacon
      @RalphBacon  3 роки тому

      Hmm, can't tell if you're serious. I guess not if I have to think about it. shame, it is a useful technique on the Arduino.

  • @flemmingchristiansen2462
    @flemmingchristiansen2462 3 роки тому

    Web radio looking great. Th price do run up with box, power supply, buttons and connectors. It can really surprise you. A £10 project cam quickly end in £20-30 before it's finished-finished.
    Good luck with moving house. I am looking forward to see your new studio.

    • @RalphBacon
      @RalphBacon  3 роки тому

      Very true. The box plus acrylic front panel costs more than all the other components. I really should invest in a 3D printer.

  • @theonlymudgel
    @theonlymudgel 3 роки тому

    Cheers Ralph. Files on their way.

    • @RalphBacon
      @RalphBacon  3 роки тому

      Got them, and your email later. Have a great one.

  • @StigBSivertsen
    @StigBSivertsen 3 роки тому

    I had an issue some time ago that is not directly related but I guess maybe a little. I was not able to get an I2C based BME280 to work together with an RF-ASK radio on an ATTiny85 running ATTinyCore, separately it worked but not simultaneously. To my knowledge, it's a timer issue so I wanted to learn these things and maybe try to get this to work... Good luck with the move...

    • @RalphBacon
      @RalphBacon  3 роки тому

      Thanks Stig, it's not in the least stressful all this packing of boxes and then falling over them as we have no space left. Thank goodness I have my workshop still in one piece to escape to. Anyway, I hope the video was useful and see you in the New Year.

  • @MUHAMMADYAWARIFRAHEEM
    @MUHAMMADYAWARIFRAHEEM 3 роки тому

    Very informative video SIR

  • @NormanNodDunbar
    @NormanNodDunbar 3 роки тому

    At around 4 minutes in, Ralph, you suggested that "someone" should have created something to make interrupts easier to use on the Arduino. Appendix K in Arduino Software Internals, sorry about mentioning it again, might be of interest.
    I'm also writing another set of libraries ti make all ATmega328 interrupts easy to use from the Arduino IDE. Not released yet, part of another book!
    Good luck with the house move, stress piled upon stress there!
    Stay safe.
    Cheers,
    Norm.

    • @RalphBacon
      @RalphBacon  3 роки тому +2

      The good news, Norman, is that I finished your book a day or so back, including all the appendices and I'll be mentioning it in the very next video before I start packing up. *Best software/hardware book* I've ever read and I wish I had had it a few years ago. No-one could ever remember all the content so it will be my reference book for the Arduino for the foreseeable future. Great work.
      For those readers interested (and you should be): amzn.to/3p3tSLV

    • @NormanNodDunbar
      @NormanNodDunbar 3 роки тому +1

      @@RalphBacon Praise indeed, thank you very much.
      I'm glad you liked it, that was 2 years of my life written down! It's hard work trying tomake sure you get everything correct.
      Have a great Christmas and here's to 2021 being much better than 2020. Stay safe.
      Cheers,
      Norm.

  • @zakaryaafa702
    @zakaryaafa702 3 роки тому

    thank you, i love your videos❤

  • @keen2461
    @keen2461 3 роки тому

    I still don't understand why people keep using the Arduino IDE. The proper way to program AVRs is the Atmel Studio. There you can simulate every single bit and see what is actually happening inside the AVR. Excellent video that show to "arduino people" that if you want to do something right, you have to read the Datasheet.

    • @RalphBacon
      @RalphBacon  3 роки тому +3

      That's because beginners need a simple IDE that hand holds without scaring them off. Anyone who gets "into" the Arduino hobby really should progress to _something_ more sophisticated; my favourite is PlatformIO right now, but Atmel Studio is great albeit a big step up from Arduino IDE. Glad you liked the video!

  • @astrogerard
    @astrogerard 3 роки тому

    I always use timer interrupts for rpm/tacho meters. Just count the pulses in a fixed amount of time and you know (can calculate) the rpm.

    • @RalphBacon
      @RalphBacon  3 роки тому

      An excellent example of Real World use of interrupts, thanks!

  • @MikesAllotment
    @MikesAllotment 3 роки тому

    Another really useful & informative video Ralph - thanks. Just wondering how things might be different on an ESP8266? Does it have similar/same timer interrupts that work in a similar/same way? In the meantime - good luck with the house move & wishing you a Merry Xmas & Happy & Healthy 2021!

    • @RalphBacon
      @RalphBacon  3 роки тому

      It's different on the ESP8266 and on the ESP32 too. Thanks for the good wishes regarding my house move, we're currently falling over half packed boxes!

  • @ChagoiSteve
    @ChagoiSteve 3 роки тому

    As ever tricky topic well explained. We'll done Ralph. Best wishes for the festive season and hope move goes smoothly. Does this meen a new bigger workshop/lab for your projects?

    • @RalphBacon
      @RalphBacon  3 роки тому

      Yes it will, a bigger workshop, that is. Well, slightly bigger but squarer which is better for doing my electronics and videos too. But some weeks off yet, so don't leave me!

    • @ChagoiSteve
      @ChagoiSteve 3 роки тому +1

      @@RalphBacon Nope not going anywhere!

  • @yogeshitaliya473
    @yogeshitaliya473 3 роки тому

    Nice one sir

  • @willofirony
    @willofirony 3 роки тому +1

    Well, just in case you don't make it back to the channel before 2021, have a happy holiday, a happy new house and above stay healthy.
    I too have been puzzled by the Arduino IDE's neglect of the Timers and counters. Admittedly, the fact that each of the timers have other jobs to do, such as Millis, analogue, SPI and I2C, does make their use a bit complicated but certainly not impossible. Ironically, they did take the time to write the macros for the various AVR defined timer control registers but would it be so difficult to alias those names with readable ones? C'est la vie. They are a very valuable resource that allow the developer to delay sections of code WITHOUT stopping everything else. They will also count pulses input to a pin. There are many cheat sheets (all of which were derived from AVR documentation) all that is required that you look through the alternate operations of each timer, very few projects use ALL the functions and choose the unaffected timer. Too complicated? Well every pin on the Atmega 328p (irrespective of the format) has multiple functions, so one has to make a choice just to flash an LED.

    • @RalphBacon
      @RalphBacon  3 роки тому

      Too right, Michael, there is so much power in the (humble) ATMega328P, it's a pity they did not continue their Arduino-speak to timers. Too complicated, maybe? Thanks for your good wishes and a Merry Christmas to you too!

  • @vonries
    @vonries 3 роки тому +1

    Good luck with the move! How can we possibly have as much stuff in our houses as we do on the day we try to move?

    • @RalphBacon
      @RalphBacon  3 роки тому

      Worse than that, Steven, we've done two "sweeps" of our house well before this and have filled up one big builder's skip and then one car full (all seats folded down) to the local tip. Even now we're finding stuff to discard. I know I shall be looking for that stuff in the months ahead! Thanks for your good wishes, fingers crossed.

  • @asagk
    @asagk 3 роки тому

    Schöne Feiertage, Ralph!
    Bei der Gelegenheit, hattest Du schon etwas über den Differential-ADC Modus gemacht? Sowas fehlt eventuell noch ...

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Yes, I'm aware that I've never discussed analog differential modes on the Arduino, although I touched on the subject when I use the pin extender (I think). I'll add it to the list for 2021. Seasonal greetings to you too, Sebastian!

  • @gazzacroy
    @gazzacroy 3 роки тому

    cool very interesting :) have a happy move too.. DONT lose the kettle..

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      That's the plan! It's going into a box marked "Kitchen - OPEN FIRST" which has the kettle, tea bags, coffee, sugar etc. The most important box of the entire move!

    • @gazzacroy
      @gazzacroy 3 роки тому +1

      @@RalphBacon lol oh yes :) good luck.

  • @stevenheynderickx583
    @stevenheynderickx583 Рік тому

    500th Like... What price do I get 🙂. I assume all the knowledge you share. For which I thank you Ralph

    • @RalphBacon
      @RalphBacon  Рік тому +1

      So nice of you, Steven. No prizes, I'm sorry, but you do get a warm fuzzy feeling that you're helping my channel! 👍

  • @kalikatz2382
    @kalikatz2382 3 роки тому +1

    I'm not John, he is, I'm Rob. Btw, grats on the move. A good, well my fav internet radio, is radioparadise.com

    • @RalphBacon
      @RalphBacon  3 роки тому

      So who answered the question, John or you? And were you sitting at the back? Interesting website, I shall check it out more fully over Christmas (unless I'm packing boxes). Cheers!

  • @sortofsmarter
    @sortofsmarter 3 роки тому

    Congratulations on the new house. Finally, sorry it's over the holidays. But I have a question and I'm no coder ( more like a code borrower ) so this may be way off or a super silly question but the ESP32 is a dual core unit, couldn't you split the processes up so one routine was looping on one core and the other routine in the other core? so they could run in parallel with each other? Or it just doesn't work like that..lol

    • @RalphBacon
      @RalphBacon  3 роки тому

      Although the ESP32 is dual core, and technically you _can_ run on both cores (which I demoed in video #149) , it's not considered wise to run anything on Core 0 as that's the core Espressif have used for all the WiFi and BT stuff. Keeping to Core 1 ensures we don't upset anything on Core 0 (unless your interrupt routine runs too long on core 1 then it reboots the entire device).

    • @sortofsmarter
      @sortofsmarter 3 роки тому +1

      @@RalphBacon Ok that makes sense. I wish the Portenta H7 wasn't so expensive I bet it would do it. Someone needs to mailbag it to you...lol

  • @dellodel9502
    @dellodel9502 2 роки тому

    First of all thanks for every things you gave us ⭐⭐⭐⭐⭐.
    I have some ATMEL uC from trash and i would lik to program them but i don't know the value of their crystal !!.
    If i want to reprogram them using the SPI protocol , the clock pin will allow me to do it? ( without knowing the value of the clock).
    In other way the clock pin of SPI protocole will replace the crystal clock ( at least during reprogramming operation ).
    Thanks.

    • @RalphBacon
      @RalphBacon  2 роки тому

      I'm glad you're enjoying my channel!
      Regarding your unknown clock speed chips, if the chips were previously running from their _internal_ clock then you can program them as normal. No crystal required. Try this first.
      If they were running from an external crystal, just connect up an 8MHz crystal (or 16MHz) temporarily between the relevant pins (you _might_ need two 20pf capacitors between each pin and ground too) and try an upload.
      Bear in mind that if you try and upload via ICSP from another Arduino, then the RESET of the target chip must be connected to pin 10 of the programmer board (assuming you're using the Arduino-As-ISP sketch). This allows the programmer board to reset the target board and not itself!

    • @RalphBacon
      @RalphBacon  2 роки тому

      Much more info from Nick Gammon: www.gammon.com.au/bootloader

  • @Roy_Tellason
    @Roy_Tellason 3 роки тому

    I ran across some ESP32s for lots less than what you posted above. Unfortunately they screwed up and got the wrong address on the package, so I haven't got them in hand yet. Based on some of what I've seen in your channel I'm in for some fun when they do get here...

    • @RalphBacon
      @RalphBacon  3 роки тому

      Just bear in mind, Roy, that the registers for the ESP32 are very different to the Arduino's. But the good news is that the ESP32 has several timers and some are 32-bit IIRC but I'll cover that next year.

  • @StigBSivertsen
    @StigBSivertsen 3 роки тому

    Hi Ralph, Hope you're ok. I had to re-see your video. I want to use the TI CC1101 radio module in a project I'm working on. In all examples, I've found it's only possible to send a maximum 64 bytes of data and I need to send more than that so I have decided to try to rewrite TI's c/c++ examples that show how to do just that. In this big example project from TI, they use timer overflow interrupts and I will need to convert this to arduino's way of doing it. Not convinced that I will be able to do this but time will tell.

    • @RalphBacon
      @RalphBacon  3 роки тому

      Good luck with that project, Stig!

  • @j1952d
    @j1952d 3 роки тому

    Hi Ralph, loving your videos - thanks!
    Do you know if there's a way of grabbing the current value of an ISR vector? If so, you could hi-jack an interrupt, do your thing (increment a counter or whatever), then pass control on to the original ISR. I did this years ago on Z80 and PDP11 systems, and it worked a treat! Would mean you could use eg Timer0 without disrupting it's usual functions. Stay safe, have a great Christmas, and hope the move goes well. Hate moving - very stressful. Cheers, John

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      You would have to rewrite the original ISR to either call your routine or write your own ISR that called the original code too. Applies often when using Timer 0 on an Arduino. But you can't define two ISRs both trying to be the routine for a certain interrupt condition - compiler spots it and throws its toys out of the pram. Yes, moving is too stressful considering we're packing without having an exchange date yet! I'M NOT STRESSED AT ALL!!!

    • @j1952d
      @j1952d 3 роки тому

      @@RalphBacon "write your own ISR that called the original code too" - that's the idea. Would probably have to do an assembly code JMP from your code to the original code, so its return-from-interrupt worked correctly. But how can you get hold of the original ISR vector? I would google it, but you seem very knowledgeable in such matters, and I'm a lazy old sod. Chill - it'll all be alright on the night :)

    • @RalphBacon
      @RalphBacon  3 роки тому

      The original ISR for Timer 0 is buried in the Arduino core but can be edited (until a new release splats over the top). It can be found in this file:
      C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\wiring.c
      and it's here for the Timer 0 overflow ISR
      #if defined(TIM0_OVF_vect)
      ISR(TIM0_OVF_vect)
      #else
      ISR(TIMER0_OVF_vect)
      #endif
      (The code then follows).
      Good bedtime reading, yes, really.

    • @j1952d
      @j1952d 3 роки тому +1

      @@RalphBacon Thanks. Nowt like a good yarn!

  • @PaulMcKillop
    @PaulMcKillop 3 роки тому

    Good luck with the move, Ralph. No stress, eh?

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      WHAT STRESS PAUL???? I'M NOT [censored] STRESSED AT ALL! Seriously, thanks for your good wishes, what could possibly go wrong?

    • @PaulMcKillop
      @PaulMcKillop 3 роки тому +1

      @@RalphBacon ME NEITHER! Lucky Christmas is always stress free too.

  • @manuelchaves6835
    @manuelchaves6835 3 роки тому

    tks

  • @andymouse
    @andymouse 3 роки тому

    I'm just gonna "Interrupt" you for a moment and say 'Merry Christmas !'...now back to the vid.....

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      So funny... what a joker! Merry Christmas right back ya, Andy! See you in 2021 (if not before).

  • @reynaldowify
    @reynaldowify 3 роки тому

    Hi, very much thanks. I wonder how would it work, doing a simple incremente of a volatile global variable in the ISR, that is used in the loop to trigger some event at certain value, reseting to 0 at the desired moment
    Thanks again

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Yes it will. You can use volatile globals in the ISR that are then used by other parts of the code. Make sure the action in the ISR is "atomic"; that is, it completes before allowing anything else to run. Applies to updating both bytes of a two-byte integer, for example.

    • @reynaldowify
      @reynaldowify 3 роки тому

      @@RalphBacon Thanks for the answer. I am new at arduino, but have to develope a system with arduino mega, for control of a industrial clothes dryer. Until now, i used a TimerOne library, but it is not nice to me, since i use a library, i loose full understanding of what is going on, and become affraid to use other interrupts. However, it works, but it is really intersting to dig deeper than simple arduino reference tells
      Certainly, arduino is way more than a toy to say "Hello world", specially the arduino mega, which allos me to manage a 7 segment 4 digit display, some sensors and control buttons , to manage the drive motor and gas valve with time count. Of course, whith extremely care and physical safety backup, using also a ladder of relays to activate power devices.
      Thanks again
      Greetings from Argentina

  • @marshdilruk
    @marshdilruk 3 роки тому +1

    Isn't PINx register in atmega328p read only? Both atmel docs & arduino reference page claims that.. But I know that the compiler compiles PINx write commands as expected. I think it's better to use PORTB ^= (1

    • @RalphBacon
      @RalphBacon  3 роки тому

      I didn't know that PIN was (officially) a readonly function, James. I did know that you can toggle a pin by using the PIN function (and many developers do this). If you are more comfortable using the PORTB that's fine, it's just more cumbersome in this instance.

    • @alhenriq
      @alhenriq 3 роки тому

      Yes I realize that directly trying to update the pins did not work for me ... however writing or assigning to port registers does work.

  • @Winkleink
    @Winkleink 3 роки тому +1

    Can you explain why the following in each interrupt routine doesn’t reset myDelay stopping it from ever being 5 or 9.
    static uint8_t myDelay = 0;

    • @RalphBacon
      @RalphBacon  3 роки тому

      Post the full (but minimal) code for the interrupt; I can't understand what you mean or the result you're getting with just that one line, sorry.

    • @Winkleink
      @Winkleink 3 роки тому +1

      Sorry for not being clear.
      In each of your interrupt functions you reset myDelay to zero at the start.
      To me this means every time the interrupt function is called myDelay is always zero.
      Since there is no loop only an ‘if’ statement I’m unclear how myDelay ever equals 5 or 9 for the 2 additional functions that toggle the second and 3rd LED slower.
      To me the if statement is executed only only doing myDelay++ once before exiting the function.
      Then next time myDelay is reset to zero.
      Meaning myDelay can only ever equal one at a maximum.
      I expect I’m missing something fundamental in how the interrupt functions are executed.
      I hope this is a bit clearer. If not then my mistake.
      Than you for your videos, good luck with the house move and Happy Nee Year.

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Ah ha! Now I understand the question. The declaration of the myDelay integer has the "static" description.
      This makes it act like a global variable but only for the function in which it was described. Basically, the compiler sets the initial value then moves it out of the function so that it is NOT reset each time. But it cannot be accessed by any function other than one it was declared in.
      Whilst some people like true global variables (because they are so easy to (ab) use), professional developers (like me, yes, really) would not use them except where strictly necessary and would prefer static variables (aka local, global vars).
      Long explanation, I hope that clears things up - if not, let me know.

  • @nexuzinnovation-com
    @nexuzinnovation-com 3 роки тому

    hi Ralph,
    1. when the Timer2 is set at 15.6kHz, is the loop() also running at 15.625kHz or just the ISR is called every 64µs ?
    2. is the loop() still running at 16MHz when the Timer2 is set at 15.625kHz ?
    Please advise, bit confused :o)
    Have a smooth Christmas.

    • @RalphBacon
      @RalphBacon  3 роки тому +2

      On this board my clock is running at 1MHz (not 16MHz).
      The loop is running at 1MHz (but would run at 16MHz normally).
      At 16MHz, the timer is being called 15,625 times a second (16,000,000 divided by 1024) but the ISR is called only when the timer overflows the 8-bit integer (every 256 calls, so on my 1MHz board at about 3.8Hz. On a standard 16MHz board it gets called 61 times a second, too quick for us to see it flashing, hence why I slowed down the board).
      Funnily enough, I clarify this in this week's video. The last of 2020 so don't miss it!

  • @johnbyrne1567
    @johnbyrne1567 3 роки тому +1

    Hi Ralph
    Good luck with the house move.
    Will the radio motherboard be available for sale,hope so
    Thanks

    • @RalphBacon
      @RalphBacon  3 роки тому

      Not sure yet, John. Are you in the UK?

    • @johnbyrne1567
      @johnbyrne1567 3 роки тому

      @@RalphBacon Yes Ralph greater London

    • @RalphBacon
      @RalphBacon  3 роки тому

      If you're quick, find my email address in the About tab of my channel, send me an email and I will see what I can do before I pack it all into moving boxes.

    • @johnbyrne1567
      @johnbyrne1567 3 роки тому

      @@RalphBacon Just looking for the about? thanks will get back asap John

    • @johnbyrne1567
      @johnbyrne1567 3 роки тому

      Ralph, I can only find an email that begins "webmaster" not sure that would be the one you are referring to.
      Not sure i should publish my email here ?

  • @benbenameur8429
    @benbenameur8429 Рік тому

    Hello
    Can the Leds be switched on off at once and for a specific period of time instead of infinity loop by using timer interrupt ?

    • @RalphBacon
      @RalphBacon  Рік тому

      So, you mean turn the LEDs on/off via the timer interrupt without using any code in the loop, just an interrupt function? I don't see why not, although how often the interrupt timer gets triggered (the MAX delay time, you might call it) might not be very long... you would have to check that.

    • @benbenameur8429
      @benbenameur8429 Рік тому

      @@RalphBacon
      I meam turn the LEDs on/off via the timer interrupt but just 5 time ON and 5 time OFF not forever

  • @fillempie1501
    @fillempie1501 3 роки тому

    Hi Ralph,
    Bit off topic. I see you are still using the Sloeber-Arduino plugin. After your PlatformIO demo I switched over to PIO and never go back again. Why are you still using eclipse?
    /Willem

    • @RalphBacon
      @RalphBacon  3 роки тому

      I have to use all three when developing sketches for this channel. I can use the exact same code for Eclipse as I do for Arduino IDE but for PlatformIO it's more complicated to make an Arduino version. Well, so far it has been. But PlatformIO is my way forward, really like it now.

  • @kentswanson2807
    @kentswanson2807 3 роки тому

    What happens if your ISWhat happens if your IWhat happens if your ISR .....
    What happens if your ISR takes longer than the time between Interrupts?

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      You miss an interrupt as interrupts are disabled whilst an interrupt is running. However, that said, interrupts are queued... but only one (of each kind). Another reason for ISRs to do what is required and get out of there, sharpish.

  • @inadequateusername7280
    @inadequateusername7280 Рік тому

    Why do you OR the bits to toggle, rather than do an exclusive OR (XOR/ ^=)?

  • @josephchamness9915
    @josephchamness9915 3 роки тому

    Using an OR to toggle confused me for a bit. Do you know why the MCU has a hardware toggle instead of using an XOR e.g.. PORTB ^= (1

    • @RalphBacon
      @RalphBacon  3 роки тому

      I'm guessing that Atmel thought it a "Good Idea" at the time, so we can use PINB instead of the structure you've outlined. Give people a choice and confuse them?

  • @strayling1
    @strayling1 3 роки тому

    If you let myDelay wrap around instead of resetting it to 0 you'd get 16M/1024/256/256 ~= 1/4Hz . Using 'if (++myDelay % n == 0)' in the test would be an easy way to vary the frequency. I think ...

    • @RalphBacon
      @RalphBacon  3 роки тому

      Yes, a good way of doing it.

  • @simonbaxter8001
    @simonbaxter8001 3 роки тому

    8:20 the first and last methods also needs to be |= otherwise they will clear bits 3 to 7 !

    • @jwconlew
      @jwconlew 3 роки тому

      should be ok I think.. .as OR-ing 0's preserves the underlying values ....... (1

    • @simonbaxter8001
      @simonbaxter8001 3 роки тому

      @@jwconlew No it won't! The point is that the first and last of those two methods writes the absolute value, not read the current register value and OR it with the new values! i.e. first one should read
      TCCR2B |= ((1

    • @jwconlew
      @jwconlew 3 роки тому

      @simon You are quite right. it should really have the compound OR operator thinking about it... however the datasheet says TCCR2B bits 3/4/5 are read only anyway, and the bits 6/7 should always be 0 under normal circumstances.. so the end result is safe, just not academically right

    • @simonbaxter8001
      @simonbaxter8001 3 роки тому

      @@jwconlew That's true. Its the academic content that concerened me. Don't want to be teaching young players bad habits!

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Mea culpa, not checking it out well enough. It's what happens when you try packing a few house-moving boxes AND create a video at the same time. Smacked wrist for me.

  • @fillempie1501
    @fillempie1501 3 роки тому

    by the way you have a little typo in the pcbway link.

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Thanks for the heads up, I better go and correct that! Thank goodness their PCBs are of a higher quality than my typing.

    • @fillempie1501
      @fillempie1501 3 роки тому

      @@RalphBacon :)

  • @fredflintstone1
    @fredflintstone1 3 роки тому +1

    Damn my brain hurts so close to christmas:-) your videos will be interrupted :-)

    • @RalphBacon
      @RalphBacon  3 роки тому

      Ho ho, you should be on stage with jokes like that!

    • @fredflintstone1
      @fredflintstone1 3 роки тому +1

      @@RalphBacon The broom was the only thing keeping me off :-)

  • @Mr.Leeroy
    @Mr.Leeroy 3 роки тому

    more on AVR C, thanks

    • @RalphBacon
      @RalphBacon  3 роки тому

      Oh my goodness, you want to move away from Arduino-speak C++, Leeroy? Good. Now install a better IDE whilst you're at it, such as PlatformIO unless you already have an IDE that isn't the Arduino one you use.

    • @Mr.Leeroy
      @Mr.Leeroy 3 роки тому

      @@RalphBacon I'm using Atom as external editor, works great for me. It's not that I want to move away from Arduino, I would love to use both and it's just that UA-cam is lacking quality info on advanced 328P programming, and your explaining style turns out to be very good for that. Yes there are attempts at AVR C on YT, but there are too many blind spots in them or they are too complex for Arduino crowd.
      Me personally would appreciate some general technics on how to approach and understand manufacturer datasheets for microcontrollers in a more efficient way to not be overwhelmed. at328p is a great candidate as an example.

    • @RalphBacon
      @RalphBacon  3 роки тому

      I'll bear that in mind for a future video, Leeroy. Datasheets are usually your best friend but can contain errors (gasp, shock, horror).

  • @superdau
    @superdau 3 роки тому

    You repeatedly said that the ISR gets called 15 thousand times a second, but that's false. The divider you set does not set how often the interrupt routine gets called. It sets how often the timer counter ticks up. Since you are using the overflow interrupt on an 8-bit timer you have to divide by 256 again to know how often the ISR is called.

    • @RalphBacon
      @RalphBacon  3 роки тому

      Yes, you're not the first to mention this, and I was (for some unfathomable reason) getting my timer ticks and interrupt ticks mixed up. I blame it on the house move packing. All will be good in the end, I'm sure.

  • @automation_jeff
    @automation_jeff 3 роки тому

    Ralph, I hope your doing well. I just managed to check back with you on your videos, I gathered you were or in the middle of moving and looks like you had an issue with your eye a while back? I don't know if your back up and running again, I wanted to ask if you have any intention of reviewing or have reviewed the new Arduino Pro Portenta H7 board? It's a bit pricey, but has quite a bit packed into it. It looks like Arduino is focusing on industrial applications? I just ran across it and wanted to see if you had looked at this or not? store.arduino.cc/usa/portenta-h7

    • @RalphBacon
      @RalphBacon  3 роки тому

      I haven't looked at it, Jeff, and you're right, is it pricey. But for industrial applications it may well be worth the robustness and in-built micropython capability. As Arduino won't give me one, I'm not buying one just to fiddle with it! And, as you said, I am STILL surrounded by house-moving boxes awaiting my house move. Not only that, I STILL have eye issues, awaiting a further op! It just never ends!

    • @automation_jeff
      @automation_jeff 3 роки тому

      @@RalphBacon Sorry to hear that you've still having eye issues. I know how that goes, I just had cataract surgery. Ya this Portenta is up in the PLC price ranges.

    • @RalphBacon
      @RalphBacon  3 роки тому

      I hope your cataract replacements serve you well. Unfortunately for me, the membrane behind the lens (now holding the lens in place) has become cloudy/smeary in my left eye too and needs lasering just enough so I can see but not too much that the replacement lens falls out! Today's the day!

    • @automation_jeff
      @automation_jeff 3 роки тому

      @@RalphBacon My cataract surgery worked out, it's amazing how much brighter everything is now. I'm sure everything will workout for you as well, after all we need you up and making more of your very informative and entertaining videos.

    • @RalphBacon
      @RalphBacon  3 роки тому

      So here I am after laser surgery and things are looking clearer again. Still on the eye drops so hopefully things will settle down soon. Glad yours worked out well, Jeff.

  • @jeffmerlin2580
    @jeffmerlin2580 3 роки тому +1

    17:54 Really? if (++myDelay == 1) will always be true when myDelay is 0. The only thing you waste is the 'if' (but a smart compiler would probably remove it) ;-) What you should do is post-increment, not pre-increment. I'm sure you knew that, Ralph. :)

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Actually, that code was just copied from the next sketch (with the comparators) and I changed the 5 (or whatever) to a 1 but didn't really think about it. Doh! I wonder if the compiler did remove it? But on the bright side I have packed 6 more boxes today!!! In the rain!!!

    • @jeffmerlin2580
      @jeffmerlin2580 3 роки тому

      @@RalphBacon This is quite interesting. Without 'static' the compiler (GCC) removes the if statement, but with 'static' it does indeed put in a 'cmp $0x1, %eax' in assembly:
      void withStatic ()
      {
      static int myDelay = 0;
      if (++myDelay == 1) {
      printf("%d
      ", myDelay);
      myDelay = 0;
      }
      }
      Compiles to
      0x401156 add $0x1,%eax
      0x401159 mov %eax,0x2ed5(%rip) # 0x404034
      0x40115f cmp $0x1,%eax
      0x401162 je 0x401168
      0x401164 ret
      0x401165 nopl (%rax)
      0x401168 sub $0x8,%rsp
      0x40116c mov $0x1,%esi
      0x401171 mov $0x402004,%edi
      0x401176 xor %eax,%eax
      0x401178 call 0x401030
      0x40117d movl $0x0,0x2ead(%rip) # 0x404034
      0x401187 add $0x8,%rsp
      0x40118b ret
      and
      void withoutStatic ()
      {
      int myDelay = 0;
      if (++myDelay == 1) {
      printf("%d
      ", myDelay);
      myDelay = 0;
      }
      }
      compiles to
      0x40118c nopl 0x0(%rax)
      0x401190 mov $0x1,%esi
      0x401195 mov $0x402004,%edi
      0x40119a xor %eax,%eax
      0x40119c jmp 0x401030
      I guess it makes sense. A static variable is like a global variable except in this case is local to the function. Maybe GCC is not brave enough to optimize a static variable? :-)
      Edit: This is of course Intel assembly, but I bet it's the same story on Atmel

    • @RalphBacon
      @RalphBacon  3 роки тому

      I know that any variable with 'volatile' is not (usually) optimised away, perhaps the same with 'static'?

    • @jeffmerlin2580
      @jeffmerlin2580 3 роки тому

      Might be, Ralph. I think static variables is less likely to be optimised away because they are "kind of" global. The are allocated only once, even if declared in a function which is called multiple times. The live perfectly well outside the scope. I like to call them global variables with restricted usage.
      To be honest, I don't like static variables defined in a function (or another non-global scope). They are as global as they can be, and the only thing that prevents you from using them as global variables are the compiler. But wait! They are treated like global variables (by everyone except the compiler). Maybe we can do something bad? :-)
      Consider this code:
      #include
      void evil(int *);
      int * func ()
      {
      static int theStaticInt;
      theStaticInt = 1;
      return &theStaticInt; // Really, really bad practice
      }
      int main ()
      {
      int *anInt = func();
      printf("%d
      ", *anInt);
      evil(anInt);
      printf("%d
      ", *anInt);
      return 0;
      }
      The function evil() is defined in another c-file, compiled and linked. It's simply this:
      void evil(int * i) {
      *i = 10;
      }
      When you run the program you get this output:
      1
      10
      The function evil() gets the address of a static variable and alters it! This should not be possible, but the compiler cannot complain (because it doesn't know). The linker doesn't care. :-)

    • @RalphBacon
      @RalphBacon  3 роки тому +2

      Now that is pure static variable abuse, Jeff. I'm sure there's a law against doing that. 😁 But in normal use, static variables with their limited scope are much safer than random global variables being updated and read by all and sundry. It's either that or passing variables as pointers, which puts off my viewers.

  • @johnkunze5362
    @johnkunze5362 7 місяців тому

    Timer2 reg2

    • @RalphBacon
      @RalphBacon  6 місяців тому

      You'll need to expand on the point you were making there, John. Timer 2 uses a different register?

  • @ForwardGuidance
    @ForwardGuidance 3 роки тому

    What's that? You in the back ....

    • @RalphBacon
      @RalphBacon  3 роки тому

      Stop talking and pay attention or I'll move you to the front! Ha ha, proper teacher mode!

    • @ForwardGuidance
      @ForwardGuidance 3 роки тому

      @@RalphBacon LOL! Loving your content Ralph. Time to get another cat, Ralph. We need one walking all over your workspace.

    • @RalphBacon
      @RalphBacon  3 роки тому +1

      Too soon yet, and we're moving house anyway. Maybe next year. But that will mean more C++ interviews and aptitude tests for the candidates. Purrfect.

  • @fillempie1501
    @fillempie1501 3 роки тому

    Not moving to a retirement home are you?

    • @RalphBacon
      @RalphBacon  3 роки тому

      Funny you should say that, it's a small place with a caretaker right next to the crematorium so they won't have too far to take us. The let us out once a week to stretch our legs then back to the board games and a snooze. Waiting for God, I call it.

    • @fillempie1501
      @fillempie1501 3 роки тому +1

      @@RalphBacon Wow sounds exciting :)

  • @fwily2580
    @fwily2580 Рік тому

    Repeat yourself much?

  • @henrikjensen3278
    @henrikjensen3278 3 роки тому +1

    Oh-oh, that was not your best video! You probably had to little time, due to the moving.
    1) You do not include anything about the actual timer count, i.e. up to 256 for a 8 bit timer. The interrupt frequency is clock/prescaler/timerCount.
    2) Using compare interrupt do not change the interrupt frequency, usually you can do everything in the timer interrupt, without using compare interrupt, just with a couple of different counters.
    3) ++myDelay==1 is true when myDelay is zero!
    4) |= is not the operator to use for toggling bits, ^= works better.
    Why not 3D print a box for the radio, it is cheaper and much easier than try to find a good box. After I got a 3D printer I have stopped buying small plastic boxes for projects, instead I print them with all the needed cutouts, studs, etc. No trouble mounting a display without visible screws and a perfect sized cutout for it.

    • @jwconlew
      @jwconlew 3 роки тому

      I too was confused by the |= operator used here, but as a newbie, I had to go and check by playing on my Uno .... and indeed it does toggle, whereas ^= will not.... this is because of a "feature" as described briefly in the 13.2.2 line in the Atmel datasheet;
      13.2.2 Toggling the Pin
      Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of DDRxn.

    • @RalphBacon
      @RalphBacon  3 роки тому

      @Henrik
      1) I most certainly mentioned the 255 max count for an 8-bit counter (I asked "you at the back")
      2) I have no idea what you mean here. You realise I am showing how to do two compare interrupts here as well as overflow interrupts?
      3) Yes, OK, but this was from borrowed from the second sketch where I do actually count to beyond 1.
      4) |= toggles the bits (how else do you explain the sketch working)?
      I haven't got a 3D printer (yet). But I have got a nice box that I intend to use. One day I might be able to afford a decent 3D printer that doesn't required constant hand-holding and tweaking, print-bed levelling and a 4 Kg spool of printer material just to get a simple shape printed!

    • @henrikjensen3278
      @henrikjensen3278 3 роки тому

      1) Yes you did, but when you talked about interrupt frequency you did not include it.
      2) For showing multiple interrupt handles you example is fine, but all of them will happen at the same frequency.
      4) Jason Wheeler explained my mistake, I have always used PORTB for changing output and not PINB
      Another place where I like using interrupt is the ADC, when I need to average the input. It is easy to do a couple of samples (like 64 in a uint16_t) and then update a result variable and a flag.
      A cheap 3D printer is not that hard to use and you can get cheap models with auto leveling. I have made a parameter controlled box in FreeCad and it takes me less than a minute to design a box, then I use some time on adding holes and stuff in the program. Printing takes a couple of hours for each part (top/bottom) and I can directly mount everything in the box. Before the printer mounting display without visible screws and making holes for USB connectors was difficult, now it is not.
      You can see one of my boxes for this project: lygte-info.dk/project/Charger%20UK.html

    • @RalphBacon
      @RalphBacon  3 роки тому

      I will be picking your brains on 3D printers next year, Henrik, that's for sure.

    • @henrikjensen3278
      @henrikjensen3278 3 роки тому +1

      You are welcome, there is an email address on my website.
      I am hoping to publish my 3D box model, but I will wait for next official version of FreeCad, the current one has some serious issues with parameter control.

  • @TruthDigest
    @TruthDigest Рік тому

    with all my respect to your efforts , but the way you are presenting ideas is not well organized, you are jumping from one point to another one and then come back again , it is not an organized presentation. I'm sorry good luck bro