Code Monkey home page Code Monkey logo

pwm's Introduction

PWM library

This library allows you to use any available timer to produce a PWM output. The design intent is to control the pulse width and PWM period, with a maximum range of supported frequencies. It uses the Fast PWM method, but this may change to include the Phase correct PWM method.

ATtiny85 BUG - ATtiny85 datasheet errata (section 27.2.3, page 213) PWM output OC1B does not work correctly unless COM1A1 and COM1A0 are set to the same value as COM1B1 and COM1B0 respectively.

This is handle internally by the PWM library when you set the 1B register settings. e.g. pwm.set(1,'b',60000,2); // internally it sets [COM1A1 COM1A0] to [COM1B1 COM1B0]

Chip         Timer0 Timer1 Timer2 Timer3 Timer4
8b PS 8b ePS --   --   --  
ATtiny85 A D0 D1 --   --   --  
          B D1   D3   --   --   --  
            8b PS 16b PS 8b PS --   --  
ATmega328p A D6# D9   D12* --   --  
          B D5   D10   D3   --   --  
            8b PS 8b PS --   16b PS 8b ePS
ATmega32u4 A D11   D9   --   D5   D13
B D3 D10 -- --   D10
C -- D11 -- --   --  
          D --   --   --   --   D6  

8b/16b : 8 bit or 16 bit timer

PS/ePS : Regular prescalar, Extended prescalar selection

PS = [0,1,8,64,256,1024]

ePS = [0,1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384]

# toggled output. The frequency is half the set frequency, the duty cycle is fixed at 50%

* same as #, but software PWM. It is implemented through the respective TIMERx_OVF_vect ISR

TODO

  • I can be smarter when setting the PeriodRegister. I plan to use the ISR as a counter to implement a static correction table to add +0 or +1 to the ICRx or OCRx register.

Output

ATtiny85 ATmega328p ATmega32u4

pwm's People

Contributors

micooke avatar

Watchers

James Cloos 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.