#2. Setup Timer to generate Precise Delay || STM32F4 || LED Blink || NO HAL

  Рет қаралды 30,851

ControllersTech

ControllersTech

Күн бұрын

Пікірлер: 79
@m-electronics5977
@m-electronics5977 6 ай бұрын
Best videos that I found until now for CMSIS programming😊😊😊👍👍👍 Very clear speaking and good explanations. You must know very much about microcontrollers.
@richardvanwijngaarden8799
@richardvanwijngaarden8799 4 жыл бұрын
Thanks for all the STM32 projects you have made to date as they have been very educational. Please keep the no HAL projects coming! How about converting the SSD1306 project to no HAL?
@ControllersTech
@ControllersTech 4 жыл бұрын
yeah i intend to make more videos on NO HAL.. I will first cover the basic peripherals, and then move to the modules.
@manoftheday1
@manoftheday1 3 жыл бұрын
@@ControllersTech Thanks , waiting.
@fkaragoz
@fkaragoz 2 жыл бұрын
The guide is very clear and detailed. I have got and timing error in my STM32F746ZG. When I have checked the blinking rate with the oscilloscope I observed around 1.8 second delay instead of 1 second. This was due to the reset values of the RCC's PLLCFGR register. I have added a line of code for resetting the PLLCFGR register with 0's before setting the parameters and I finally got the 1 second delay. My take from this issue is that the reset values of the registers need to be considered when we are not resetting every register manually before setting them.
@serpico3w767
@serpico3w767 2 жыл бұрын
Can you please elaborate
@fkaragoz
@fkaragoz 2 жыл бұрын
@@serpico3w767 RCC peripheral’s PLLCFGR register which can be found in the Reference Manual of the related MCU was not 0x0000 0000. Its was something like 0x0000 0101. I have observed this in step by step debugging of the code with the STM32CubeIDE and also checked the default reset value of the register wirth the reference manual. So if you do not set the register to all zeros before setting the bits with OR statement you might get different value than you wanted to set. So I needed to clear the register before setting the bits.
@kazim.karabacak
@kazim.karabacak 4 жыл бұрын
❤️ from Turkey
@noweare1
@noweare1 4 жыл бұрын
You are a very good programmer. I had to smile when you said you'd rather shift 16 bits left instead of shifting 21 bits left. But you are correct you saved the time it takes to shift 5 bits. Do you prefer using register programming or using ST's HAL API ? One last question .. will you be advancing to robotic applications in the videos at some point ?
@ControllersTech
@ControllersTech 4 жыл бұрын
I prefer registers but things gets very complicated specially with arm Cortex series. HAL is easier approach but not so much optimised I might include more robotic stuff but not now. I still have more basic things to cover right now..
@elishaul4125
@elishaul4125 3 жыл бұрын
No words, just great video, thank you
@giupeppe6380
@giupeppe6380 Жыл бұрын
Thanks for your video, i have to make a project were i need the timer works in nanoseconds. Using every 72mhz of bluepill, with no prescale, i should have a precision of 13.8nanoseconds, what do you think? I am scared about Crystal 8mhz because I don't know if it is a bottleneck. I will use a photodiode that is very fast (5nanoseconds) to send value to stm32. Thanks again and keep up the good work!
@xuanangang6241
@xuanangang6241 Жыл бұрын
Thanks for this video. Can you make a video about timer at mode interrupt? I'm investigate about it, but I can't implement it yet!😢
@rsamurti
@rsamurti 4 күн бұрын
This clock configuration doesn't work properly with STM32 CubeIDE. Any suggestions regarding CubeIDE to do CMSIS based programming without using HAL?
@m-electronics5977
@m-electronics5977 6 ай бұрын
9:44 there I've a question: when we only write "1" with the "or" operator to the register or also without the "or" then the same result should be come out in my head. Because when we write a "1" and not 0b1: is that not the same? Because in 0b1 the zeros that are before the one are thinked before, but we don't need to write it. Is that also true when we write "1" as integer / decimal number in the register?
@ControllersTech
@ControllersTech 6 ай бұрын
OR operator is for addition.
@4valves551
@4valves551 2 жыл бұрын
hello sir...kindly make a video for systick timer in STM32 !!!!
@seifelkhouly9090
@seifelkhouly9090 2 жыл бұрын
Thanks for your helpful videos. I just have one concern. which is to set The UG bit in TIMx_EGR registers to update the registers. otherwise, the update will not going to happen until an overflow or underflow occurs. which could take a very long time if using the 32-bit register, and this is what exactly happened with me until I noticed that in the datasheet.
@serpico3w767
@serpico3w767 2 жыл бұрын
This tutorial worked for me, so can you please explain a bit(lol) more?
@justsomegamer4086
@justsomegamer4086 Жыл бұрын
hello, I am trying to do a similar program for 3 different LEDs using 3 different timers, I am using 2 16 bit timers and one 32 bit timer, the program works fine for the 16 bit timers with both LEDs blinking at different periods, but my other led which is using the 32bit timer does not blink it stays on for a long while and turns off. Could you explain the EGR register in more detail because I think this is the part I am missing in my code, thanks
@seifelkhouly9090
@seifelkhouly9090 Жыл бұрын
@@justsomegamer4086 sorry just noticed your comment. Do you still need help?
@justsomegamer4086
@justsomegamer4086 Жыл бұрын
@@seifelkhouly9090 figured it out boss, thanks
@elcaoista
@elcaoista Жыл бұрын
Great explain like programming.
@pravinkhatale
@pravinkhatale Жыл бұрын
Thanks sir , keep teaching ....
@gajos123456
@gajos123456 3 жыл бұрын
How do you know that you need to check bit UIF in TIM6->SR register?
@yefimvarshavsky4590
@yefimvarshavsky4590 3 жыл бұрын
Hello,Very good video. Could you please make a video of NO HAL timer delay based on interrupts? Thanks
@ControllersTech
@ControllersTech 3 жыл бұрын
how will delay with interrupt work ?
@markday3145
@markday3145 3 жыл бұрын
@@ControllersTech If you set the prescaler and ARR such that the ARR period is the delay you want, and configure the timer’s UIF interrupt, then the interrupt handler will fire at the end of the desired delay. For longer delays, compute the multiple of the ARR period, then decrement in the interrupt handler; when it gets to 0, your time is up. For example, make the ARR period be 1ms; then you can easily do Delay_ms() without blocking. I think there may be another counter that changes on every ARR period (on advanced timers only?); if so, that would be an alternative to a software counter.
@ControllersTech
@ControllersTech 3 жыл бұрын
Yeah i know about that but can we call it delay ? It is more of a period update, suited for some periodic function. Maybe be good for blinking LED but certainly can not be used for delay purpose
@tranthienan2655
@tranthienan2655 Ай бұрын
thanks very much for your turial
@markday3145
@markday3145 3 жыл бұрын
I’m curious why TIM6Config waits for UIF to be set? That’s going to end up waiting for 65536 microseconds (when the timer’s counter reaches the ARR value and is reloaded). AFAICT, you don’t need to wait after configuring timers (like you do with the oscillators and PLLs).
@ControllersTech
@ControllersTech 3 жыл бұрын
Yeah even i am not sure about that. I tried simple way and it wasn't running.. after i almost gave up on it, i went through the hal initialisation and there i saw that they were looking for this bit to update. I still don't know why though.. but it works with it. I will dig deep when i have some free time for this
@mahianabosszuallo9726
@mahianabosszuallo9726 3 жыл бұрын
@@ControllersTech The problem is actually that the prescaler only starts working after the next update event. It is written in the datasheet: "The new prescaler ratio is taken into account at the next update event." So basically after you start the timer the prescaler won't work because no update event happens until it reaches the ARR value. If you wait for the UIF flag to set (like in the video) that means you wait for the counter to count until it reaches 0xffff, with lower clock speeds and higher ARR values it can take a really long time (even minutes) for your program to move forward because it is stuck in the while loop. After you enable the timer you can generate an event by software with setting the first bit of the Event Generation Register (TIMx_EGR: Update generation) and then your prescaler will work. To summerize: if you change that while loop to: TIM6 -> EGR |= 1, you don't have to wait for a UIF event, your program can instantly proceed and your timer will work corretly. I hope i was clear. Thanks for your videos they help me a lot. :)
@thangavigneshc9785
@thangavigneshc9785 11 ай бұрын
Sir you have any idea about mm32f0020 timers , bcz I don't get any source to refer this controller
@minhtriet5989
@minhtriet5989 4 жыл бұрын
hello sir ! i have a question ? on this video, you dont use Hal library, configuraions,.. of stm32cubemx . So Can you send me the reference document related to the configuration sequence of registers ? tks you very much
@ControllersTech
@ControllersTech 4 жыл бұрын
The reference document is the reference manual of your controller. Watch the video properly as i have explained each and every step for configuration
@mprone
@mprone 4 жыл бұрын
what's the difference between uVision and CubeIDE ? Can I use cubeIDE to execute this same exact code with the same result ? (I apologize for this silly question, just a noobie in Embedded Software)
@mprone
@mprone 4 жыл бұрын
@@hjvanderlinden So basically both cube and keil can do the same job (with slight differences) ? In other words , they are two "equivalent" alternatives for ST like, for example, eclipse and NetBeans are two IDEs for Java?
@nguyenvu6371
@nguyenvu6371 3 жыл бұрын
@@mprone STM32CubeIDE is free. In fact you can, program stm32 or any Arm on you fav IDE if you know how to write linker script (.ld file), startup script (.s file) and makefile (using cross compiler to compile your code). I heard you can develop arm projects on vscode using PlatformIO but my friend said he couldn't upload code to microcontroller while using that extension. I haven't tried it yet.
@GermanoCavalli1
@GermanoCavalli1 4 жыл бұрын
Nice project!!! Have you ever thought about taking a course at Udemy? Beginner to advanced in barel metal course
@GermanoCavalli1
@GermanoCavalli1 4 жыл бұрын
@@ControllersTech I was telling you to create a course, you have a lot of knowledge and you are a great teacher
@ControllersTech
@ControllersTech 4 жыл бұрын
Ok I'll take the compliment and delete my comment. KZbin is fine.. maybe in the future I'll think about it.
@yadniksn6657
@yadniksn6657 4 жыл бұрын
Nice tutorial. I watch ur entire vdo and write same program for my STM32F401RE. Here u have used timer6 and bus having 90 Mhz frequency for timer peripherals. In my case, I'm using timer3 and bus having 84 Mhz for timer peripherals. I set all register according to ur vdo and code is also working properly. But time delay is not exact. In your vdo, when u pass millisecond, seconds value it produces exact delay. In my case it takes 7 second OFF and 6 second ON when i pass 1000 in delay_ms() function. And it is not exact for micro-second as well. What could be problem ? I watched ur vdo many times but not able to point out, whats going on with my code. Plz give some suggestion about it. Your any answer will be appreciable.
@ControllersTech
@ControllersTech 4 жыл бұрын
Did you saw the first video and did the setup accordingly. The 84 MHz clock is only valid if you have set it up for 84 MHz.
@yadniksn6657
@yadniksn6657 4 жыл бұрын
@@ControllersTech Thank you for ur fast reply. Yes I did same as u explain in both vdo's. As a beginner i type each word one by one and for cross check i also download the code provided by u from ur website. After selecting max frequency i.e 84 Mhz for my 401RE board in CubeMX I noticed these values, if wrong correct me. PLL_M - 4 PLL_N - 84 PLL_P - 0 // PLL_P 2 SYSCLK - 84 Mhz AHB PRESCALAR - 1 HCLK - 84 Mhz APB1 PRRSCALAR - 2 APB1 Timer clock frequency is 84Mhz. I'm using Timer 3 for my delay code. These are the values I have set in my code according to ur instructions. Code is running but delay is not perfect. Plz, i request u to choose 401RE Board in your CubeMX and tell me where I'm going wrong.
@ControllersTech
@ControllersTech 4 жыл бұрын
Mail me or use telegram to send the code
@karthikps3892
@karthikps3892 3 жыл бұрын
There is trick, set the same frequency value for the timer prescale, and you will get 1Mhz(1us) as output.
@thisismazhar
@thisismazhar 3 жыл бұрын
Hi...I am using stm32f407 discovery board. @168mhz. I have done everything right but my LED blinking delay is about 5 seconds, where as it should be 1 second.
@ControllersTech
@ControllersTech 3 жыл бұрын
I need to see the code.. contact me on discord
@justinvuong8161
@justinvuong8161 3 жыл бұрын
What was the fix to this? I am having the same problem and would appreciate any guidance. I am using stm32f767zi.
@ControllersTech
@ControllersTech 3 жыл бұрын
I don't remember exactly but i guess it could be due to because he was keeping the input clock at 25MHz, though his board had the 8 MHz input crystal.
@justinvuong8161
@justinvuong8161 3 жыл бұрын
@@ControllersTech Thanks for the quick reply. After some investigation, it turns out that the Nucleo board that I have has a 25 MHz external clock as you described. Thanks so much for your help and videos!
@muratarslan7122
@muratarslan7122 4 жыл бұрын
more NO HAL FTW.
@eamonhannon1103
@eamonhannon1103 3 жыл бұрын
Very good
@epat4706
@epat4706 4 жыл бұрын
You use an 8 MHz external crystal but the external crystal position is empty?
@ControllersTech
@ControllersTech 4 жыл бұрын
It's there on the top. Shared between st link and the mcu
@skvalavideo
@skvalavideo 2 жыл бұрын
Hello sir how I reset the timer value to zero after stop when reaching a desired value . When I stop the timer at a certain value then again start the timer ,the timer start from previous value not from zero what to do.
@ControllersTech
@ControllersTech 2 жыл бұрын
Tim->cnt = 0
@majesty-4246
@majesty-4246 2 жыл бұрын
how to make the output will be on for 10 minutes?
@ControllersTech
@ControllersTech 2 жыл бұрын
Turn the LED on and give the delay of 10 min 🤷
@m-electronics5977
@m-electronics5977 6 ай бұрын
11:32 why we don't simply shift a "0" 5 Bits to left with "or" operator?
@ControllersTech
@ControllersTech 6 ай бұрын
You clearly don't know how bitwise operations work. Please read the topic. OR is used for addition. Adding 0 does not has any effect on the bit.
@m-electronics5977
@m-electronics5977 6 ай бұрын
@@ControllersTech that is really true I think now. 😅 When I do OR with a zero and a 1 is in that bit -> the one doesn't change. When I use AND with a zero and a 1 is in that bit -> the result won't become true, so a 0 is written in the register bit. 😊 But why we invert a 1 to a zero with the tilde? And don't use directly a zero?
@albinsclassroom8388
@albinsclassroom8388 Жыл бұрын
Can i give counter value directly in arr register . for examble tim2->ARR =1000;
@ControllersTech
@ControllersTech Жыл бұрын
CNT register holds the current counter value. ARR register hold the maximum counter value allowed. Thee CNT value is compared with the capture compare register (CCR), and relevant operation is performed.
@m-electronics5977
@m-electronics5977 6 ай бұрын
14:27 but Stop! When the timer runs at 1 MHz I learned wie can't count longer then 65,535 ms? How we count then so long? Or I have a brain failure maybe?
@ControllersTech
@ControllersTech 6 ай бұрын
We are not directly counting here. Check 08:28, there is another function. Also it's not 65535 ms, it's 65535 counts. There is a difference between both. If each count takes 1us, then max counts will be 65535 us. If each count takes 1ms, the it will be 65535ms. The counter resets after reaching this value.
@m-electronics5977
@m-electronics5977 6 ай бұрын
@@ControllersTech oh, misunderstanding of my format. I mean with the comma really a comma. Then I must write so: 65.535 ms is the max counting value with 1 MHz. But I understand it yesterday after a little bit time goes over after the video. How you realize the ms delay, we don't need to count over 1ms. Because we use a delay from the other function for that....🙂
@4valves551
@4valves551 2 жыл бұрын
i cant set the clock frequency in target option . its shows undefined on that position. here im also using mdk v5. please give the solution sir....
@ControllersTech
@ControllersTech 2 жыл бұрын
Don't set it then. Try without that
@karthikps3892
@karthikps3892 3 жыл бұрын
You have done a mistake bro...check the APB1, it is 45Mhz and you are selected 90 for pre scaling. 45 is correct for pre scaling.
@ControllersTech
@ControllersTech 3 жыл бұрын
Apb1 timer clock..
@karthikps3892
@karthikps3892 3 жыл бұрын
@@ControllersTech TIM6 ->PSC = 45-1; ... this is correct
@ControllersTech
@ControllersTech 3 жыл бұрын
Not APB1 peripheral clock.. look at APB1 timer clock.. they are different
@nguyenvu6371
@nguyenvu6371 3 жыл бұрын
@@karthikps3892 He was right. He used APB1 prescaler = 4. HCLK was 180Mhz => PCLK1 = APB1 peripheral clocks = 180/4 = 45Mhz while APB1 Timer clocks = (180/4) * 2 = 45 * 2 = 90Mhz. You should revisit 3:17. TIM6->PSC scales the APB1 Timer clocks, which is 90Mhz, not APB1 peripheral clocks (which is 45Mhz).
@4valves551
@4valves551 2 жыл бұрын
i cant set the clock frequency in target option . its shows undefined on that position. here im also using mdk v5. please give the solution sir....
@ControllersTech
@ControllersTech 2 жыл бұрын
Try without setting that.. i guess it works alright
@4valves551
@4valves551 2 жыл бұрын
@@ControllersTech ok sir
#4. STM32F4 I2C Using Registers || Master mode || NO HAL ||
27:56
ControllersTech
Рет қаралды 25 М.
小蚂蚁会选到什么呢!#火影忍者 #佐助 #家庭
00:47
火影忍者一家
Рет қаралды 71 МЛН
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 3,7 МЛН
小路飞嫁祸姐姐搞破坏 #路飞#海贼王
00:45
路飞与唐舞桐
Рет қаралды 28 МЛН
She's very CREATIVE💡💦 #camping #survival #bushcraft #outdoors #lifehack
00:26
4. How to create a precision delay with stm32 timer
17:21
CMTEQ
Рет қаралды 2,1 М.
STM32 Guide #2: Registers + HAL (Blink example)
30:02
Mitch Davis
Рет қаралды 201 М.
How to create delay in nano/micro seconds using timers in stm32
7:41
ControllersTech
Рет қаралды 47 М.
Tutorial on STM32 External Interrupts and callback funktions
24:31
#3. How to Configure UART using REGISTERS || STM32F4
25:31
ControllersTech
Рет қаралды 38 М.
Stm32 Delay Using Timers or Systick
24:42
Eddie Amaya
Рет қаралды 36 М.
RP2040-Zero. как альтернатива Arduino Nano
15:46
arduinoLab
Рет қаралды 21 М.
How to Blink a LED | #5 STM32 GPIO output
24:41
Terminal Two
Рет қаралды 57 М.
How Do Computers Remember?
19:32
Sebastian Lague
Рет қаралды 6 МЛН
iPhone 16 Vs S25 ultra💀
1:01
Skinnycomics
Рет қаралды 6 МЛН
Телефон - самая грязная ваша вещь
0:24
Up Your Brains
Рет қаралды 2,2 МЛН
Последствия выхода Айфона 16
0:23
ТРЕНДИ ШОРТС
Рет қаралды 6 МЛН
iPhone теперь БЕСПОЛЕЗНО воровать 🛠
0:25
Technodeus
Рет қаралды 1,2 МЛН