td0g.ca

always know where your towel is

Basic Coding Notes:

Array Syntax:

myArray[][3] = {{1, 2, 3},
                          {4, 5, 6}};

Bit Shifting - Basic Syntax: 16 << 2 = 64

Bit Shifting - Shifting Right & Sign Extension:

int x = -16; // binary: 1111111111110000

int y = x >> 3; // binary: 1111111111111110


Bit Math
& | ! ^ (And, Or, Not, Xor)
Bit Masking (&):
byte x = 5 = 0b00000101
byte y = x & 0b00000011 = 0b00000001
Turning Bit On (|):
byte x = 5 = 0b00000101
byte x = x | 0b00000011 = 0b00000111


Data Types
All literals (constants) are assumed to be signed integers:
1. if entered without a decimal (1.0 is a float)
2. if not explicitly specified (1UL is an unsigned long)
If the math performed involves a float, then floating-point math will be performed.
Otherwise math is performed in the domain of the first rside OPERATION (see operation precidence).
See The Bald Engineer


And see C Operator Precidence


Advanced Coding Topics:

Direct Port Register Manipulation -Guide-

Timer Registers -Guide- | -Cheat Sheet-

Pinouts -ATMega328- | -ATTiny85-

Arduino Reference Page

Bit Hacks


Timers:

ATMega328:

TimerSizeBase frequencyAffected functions
08-bit62500millis, micros, delay
116-bit31372.55Servo library
28-bit62500Tone

ATTiny85:

TimerSizeAffected Functions
0

Configuring Timers:

Bit87654321
TCCRxACOM, 1A1, RWCOM, 1A0, RWCOM, 1B1, RWCOM, 1B0, RWR WG, M11, RWWG, A10, RW
TCCRxB1CNC 1 RW 1CES, 1, RWRWG, M13, RWWG, M12, RWCS12, RWCS11, RWCS10, RW



For PWM freq adjustment, set timer's base frequency divided by prescaler.

CS12CS11CS10Prescaler
000No Clock (default)
001 /1 (fastest)
010/8
011/64
100/256
101/1024 (slowest)
110Ext clock T1 pin - falling
111Ext clock T1 pin - rising

Initializing timers:
cli;
TCCRxA = 0;
TCCRxB = 0;
TIMSKx |= 1< TCCRxB |= ________;
TCNT1 = startTime;
sei();


Programming:

Board Manager URL's (separated by comma):

ATTiny: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json

ESP8266: http://arduino.esp8266.com/stable/package_esp8266com_index.json

Arduino as ISP --> ATMega328: homeautomation.org

Programming Bootloaded ATMega328 w/ FTDI: gammon.com.au

NOTES: Both Lilypad and Uno bootloaders are confirmed to work.

Adafruit FTDI cable has 5V supply and 3V logic - One or the other MUST be shifted.

Programmer: Select AVRISP mkII | Board: Lilypad Arduino or Arduino Uno

When changing from internal to external oscillator bootloader, don't forget to add the external oscillator.