Coder Social home page Coder Social logo

khoih-prog / megaavr_slow_pwm Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 132 KB

This library enables you to use ISR-based PWM channels on Arduino megaAVR boards, such as UNO WiFi Rev2, AVR_Nano_Every, etc., to create and output PWM any GPIO pin. It now supports 16 ISR-based PWM channels, while consuming only 1 Hardware Timer. PWM channel interval can be very long (ulong microsecs / millisecs). The most important feature is they're ISR-based PWM channels, supporting lower PWM frequencies with suitable accuracy. Their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These ISR-based PWMs, still work even if other software functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software-based PWM using millis() or micros(). That's necessary if you need to control devices requiring high precision. Now supporting MegaCoreX.

License: MIT License

C 62.15% C++ 37.50% Shell 0.35%
megaavr nano-every uno-wifi-rev2 isr pwm on-the-fly pwm-driver duty-cycle timer-interrupt hardware-timer

megaavr_slow_pwm's People

Contributors

khoih-prog avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

huynhsi681988

megaavr_slow_pwm's Issues

Minimal example for running PWM with custom frequency

Hi,

I am quite new to arduino and need to run PWM with a custom frequency on a pin in a precisely timed fashion at a slow frequency (30/100Hz) on an arduino nano every in an experimental setup (I work in a neuroscience lab).

I guess this toolbox could help doing so, I am however a bit confused by the provided examples which are relatively complex.

I for instance managed to do something similar on an arduino uno using the Arduino PWM Frequency Library (which is unfortunately not compatible with arduino nano every). Using this library, I was for instance able to run PWM at 100Hz with a duty cycle of 50% on pin 3 using:

#include <PWM.h>
#define PIN_PWM 3
int32_t FREQUENCY = 100;  // frequency, Hz
byte DUTY_CYCLE = 128; // 0-255, 128 corresponds to a 50% duty cycle

void setup(){
  InitTimersSafe();
  bool success = SetPinFrequencySafe(PIN_PWM, FREQUENCY);
  pinMode(PIN_PWM, OUTPUT);
}

void loop(){
  // Start PWM on PIN_PWM
  pwmWrite(PIN_PWM, DUTY_CYCLE);
  delay(1000);
  // Stop PWM on PIN_PWM
  digitalWrite(PIN_PWM, LOW);
  delay(1000);
}

Would it be possible to provide a similar minimal example for setting up the frequency/duty cycle and running/stopping PWM on a given pin ? Or did I misunderstand the purpose of this library and should I use a different one ?

Thanks !

rfayat

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.