Skip to content

Instantly share code, notes, and snippets.

View dranger003's full-sized avatar

DAN™ dranger003

  • Canada
  • 00:32 (UTC -04:00)
View GitHub Profile
@dranger003
dranger003 / ATtiny85_PWM
Last active January 12, 2017 14:11
ATtiny85 Hardware PWM, pins 0, 1 & 4
// ATtiny85
// Hardware PWM, pins 0, 1 & 4
int main()
{
sei();
DDRB = _BV(PORTB0); // OC0A
DDRB |= _BV(PORTB1); // OC0B
DDRB |= _BV(PORTB4); // OC1B
const double _F = F_CPU / 38000.0 + 0.5 - 1;
const double _D = _F * 0.33 + 0.5 - 1;
const uint16_t _cv[] = { 40085, 36.39716198 };
const uint16_t _cp[][2] =
{
{ 97, 24 },
{ 24, 24 },
{ 48, 24 },
// 1 cycle = 62.5ns
int main()
{
DDRD |= _BV(3);
PORTD &= ~_BV(3);
for (;;)
{
PORTD ^= _BV(3); // 5 cycles