PIC MCU TUTORIALS #12 - Delays & Built-in delay functions (Absolute Beginner)

Поділитися
Вставка
  • Опубліковано 22 жов 2024

КОМЕНТАРІ • 11

  • @luannewatson9195
    @luannewatson9195 Рік тому +2

    Very easy to understand,...Thank You

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

    The best explanation for dealy function. Thank you.

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

    Fantastic explanation, super clear

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

    Thank you for the absolute noob spoon-feed! Really insightful! Got mine to run off a picket 4 on a pic10f200. Haven't been able to run blinking LED off of independent source, it only runs while connected to the picket. Have prepared a separate bread board to run off a 5v supply as suggested in your previous video.

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

      Thanks 👍 The microcontroller should run just fine after disconnecting the programmer. If it isn't, make sure you're actually uploading your code and not debugging. If you upload a debug build, the microcontroller won't run without the programmer. Also, make sure the MCLR pin is either disabled or connected to Vdd with a pull-up resistor so it doesn't stay in reset when the programmer is disconnected.

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

    Keep making videos bro

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

    You saved me a lot of time. Thank you!

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

    What is the built-in function for pic24fj128ga704

    • @Microesque
      @Microesque  6 місяців тому +1

      PIC24 are 16-bit microcontrollers, so the process is a little different. This is why I try to tech how to read datasheets and manuals. Answers to questions like these will almost always be somewhere in the user's guide of the compiler. I've included a short and a long answer below. I recommend reading both, but it's up to you 👍
      -------------------------------
      *Short answer:*
      -> Define the "FCY" macro as the instruction frequency of your microcontroller, so for 10MHz: _"__#define__ FCY 10000000UL"_
      -> Include the "libpic30.h" library in your code: _"__#include__ "_
      -> Now you should be able to use the same "__delay_ms()" and "__delay_us()" functions. Be careful, you need to define "FCY" before including the library!
      -------------------------------
      *Long answer:*
      -> If you open the XC16 user's guide ( ww1.microchip.com/downloads/en/DeviceDoc/50002071K.pdf ) and go to page 63, there is a section for "How Can I Implement a Delay in My Code?". There, it tells you that there are library functions, but you have to download it to use them. It also directs you to another manual dedicated to 16-bit libraries for XC16.
      -> If you open the 16-bit libraries document ( ww1.microchip.com/downloads/en/DeviceDoc/16-Bit-Language-Tools-Libraries-DS50001456K.pdf ) and read the introduction etc, it tells you that the XC16 comes with the libraries pre-installed already. You just have to explicitly include them in your code.
      -> Now you can just search the term "delay" in the page to see your options. After finding the function you're looking for, it tells you which library you have to include, the signature of the function, and also a general description. I recommend you glance over some of the functions, as there are a lot of convenient ones that may catch your eye 👍

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

    How about delay of 120 seconds

    • @Microesque
      @Microesque  Рік тому +2

      A single delay function in the XC8 compiler can only delay the microcontroller for at most 50,463,240 instructions. For longer delays, you need to use multiple delay functions. If the delay you want is very large, use a for loop, like 10:02 in the video with a large delay. I must have forgotten to add this limitation when making the video. For a better explanation, read below:
      -------------------------------------------
      The XC8 Compiler User's Guide states that the "_delay()" function can't delay for more than 50,463,240 instructions (page 348). This likely exists as a result of the way this delay function is implemented in the compiler. Don't forget that the "__delay_ms()" and "__delay_us()" functions calculate the instructions needed to achieve a given delay, then call the "_delay()" function with it (you can see it in 3:24). So, if you're running the microcontroller at 64MHz, the highest delay you can generate using the "__delay_ms()" function is 3153ms.
      -> Calculation: (50463240*1000)/16000000 = 3153
      - 50463240 is the maximum instructions.
      - 1000 is the conversion from seconds to milliseconds.
      - 16000000 is the instruction frequency.
      (This also means that the maximum delay you can generate is affected by your instruction frequency.)