Git Product home page Git Product logo

avrassist's Introduction

AVRAssist

AVRAssist is a set of header files which can be #included in your AVR C++ code, or, #included in an Arduino Sketch where you want to get down and dirty in the various hardware bits of the AVR micro controller. The AVRAssist headers make it easier to make setting various AVR registers a tad easier.

Components

The following AVR internal devices can be set up with the current version of AVRAssist:

  • Timer/counters - all three timer/counters have separate header files;
  • Analogue to Digital Converter;
  • The Analogue Comparator;
  • The Watchdog Timer.

Example

As an example, the following will configure Timer/Counter 0 with:

  • Fast PWM mode with TOP = 255;
  • A prescaler of 64;
  • OCOA & OCOB = Pins 11 & 12 = Arduino D5 & D6 = AVR PD5 & PD6 in normal GPIO mode;
  • Interrupt to fire on compare match A;
  • Interrupt to fire on compare match B;
#include <timer0.h>

using namespace AVRAssist;

...

Timer0::initialise(Timer0::MODE_FAST_PWM_255,           // Timer mode;
                   Timer0::CLK_PRESCALE_64,             // Prescaler;
                   Timer0::OCOX_DISCONNECTED,           // OCOA, OCOB actions on compare match;
                   Timer0::INT_COMP_MATCH_A |           // Interrupt(s) to enable;
                        Timer0::INT_COMP_MATCH_B
                  );
...

Only the first two parameters are actually required though, the rest have sensible defaults. (For certain values of sensible perhaps?)

Later on in the code, you can force a comparison between TCNT0 and either OCR0A and/or OCR0B, should you have the need. This will not fire any configured interrupts but will set OC0A or OC0B to the state they would take without a forced compare if they happen to match TCNT0 when forced. This is simply done as follows:

Timer0::forceCompare(Timer0::FORCE_COMPARE_MATCH_A |
                          Timer0::FORCE_COMPARE_MATCH_B
                    );

Using AVRAssist is, hopefully, much easier and less prone to fat fingered typist syndrome (something I suffer from, frequently!) especially when attempting to type the following, equivalent code:

TCCR0A = (0 << COM0A1) | (0 << COM0A0) | (0 << COM0B1) | (0 << COM0B0) | (1 << WGM00) | (1 << WGM01);
TCCR0B = (0 << FOC0A)  | (0 << FOC0B)  | (0 << WGM02)  | (0 << CS02)   | (1 << CS01)  | (1 << CS00);
TIMSK0 = (1 << OCIE0A) | (1 << OCIE0B) | (0 << TOIE0);

especially if there's a different waveform to be applied to TCCR0A! At least, I find it easier! And, yes I did type the above incorrectly when writing this readme. Sigh!

NOTE: Yes, I know, I've set all the zero bits in the above equivalent code, but that makes it easier to change the bits later, if I needed to change the mode or prescaler etc.

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.