Giter Club home page Giter Club logo

time-prescaler's Introduction

Time Prescaler

What is it?

Time Prescaler is a library that helps you prescale time. The most common use case is low-frequency signal generation, using timer interrupt as a signal source. Says, if you want a 10Hz signal from 1kHz timer interrupts, this library is a perfect fit for you.

Compatabilities

The library will work anywhere as long as the C language works. The author of the library uses it on STM8 devices, but it should run fine on AVR, PIC, MCS-51, etc. If it is not, please open an issue on GitHub, you just found a bug.

How to use this?

Just include the header to your project.

#include "time_prescaler8.h"

Declaring the function to be called periodically.

void periodic_function(void) {
  // do something
}

Setup an instance

const TimePrescaler8_Config prescaler_config = {
    // point to the function we declared earlier
    .target = &periodic_function,
    // we want 10Hz from 1kHz so we scale it by a factor of 100
    // 0x100 is a constant depict an overflowed conter value
    .reload_value = 0x100 - 100
};
static TimePrescaler8_State prescaler_state;

// somewhere in main()
time_prescaler8__init(
  &prescaler_config,
  &prescaler_state
);

And lastly, hooks the source signal

void timer_overflow_isr() {
  time_prescaler8__tick(
    &prescaler_config,
    &prescaler_state
  );
}

License

Time Prescaler is released under the BSD 3-Clause License. ๐ŸŽ‰

time-prescaler's People

Contributors

midnight-wonderer avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.