Giter VIP home page Giter VIP logo

stm32_micro_second_delay's Introduction

STM32_Micro_Second_Delay

Intro :

This project create us-delay with timer Made with STM32CubeMX with STM32CubeIDE Toolchain Selected microcontroller is STM32F4xx and HAL library has been used. (for other microcontrollers, just repalce library)

Clock configuration :

Clock configured 168MHz with PLL (maximum for my microcontroller,you can use any clock-rate):

Clock settings

Create Project :

TIM1 settings:

TIM1_Settings

Just set clock source, internal clock

PSC set at 167 ((Used-Clock/1,000,000)-1) and counter period at maximum Value.

attention: for other Used-Clock, just modify PSC.

Code algorithm :

Algorithm is so simple:

First start the timer (in this code, Timer 1),

HAL_TIM_Base_Start(&htim1);

Then reset CNT value,

htim1.Instance->CNT=0;

And wait for CNT to reach us(input) value (with while).

while(htim1.Instance->CNT < us);

Result :

In main function, toggle GPIOE port, pin 15 every 20 micro-second and result:

monitor

Notes :

Accuracy :

Result was not exactly 20us because HAL-library functions have a delay itself and if it was very large, you can calibre it manually:

For example if we want 40us delay and every time we got ~42 us, write this code before the while:

us -= 2;

Other method :

Also you can library to make us-delay with HAL-library functions delay rather than Timer.

For example, write this code and monitor the delay and calibre it with changing the value to make one us delay :

void us_delay(int us){
value = 10000;
delay = us * value;
for(int i;i < delay;i++);

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.