Giter Site home page Giter Site logo

pwm's People

Watchers

Alexandru avatar

pwm's Issues

PWM 16 bit

// this code sets up counter1 A output at 25% and B output at 75%
// using ICR1 as top (16bit), Fast PWM.

#include <avr/io.h>

int main(void)
{
DDRB |= (1 << DDB1)|(1 << DDB2);
// PB1 and PB2 is now an output

OCR1 = 0xFFFF;
// set TOP to 16bit

OCR1A = 0x3FFF;
// set PWM for 25% duty cycle @ 16bit

OCR1B = 0xBFFF;
// set PWM for 75% duty cycle @ 16bit

TCCR1A |= (1 << COM1A1)|(1 << COM1B1);
// set none-inverting mode

TCCR1A |= (1 << WGM11);
TCCR1B |= (1 << WGM12)|(1 << WGM13);
// set Fast PWM mode using ICR1 as TOP

TCCR1B |= (1 << CS10);
// START the timer with no prescaler



while (1);
{
    // we have a working Fast PWM
}

}

PWM.cpp

// this code sets up counter0 for an 8kHz Fast PWM wave @ 16Mhz Clock

#include <avr/io.h>

int main(void)
{
DDRD |= (1 << DDD6);
// PD6 is now an output

OCR0A = 128;
// set PWM for 50% duty cycle


TCCR0A |= (1 << COM0A1);
// set none-inverting mode

TCCR0A |= (1 << WGM01) | (1 << WGM00);
// set fast PWM Mode

TCCR0B |= (1 << CS01);
// set prescaler to 8 and starts PWM


while (1);
{
    // we have a working Fast PWM
}

}

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.