How to use a microcontroller's analog to digital converter

Sdílet
Vložit
  • čas přidán 24. 07. 2024
  • Analog to digital converters (ADCs) are very useful tools for converting voltages into numbers.
    In this tutorial we will learn how to use the 10-bit ADC module of the PIC16F1455 microcontroller: we will connect it to a potentiometer and use it to control the brightness of an LED. Check out the companion article on my website for more details and an up-to-date list of all components: www.friendlywire.com/tutorials...
    Thanks for tuning in, and let me know in the comments if you have any questions!
    Website: www.friendlywire.com
    Twitter: / friendlywire
    Reddit: / friendlywire
    Facebook: / friendlywire
    Instagram: / friendlywire
    Timestamps:
    0:00 Introduction
    0:56 Part 1: The main idea
    2:23 Part 2: Programming and flashing the PIC16F1455
    7:44 Part 3: Schematic and building the circuit

Komentáře • 56

  • @Akos_V
    @Akos_V Před rokem +3

    Thank you so much, these videos got me started with microcontrollers. It is a massive help

    • @FriendlyWire
      @FriendlyWire  Před rokem +1

      Thank you, and I am so happy to hear that! :)

  • @mikko-mattikurppa4779
    @mikko-mattikurppa4779 Před rokem +2

    Thank you for this awesome tutorial video. You are great teacher. I'd like to hear why you prefer using IPE for programming, instead of using make and program device button. I mean maybe there are some benefits that i do not know of? You can also enable power target circuit from pickit3 in MPLAB X ide. Right-click active project folder and select properties: make sure that pickit 3 is connected hardware tool. Select pickit 3 (left), option categories --> power. Enable and select voltage. Ipe is much clearer though and propably the best way to teach.
    I'm addicted to your professional and well-made videos. And what's best i think is your website. This is just pure gold. Hope this channel grows ALOT.

    • @FriendlyWire
      @FriendlyWire  Před rokem

      Thank you so much for your kind words, Mikko-Matti! For some reason the IDE's interface with the PICkit3 would not work reliably for me and my setup, whereas for the IPE it always works fine. I will be sure to give it another try some time, I hope it's not too confusing for beginners. Thank you again, and have a fantastic week!

  • @anokhautomation4453
    @anokhautomation4453 Před 2 lety +1

    Very very useful tutorial 👍 thanks for your detailed demonstration 🙏

    • @FriendlyWire
      @FriendlyWire  Před 2 lety

      Thank you so much, glad you like the video! :)

  • @mrengtop
    @mrengtop Před 7 měsíci +1

    This is realy good & clear explanation... Thank you..👏👏👏

    • @FriendlyWire
      @FriendlyWire  Před 7 měsíci

      Thank you, I am glad you found it helpful! :)

  • @VintageProjectDE
    @VintageProjectDE Před 4 lety +2

    A really neat little project for an intro to ADC!
    One hint towards those breadboard PSUs: It's worth checking polarity before plugging them into the breadboard. It's very convenient to have them matched + to red and - to blue. The other way round, not so much. (Yes, happened to me. Didn't find it at first.)

    • @FriendlyWire
      @FriendlyWire  Před 4 lety

      Thanks! I have never seen a breadboard PSU with inverted polarity, but I will make sure to mention it in a future video! Thankfully the polarity is printed on the PCB and you can see it at 8:35 so it is hopefully not too confusing :)

    • @science.20246
      @science.20246 Před rokem

      @@FriendlyWire ١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١١111

  • @FriendlyWire
    @FriendlyWire  Před 4 lety +3

    Here is the overview:
    Part 1, The main idea: 0:57
    Part 2, Programming and flashing the PIC16F1455: 2:24
    Part 3, Schematic and building the circuit: 7:45

  • @mqi7269
    @mqi7269 Před 3 lety +1

    Very good Present, Thank you

    • @FriendlyWire
      @FriendlyWire  Před 3 lety

      Thank you so much, I am happy you like it! Is there anything about microcontrollers you want to see next here on the channel? I am always looking for new ideas :)

  • @Mr_Motor
    @Mr_Motor Před 2 lety +1

    your premium content deserve more views

  • @lcohen2981
    @lcohen2981 Před 4 lety +3

    Thank you for these videos, they are so helpful! Particularly to someone like myself who has no previous experience. I was wondering what programming languages you can use to write the code for pic microcontrollers. Any suggestions?

    • @FriendlyWire
      @FriendlyWire  Před 4 lety

      Thank you for tour nice words, I am happy that the videos are helpful to you, it means a lot!
      I only use C to program PIC microcontrollers, and the compiler is called XC8 (and, with certain optimizations switched off, it is free to use). You can check out my PIC introduction video and my website www.friendlywire.com for more information on this. It is of course also possible to program directly in machine language (assembler), but for simple projects that are not time critical it is hardly necessary.
      Not sure if there are other dialects you could program PIC microcontrollers with, for me C has always been the language of choice :)

  • @anokhautomation4453
    @anokhautomation4453 Před rokem +1

    Nice tutorial 👍. shall we do it with pic 16f627A also??

    • @FriendlyWire
      @FriendlyWire  Před rokem

      Sadly, the PIC16F627A does not have an ADC module built in, so it does not work in that case.

  • @Rafea_alshehry
    @Rafea_alshehry Před rokem +1

    Can I use PIC16F628A?
    I need a piece other than PIC16F1544, can I exchange it for any other item? I hope you mention an alternative to it

    • @FriendlyWire
      @FriendlyWire  Před rokem

      This tutorial is specifically for the PIC16F1455. The PIC16F627A and PIC16F628A do not have built-in ADC modules, unfortunately, so you cannot use them for this purpose. Do you have other chips available? The PIC16F1459 may be a good choice, too. Let me know, and I am happy to help :)

  • @anithasshenoy6662
    @anithasshenoy6662 Před 5 měsíci +1

    MPLAB has an online facility called MPLAB xPress. we can do the programming on it. However it doesn't show PICKIT3 or 2. I tried this code on it. It did well and produced the hex file too. One thing I noticed is, when choosing the type of file, it shows only C. There is no assembly. Any idea on this ?

    • @FriendlyWire
      @FriendlyWire  Před 5 měsíci +1

      PICkit2 and 3 are deprecated and no longer officially supported by MicroChip, this is probably why they don't show. It's a bit of a shame since the PICkit3 is all you really need for basic hobby electronics. I was not aware of the online tool, interesting. I use the MPLAB X software on my computer, so that it does not require an internet connection.
      At what point do you choose a file type? The source code on my websites is written in C.

    • @anithasshenoy6662
      @anithasshenoy6662 Před 5 měsíci

      @@FriendlyWire It is sad that they deprecated Pickit 2 & 3. Pickit4 is damn costly here. Can't buy it at this point.
      There is one disadvantage with the online facility. Once can do only one project at a time. Looks like it holds the files in a folder called sandbox. I suspect it holds the files only for three days. Some thing like that flashed on the screen.
      When I tried to open a new project, It deleted the already created one.
      But for beginners, it is a not a bad option.
      When I tried to create a new file it displayed three types - Header, c main , source file.
      So I believe it allows only C language.
      need to explore more.

  • @soumeya772
    @soumeya772 Před 2 lety +1

    Hello, first I wanna say this video was great and u did explain it very well, keep going!
    Now I have a question: can we create a ramp or triangular waveform using an ADC? and if this signal can do the job of the potentiometer like increasing the glowing and decreasing it ? ( I m using a pic32mk in my project )

    • @FriendlyWire
      @FriendlyWire  Před 2 lety +1

      Thank you! You are thinking of a DAC, a digital to analog converter, basically the opposite :) An ADC takes an analog voltage and turns it into a number. A DAC takes a number and outputs and analog voltage. If you want to dim an LED I would recommend using pulse width modulation (PWM) instead; you can check out my electronic candle video: czcams.com/video/pCvCan2yGZg/video.html If you are interested in generating specific waveforms, then the DAC is your tool of choice, but the built-in ones typically have a slightly lower resolution.

    • @soumeya772
      @soumeya772 Před 2 lety +1

      @@FriendlyWire thanks for explaining!

    • @FriendlyWire
      @FriendlyWire  Před 2 lety

      @@soumeya772 Of course, and let me know if you have other questions :) I may do a video on DAC's in the future.

    • @soumeya772
      @soumeya772 Před 2 lety +1

      @@FriendlyWire your video is gonna be so helpful! Thank u again for helping ^^)!

    • @FriendlyWire
      @FriendlyWire  Před 2 lety +1

      @@soumeya772 Thank you for your kind words, it means a lot :)

  • @anithasshenoy6662
    @anithasshenoy6662 Před 5 měsíci +1

    Thank you very much for presenting this in a simple and practical manner. I love it. Pic16F1455 is not available here. Can I use pic12f510 instead. It too have ADC.

    • @FriendlyWire
      @FriendlyWire  Před 5 měsíci +1

      The PIC12F510 can also be programmed with the same tools as presented in this video. But the code will be different, unfortunately, this is the disadvantage of there being so many different PICs :( Where are you located?

    • @anithasshenoy6662
      @anithasshenoy6662 Před 5 měsíci +1

      @@FriendlyWire India. Unless there is a huge demand, the vendors will not import the components. Once the stock is sold out, it may not be easy to get the same item again. There are international vendors like elements14. But they sell only to tax registration holders.
      pic16f1455 is 10 bit , while 12f510 is 8 bit. Hence the code will need to adjusted for 8 bit . right ? is there anything else I need to look out? thks

    • @FriendlyWire
      @FriendlyWire  Před 5 měsíci +1

      @@anithasshenoy6662 The problem with PIC controllers is that they all have a slightly different architecture (different register names etc) which makes it difficult to re-use code from one controller (like the PIC16F1455) and use it directly for another one, like the PIC12F510. More likely, we would have to re-write this from scratch.
      Do you have experience with PIC controllers? If not---which is totally OK---then I would suggest we start with making an LED blink first, and then move on to the ADC question. Let me know!
      We can chat on Instagram/Twitter or via email (address is at the bottom of www.friendywire.com).

    • @anithasshenoy6662
      @anithasshenoy6662 Před 5 měsíci +1

      @@FriendlyWire Thank you very much. I understand. I have been into electronics since my school days 50 years back and into software programming since 1985. This is not my profession now. I had stopped doing electronics some 30 years back. However , now that I have lots of free time , I started looking into it. I found that there is whole new world in MC. I am gathering the required equipments for the programming. I hope to get it by next week or so. Though I live in a big city, the local stores do not have the PICKIT3 or 3.5 and even the MC's. I wanted to order some of these MC's online , hence wanted to know a bit about them.
      I shall write to you , once I get those items and try my hand. Your video's are of great help. Thanks once again for your kind efforts.

    • @FriendlyWire
      @FriendlyWire  Před 5 měsíci +1

      @@anithasshenoy6662 Thank you for sharing, and I think you will have a lot of fun with microcontrollers, especially if you already have a background in coding. Regardless of whether you will use PICs or not, I am sure it will be a great experience.
      Yes, please get in touch when the items arrive, or if you want to chat about projects, I am always happy to help. :-)

  • @mariakitchen4182
    @mariakitchen4182 Před rokem +1

    Please can you do it using assemble code and lcd

    • @mariakitchen4182
      @mariakitchen4182 Před rokem +1

      Using atmega328p and output x axis and y axis

    • @FriendlyWire
      @FriendlyWire  Před rokem

      @@mariakitchen4182 That's a nice idea for a project. I don't work with assembler, though, for now. I will do an LCD tutorial very soon, stay tuned!

  • @cying6614
    @cying6614 Před 2 lety +1

    Do you guys have any ideas on how to save the digital values into a text file? Thanks

    • @FriendlyWire
      @FriendlyWire  Před 2 lety

      Good question! The easiest way I can think of, with the content I have online, is to use the RS232 tutorial to sent it to a computer. Then you need a program running on the computer that manages the incoming data. You can learn more about RS232 and how to use it on a microcontroller here: czcams.com/video/2T9ca53KMrM/video.html

    • @cying6614
      @cying6614 Před 2 lety +1

      @@FriendlyWire Thank you for your quick response. I appreciate it greatly. How about if this is a chip in an independent instrument which should save the data like temperature readings as text file in itself and when the computer is connected to the instrument via USB it then can read the data like from a regular USB fresh memory? Thank you

    • @FriendlyWire
      @FriendlyWire  Před 2 lety

      @@cying6614 Then you need a means of storage on the chip. Many PICs have an EEPROM memory that you can use, but that memory is limited. You could use an external EEPROM as well. Another alternative is to use an SD card adapter. These are fairly easy to write to, but managing the file system is a bit complicated if you want the data to be readable on a computer.

    • @cying6614
      @cying6614 Před 2 lety +1

      @@FriendlyWire Thank you very much

    • @FriendlyWire
      @FriendlyWire  Před 2 lety

      @@cying6614 Happy to help!

  • @swatcat7928
    @swatcat7928 Před 2 lety +1

    Good bless Arduino...

    • @FriendlyWire
      @FriendlyWire  Před 2 lety

      Ha, how so? I always believe that people should use the microcontroller that works best for them :)

    • @swatcat7928
      @swatcat7928 Před 2 lety +1

      @@FriendlyWire for been easy to learn..

    • @FriendlyWire
      @FriendlyWire  Před 2 lety +1

      @@swatcat7928 I know what you mean :) I find working with PICs very interesting, because we need to look at registers in the controller and have to try to program everything ourselves, and I like the challenge. Also, once you have bought the PICkit3 programmer for around $25, a PIC only costs $3 or so, so they can also be a bit cheaper than Arduinos in the long run. But to each their own :)

  • @jadidfekih
    @jadidfekih Před 3 lety +1

    Good 8-bits joke LOL

    • @FriendlyWire
      @FriendlyWire  Před 3 lety +1

      Ha, you're the first one to comment on that! :)

    • @jadidfekih
      @jadidfekih Před 3 lety +1

      ​@@FriendlyWire You both (you and 8-bit guy) are doing a great job, keep it up.

    • @FriendlyWire
      @FriendlyWire  Před 3 lety

      @@jadidfekih Thank you for your kinds words, I am glad you enjoy the videos! :)