ATTiny85 based class D amplifier. - diyAudio
Go Back   Home > Forums > Amplifiers > Class D

Class D Switching Power Amplifiers and Power D/A conversion

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Thread Tools Search this Thread
Old 26th June 2014, 05:17 PM   #1
diyAudio Member
Join Date: Jun 2014
Location: Sparta, Michigan
Default ATTiny85 based class D amplifier.

This is my first foray into class D amplifiers. It is an implementation of Dimitrov's ATTiny based design which can be found here. I modified the code a bit to remove a DC offset and programmed it with the Arduino IDE.

My circuit has a high pitched noise problem, but otherwise seemed to do a decent job. I just thought someone might be interested. Although, I am certain you are all familiar with it already.

My goal was a small amplifier for my bass guitar. This does not have enough gain to take the raw signal and send it to the speaker. I'm working on a different circuit that uses a TPA3125 and includes a pre-amp.

Class D Amplifier ATTiny85 Controller Sketch
last updated 6-23-2014

#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <stdint.h>

#define DACP OCR1A
#define DACN OCR1B

// variable declarations

byte time;

unsigned int pos;
unsigned int neg;
unsigned int adc;

int val1 = 0;
int errorSum = 0;

void setup() {    
// Disable global interrupts

// Configure ports
    DDRB = B00010010;
    PORTB = B11100100;

// Configure ADC
    ADMUX = B11010011;
    ADCSRA = B11000100;
// Power reduction
    PRR = B00000110;
    MCUCR = B00100000;
// Configure PWM
    TCCR1 = B01100010;
    GTCCR = B01100000;
    TIMSK = B100;
    PLLCSR = B110;
// Enable global interrupts

void loop() {

ISR(TIMER1_OVF_vect) {
    if(1 & ++time){
      adc = ADC;
      val1 = (adc >> 2) - 127 - (errorSum >> 10);
      errorSum = errorSum + val1;
      pos = 127 + val1;
      neg = 128 - val1;

      DACP = (pos & 255);
      DACN = (neg & 255);
    } else {
      DACP = (pos & 255);
      DACN = (neg & 255);    
Attached Images
File Type: jpg ATTinyAmpView01.jpg (393.9 KB, 154 views)
File Type: jpg ATTinyAmpView02.jpg (349.9 KB, 152 views)

Last edited by Caleb6543; 26th June 2014 at 05:43 PM.
  Reply With Quote
Old 28th June 2014, 02:34 PM   #2
diyAudio Member
theAnonymous1's Avatar
Join Date: Feb 2004
Location: Anonymityville
Maybe a good learning exercise, but kind of pointless considering it doesn't have any feedback.

Lot's of options out there for proper compact class-d amplifiers.
  Reply With Quote


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
"The Wire AMP" Class A/AB Power Amplifier based on the LME49830 with Lateral Mosfets opc Solid State 2471 12th April 2015 10:54 AM
f5 based high power class ab amplifier 400kg Solid State 7 28th July 2014 02:21 PM
IGBT based class D amplifier muddasirwaheedmalik Class D 7 7th January 2013 07:14 AM
"WTB" "The Wire AMP" Class A/AB Power Amplifier based on the LME49830 with Lateral enantra Swap Meet 3 23rd December 2012 06:36 PM

New To Site? Need Help?

All times are GMT. The time now is 04:30 AM.

vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2015 DragonByte Technologies Ltd.
Copyright 1999-2015 diyAudio

Content Relevant URLs by vBSEO 3.3.2