M62429 digital volume control with working code example

Hello all,

if someone is interested, I’m running the M62429 on such a “Digital Stereo Audio Volume Control Board PT2259”: http://www.ebay.de/itm/Digital-Stereo-Audio-Volume-Control-Board-PT2259-Headphone-Audio-Amplifier-DIY-/141084601932?pt=DE_Computer_Sonstige&hash=item20d94c2e4c

If you do not use the rotary encoder but instead plug +5V, GND, DATA, and CLOCK to your Arduino it will work perfectly. The external power supply is also not needed.

I found a library and examples at this site GitHub - krupski/M62429: Arduino Library for the NEC/Renesas M62429 Digital Volume Control, but in the library the delay functions have wrong syntax, so change _delay_ms to delay and _delay_us to delayMicroseconds.

The following code is based on the library, but mine doesn’t need a library, it’s all in the code.

/*
A little example sketch based on this lib: https://github.com/krupski/M62429/blob/master/M62429.cpp
*/

int x=0;
int VolumePinDAT=7; // connect to DATA
int VolumePinCLK=6; // connect to CLOCK




void setup (void)
{
  pinMode(VolumePinDAT, OUTPUT);
  pinMode(VolumePinCLK, OUTPUT);
}

void loop (void)
{
 
  // sweep from quiet to loud
  for (x=0;x<=100;x++)
 {
  setVolume(x);
  delay(100);
  }
  
  // sweep back
  for (x=100;x>=0;x--)
 {
  setVolume(x);
  delay(100);
  }
}


  

// this function does the job
void setVolume (uint8_t volume)
{
	uint8_t bits;
	uint16_t data = 0; // control word is built by OR-ing in the bits

	// convert attenuation to volume
	volume = (volume > 100) ? 0 : (((volume * 83) / -100) + 83); // remember 0 is full volume!
        // generate 10 bits of data
	data |= (0 << 0); // D0 (channel select: 0=ch1, 1=ch2)
	data |= (0 << 1); // D1 (individual/both select: 0=both, 1=individual)
	data |= ((21 - (volume / 4)) << 2); // D2...D6 (ATT1: coarse attenuator: 0,-4dB,-8dB, etc.. steps of 4dB)
	data |= ((3 - (volume % 4)) << 7); // D7...D8 (ATT2: fine attenuator: 0...-1dB... steps of 1dB)
	data |= (0b11 << 9); // D9...D10 // D9 & D10 must both be 1

	for (bits = 0; bits < 11; bits++) { // send out 11 control bits
		delayMicroseconds (2); // pg.4 - M62429P/FP datasheet
		digitalWrite (VolumePinDAT, 0);
		delayMicroseconds (2);
		digitalWrite (VolumePinCLK, 0);
		delayMicroseconds (2);
		digitalWrite (VolumePinDAT, (data >> bits) & 0x01);
		delayMicroseconds (2);
		digitalWrite (VolumePinCLK, 1);
	}
	delayMicroseconds (2);
	digitalWrite (VolumePinDAT, 1); // final clock latches data in
	delayMicroseconds (2);
	digitalWrite (VolumePinCLK, 0);
	//return data; // return bit pattern in case you want it :)
}

Old post, I know. But I'm hoping someone can help me with this module. I am trying to drive it with the left channel of the headphone output from my phone but I barely get any volume out of the chip even when set to 0dB. I can hear it, but the output is nothing close to what is coming out of the right channel ear piece. If I turn up the volume on the headphone output it causes the audio from the chip to distort terribly.

Am I just doing this wrong? I want to use this to control the volume on an amplifier but this audio level output is too low without a pre-amp.

Hi forcedfx,

Let me answer that, 2 years later ;-)

The M62429 is not actually a potmeter. It is a AD - DA converter. Meaning, it takes in an analogue signal, converts it to a signal with smaller or bigger amplitude, and outputs this again. Inside there is a digital heart that does the converting.

The output power of the chip is very limited. :confused: If you look at the datasheet: http://nice.kaze.com/M62429.pdf It says that max drive is 16mA and typical only 8mA. That's too small to actually drive a headphone.

Where you can use this chip is between a source and an amplifier.

For instance: I am building a jukebox that runs a MP3 player board and an amplifier board based on the TDA7297. Between these boards, I have this chip, so my Arduino can control the volume.

That's where it works best ;)