3.3 - 4 wire digital

Submitted by Webbot on October 30, 2008 - 5:06pm.

This mode allows you to use 4 contiguous output pins from the same port to output the 16 different volume levels.


To activate this mode then edit the global.h and make sure that the line:-

    #define _AVR_QUAD_
    is not commented out.


You can change the port and pins that are used by editing the following lines in global.h


    #ifdef _AVR_QUAD_
        #define QUAD_PORT PORTC
        #define QUAD_DDR  DDRC
        #define QUAD_BIT  PC0
        #define QUAD_MASK (BV(QUAD_BIT) | BV(QUAD_BIT+1) | BV(QUAD_BIT+2) | BV(QUAD_BIT+3))

the above values will use Port C pins 0,1,2,3.


This mode may be preferable to PWM if you are using the PWM ports already, say for controlling motors, but it does need 4 I/O pins. The electronics of the audio driver board are also fairly complex. First of all we take the outputs from the pins and feed them into a resistor ladder, which acts like a digital-to-analogue convertor, and generates a signal between 0v and 5v in 16 steps. Since the 'ladder' requires lots of resistors with one value, and lots more with twice that value, then I have opted (in my schematic) to use several SIL Resistor arrays of 10k resistors. These things are quite cool in this scenario. A single package has 8 pins in a single line (hence SIL). Each adjacent pair of pins contains one 10k resistor. So an 8 pin package has 4 resistors. Note how I put some in parallel to generate 5k resistors in order to satisfy the requirement of the ladder. These devices are normally rated at +-2% which is better than your average resistor.


The output of the ladder (ie the analogue signal) is then fed into a unity gain operational amplifier just to give it some extra oomph. Note how the op-amp has power supplied via an RC network to try to protect it from power supply noise.


The output of the op amp is used to drive a transistor that drives the speaker.


Here's the schematic:-


4port.zip33.09 KB