Go Down

Topic: PT2258 No sound (Read 1 time) previous topic - next topic

arifs

Feb 20, 2017, 08:31 pm Last Edit: Feb 20, 2017, 08:44 pm by arifs
Hi good fellows.

I need you wisdom and wizardry with my project :)

I am trying to use PT2258 for my next amplifier project and its giving me hardtime. I have scanned the address via i2c scanner code (thank you Mr. Nick Gammon),

firstly the address code is not what was written in datasheet 0x40 instead of 80h as per datasheet (am i reading something wrong here)

Secondly after i found and used some code from this good fellow.
https://github.com/koszoaron/diy_projects/blob/master/OrionHT550/original_source.pde



My results are nill no sound from any channel. I am giving input from small portable radio (12k resistor attached in series  to reduce risk of any damage to ic) and taking output to testing purpose 10 watt amplifier.  I have banged my head around datasheet , but just cant make it run.

HELP PLZ!

is there any way I can debug the code or simulate this ic somewhere till the code is right. to avoid any problems caused by hardware


Code: [Select]

#include <Wire.h>
#define PT_ADDR 0x40


//``````````````````````````````````````````````````````````//

void setup() {
  Serial.begin (9600);
  Serial.println ("delaying 300ms");
  delay (500);

  // clear register as per datasheet
  Wire.beginTransmission(0x40);
  Wire.write(0xC0);
  Wire.endTransmission();

}  // end of setup

//``````````````````````````````````````````````````````````//

void loop() {
  // set all volumes, i think datasheet says we need to tell all channels
  Serial.println("vol 1");
  pt2258(1, 1);
  pt2258(1, 2);
  pt2258(1, 3);
  pt2258(1, 4);
  pt2258(1, 5);
  pt2258(1, 6);
  delay(3000);

  Serial.println("79");
  pt2258(79, 1);
  pt2258(79, 2);
  pt2258(79, 3);
  pt2258(79, 4);
  pt2258(79, 5);
  pt2258(79, 6);
  delay(3000);

}

//``````````````````````````````````````````````````````````//

//------------------------------------------------------------------------------
// Volume controller IC command set
//------------------------------------------------------------------------------
void pt2258(byte command, byte ch)  // send volume level commands
{
  byte x10;
  byte x1;

  if (command >= 10)
  {
    x10 = command / 10;      // set decade step
    x1 = command % 10;       // set step
  }
  else                       // set step
  {
    x1 = command;
    x10 = 0;
  }

  switch (ch)                // which channel to command
  {
    case 0:    // all channels
      x1 = x1 + 0xe0;
      x10 = x10 + 0xd0;
      break;

    case 1:    // channel 1
      x1 = x1 + 0x90;
      x10 = x10 + 0x80;
      break;

    case 2:    // channel 2
      x1 = x1 + 0x50;
      x10 = x10 + 0x40;
      break;

    case 3:    // channel 3
      x1 = x1 + 0x10;
      x10 = x10 + 0x00;
      break;

    case 4:    // channel 4
      x1 = x1 + 0x30;
      x10 = x10 + 0x20;
      break;

    case 5:    // channel 5
      x1 = x1 + 0x70;
      x10 = x10 + 0x60;
      break;

    case 6:    // channel 6
      x1 = x1 + 0xb0;
      x10 = x10 + 0xa0;
      break;

    default:   // mute functions
      if (command == 0) x10, x1 = 0xf8;  // mute off
      else x10, x1 = 0xf9;               // mute on
      break;
  }

  for (int i = 0; i <= 2; i++) // repeat 2x (had some unknown issues when transmitted only once)
  {
    Wire.beginTransmission(0x40); // transmit to device 0x88(hex) -> 136(dec)(addressing is 7-bit) -> 136/2
    Wire.write(x10);             // send decade step
    Wire.write(x1);              // send step
    Wire.endTransmission();     // stop transmitting
  }
}


el_supremo

The address is 0x40. The extra low order bit (which would make it 0x80) is the read/write bit which is not part of the address.

Pete
Don't send me technical questions via Private Message.

arifs

Thanks Pete


this just flew over my head, what query can i search on google to read more on this (no programming background here, just a designer trying to fulfill his lust for making things)


Any view on the no sound problem

el_supremo

I haven't got one of those chips to play with so I can only go by what is in the datasheet which is not as clear as it could be.

This piece of the code doesn't look right:
Code: [Select]
    if (command == 0) x10, x1 = 0xf8;  // mute off
      else x10, x1 = 0xf9;               // mute on

My guess is it should be:
Code: [Select]

     x10 = 0;
     if (command == 0) {
        x1 = 0xf8;
     }  // mute off
     else {
        x1 = 0xf9;               // mute on
     }


Quote
Any view on the no sound problem
You'll need a hardware guru to help with that side of the project.

Pete
Don't send me technical questions via Private Message.

el_supremo

To make life easier for anyone who can help, here's the datasheet http://www.futurlec.com/Datasheet/Others/PT2258.pdf

Pete
Don't send me technical questions via Private Message.

arifs

Thankyou. this looked like a good chip (I have to hunt for it locally) but i think if this dosent work I ll go for AD5242 that is available in simulation I have made it work , but for 6 channels i need 3

arifs

Good morning all.

Just going through datasheet and trying to understand when I stumbled upon this

Datasheet
"Every byte transmitted to the SDA Line consists of 8 bits. Each byte must be followed by an Acknowledge Bit. The MSB is transmitted first."


Wire library
". The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8 bit address, you'll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127."


I have seen some example code using address like this (80>>1)


comments plz, can that be the cause of pt2258 not working

CrossRoads

"Every byte transmitted to the SDA Line consists of 8 bits."
"The Wire library uses 7 bit addresses throughout. "

The 8th bit is generally a read/write bit that the library will add.

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

arifs

Thank you CrossRoads. Being in strange waters and utterly clueless I didnt want to take risk. so I have tried this library

https://github.com/felias-fogg/SoftI2CMaster


and it lo00oks like its working, long looks, because I am not sure,

I am trying to test on breadboard and going for Mute and unmute

Though i can feel the difference in volume, but that's not what I supposed it should do should allows and stop sound on unmute and mute.

here's my so far effort.

NEXT STEP:
To eliminate the chances that breadboard might be causing any issues I will try on veroboard. I dont know how low -79 db should be,  should it be faint (like low side of volume pot) ??

Code: [Select]

// all credits original authors and a lots of thanks for sharing for make life of hobbyists easier :D ~ Arif

// below section is from library reference
//https://github.com/felias-fogg/SoftI2CMaster

// Simple sketch to read using SoftI2C
#define SDA_PORT PORTC
#define SDA_PIN 4
#define SCL_PORT PORTC
#define SCL_PIN 5
#include <avr/io.h>

// use ports usually used for hardware I2C
#define SDA_PORT PORTC
#define SDA_PIN 4
#define SCL_PORT PORTC
#define SCL_PIN 5

#define I2C_TIMEOUT 100
#define I2C_NOINTERRUPT 0
#define I2C_SLOWMODE 1
#define FAC 1
#define I2C_CPUFREQ (F_CPU/FAC)


void CPUSlowDown(int fac) {
  // slow down processor by a fac
  CLKPR = _BV(CLKPCE);
  CLKPR = _BV(CLKPS1) | _BV(CLKPS0);
}


#include <SoftI2CMaster.h>  // if we copy it to top of document, arduino ide 1.6.7 gices  a long list of erere, here it sits happily. magic :)

// my declarations
byte LED = 13; // pin 13 led of uno
#define addr 0x80 // as per data sheet for grounding both code 1&2 lines to ground


//--------------------- SETUP ------------------------------------//
void setup(void) {
  pinMode (LED, OUTPUT); // for visual representation of mute, unmute
  Serial.begin(19200);
  Serial.println(F("starting")); // for hope that its all working so far
  delay (900);
  // ~~~~~~~~~~~~~~~~~~~~~

  // copied from library example, again just to check if all is good on sda and scl lines
  Serial.println(F("Intializing ..."));
  Serial.print("I2C delay counter: ");
  Serial.println(I2C_DELAY_COUNTER);
  if (!i2c_init())
    Serial.println(F("Initialization error. SDA or SCL are low"));
  else
    Serial.println(F("...done"));
  // ~~~~~~~~~~~~~~~~~~~~~

  // data sheet said so to clear register C0H , to ensure working
  i2c_start_wait(addr | 0);
  i2c_write(0xC);
  i2c_stop();
  Serial.println(F("end setup"));
} // end setup braces


//--------------------- LOOP ------------------------------------//

void loop(void) {

  Serial.println(F("mute"));
  digitalWrite (LED, LOW); // for visua l representation
  // PT2258 is a function at the end of loop doing all calculations, credits to https://github.com/koszoaron/diy_projects/blob/master/OrionHT550/original_source.pde
  pt2258(78, 0);        // -79dB All CH (mute)
  delay(6000);

  // ~~~~~~~~~~~~~~~~~~~~~
  Serial.println(F("play"));
  digitalWrite (LED, HIGH);
  pt2258(1, 0);        // -79dB All CH (mute)
  delay(6000);
}



//------------------------------------------------------------------------------
// Volume controller IC command set
//------------------------------------------------------------------------------
void pt2258(byte command, byte ch)  // send volume level commands
{
  byte x10;
  byte x1;

  if (command >= 10)
  {
    x10 = command / 10;      // set decade step
    x1 = command % 10;       // set step
  }
  else                       // set step
  {
    x1 = command;
    x10 = 0;
  }

  switch (ch)                // which channel to command
  {
    case 0:    // all channels
      x1 = x1 + 0xe0;
      x10 = x10 + 0xd0;
      break;

    case 1:    // channel 1
      x1 = x1 + 0x90;
      x10 = x10 + 0x80;
      break;

    case 2:    // channel 2
      x1 = x1 + 0x50;
      x10 = x10 + 0x40;
      break;

    case 3:    // channel 3
      x1 = x1 + 0x10;
      x10 = x10 + 0x00;
      break;

    case 4:    // channel 4
      x1 = x1 + 0x30;
      x10 = x10 + 0x20;
      break;

    case 5:    // channel 5
      x1 = x1 + 0x70;
      x10 = x10 + 0x60;
      break;

    case 6:    // channel 6
      x1 = x1 + 0xb0;
      x10 = x10 + 0xa0;
      break;

    default:   // mute functions
      if (command == 0) x10, x1 = 0xf8;  // mute off
      else // x10, x1 = 0xf9;               // mute on
        break;
  }


  i2c_start_wait(addr | 0);
  i2c_write(x10);            // send decade step
  i2c_write(x1);             // send step
  i2c_stop();                // stop transmitting

}


arifs

Good news , I made it on veroboard for testing purposes and its working fine, perhaps loose wires or capacitance of breadboard was messing with it.


Here the code for anyone playing around PT2258, this just allows and stops sound after few seconds to check the ic.


 

Code: [Select]




// below section is from library reference




// Simple sketch to read using SoftI2C
#define SDA_PORT PORTC
#define SDA_PIN 4
#define SCL_PORT PORTC
#define SCL_PIN 5
#include <avr/io.h>

// use ports usually used for hardware I2C
#define SDA_PORT PORTC
#define SDA_PIN 4
#define SCL_PORT PORTC
#define SCL_PIN 5

#define I2C_TIMEOUT 100
#define I2C_NOINTERRUPT 0
#define I2C_SLOWMODE 1
#define FAC 1
#define I2C_CPUFREQ (F_CPU/FAC)


void CPUSlowDown(int fac) {
  // slow down processor by a fac
  CLKPR = _BV(CLKPCE);
  CLKPR = _BV(CLKPS1) | _BV(CLKPS0);
}


#include <SoftI2CMaster.h>  // if we copy it to top of document, arduino ide 1.6.7 gices  a long list of erere, here it sits happily. magic :)

// my declarations
byte LED = 13; // pin 13 led of uno
#define addr 0x88 // as per data sheet for grounding both code 1&2 lines to ground


//--------------------- SETUP ------------------------------------//
void setup(void) {
  pinMode (LED, OUTPUT); // for visual representation of mute, unmute
  Serial.begin(19200);
  Serial.println(F("starting")); // for hope that its all working so far
  delay (900);
  // ~~~~~~~~~~~~~~~~~~~~~

  // copied from library example, again just to check if all is good on sda and scl lines
  Serial.println(F("Intializing ..."));
  Serial.print("I2C delay counter: ");
  Serial.println(I2C_DELAY_COUNTER);
  if (!i2c_init())
    Serial.println(F("Initialization error. SDA or SCL are low"));
  else
    Serial.println(F("...done"));
  // ~~~~~~~~~~~~~~~~~~~~~

    // data sheet said so to clear register C0H , to ensure working
    i2c_start_wait(addr | 0);
    i2c_write(0xC);
    i2c_stop();
   
// blink led to show that arduino is starting, if you dont to serial again and again,
  digitalWrite (LED, HIGH); // for visua l representation
  delay(300);
  digitalWrite (LED, LOW); // for visua l representation
  delay(300);
  digitalWrite (LED, HIGH); // for visua l representation
  delay(300);
  digitalWrite (LED, LOW); // for visua l representation
  delay(300);
  digitalWrite (LED, HIGH); // for visua l representation
  delay(300);
  Serial.println(F("end setup"));
} // end setup braces


//--------------------- LOOP ------------------------------------//

void loop(void) {

  // ~~~~~~~~~~~~~~~~~~~~~
  Serial.println(F("play"));
  digitalWrite (LED, HIGH);
  pt2258(0, 0);        // -79dB All CH (mute)
  Serial.println(F("delaying"));
  delay(4000);


 
  Serial.println(F("mute"));
  digitalWrite (LED, LOW); // for visua l representation
  // PT2258 is a function at the end of loop doing all calculations, credits to https://github.com/koszoaron/diy_projects/blob/master/OrionHT550/original_source.pde
  pt2258(78, 0);        // -79dB All CH (mute)
  Serial.println(F("delaying"));
  delay(4000);
}



//------------------------------------------------------------------------------
// Volume controller IC command set
//------------------------------------------------------------------------------
void pt2258(byte command, byte ch)  // send volume level commands
{
  byte x10;
  byte x1;

  if (command >= 10)
  {
    x10 = command / 10;      // set decade step
    x1 = command % 10;       // set step
  }
  else                       // set step
  {
    x1 = command;
    x10 = 0;
  }

  switch (ch)                // which channel to command
  {
    case 0:    // all channels
      x1 = x1 + 0xe0;
      x10 = x10 + 0xd0;
      break;

    case 1:    // channel 1
      x1 = x1 + 0x90;
      x10 = x10 + 0x80;
      break;

    case 2:    // channel 2
      x1 = x1 + 0x50;
      x10 = x10 + 0x40;
      break;

    case 3:    // channel 3
      x1 = x1 + 0x10;
      x10 = x10 + 0x00;
      break;

    case 4:    // channel 4
      x1 = x1 + 0x30;
      x10 = x10 + 0x20;
      break;

    case 5:    // channel 5
      x1 = x1 + 0x70;
      x10 = x10 + 0x60;
      break;

    case 6:    // channel 6
      x1 = x1 + 0xb0;
      x10 = x10 + 0xa0;
      break;

    default:   // mute functions
      if (command == 0) x10, x1 = 0xf8;  // mute off
      else // x10, x1 = 0xf9;               // mute on
        break;
  }


  i2c_start_wait(addr | 0);
  i2c_write(x10);            // send decade step
  i2c_write(x1);             // send step
  i2c_stop();                // stop transmitting

}


daba

#define addr 0x88 // as per data sheet for grounding both code 1&2 lines to ground

The datasheet (pages 7-8) define the chip addresses as follows....
Code: [Select]

CODE1, CODE2, ADDRESS

   1     1    0x8C
   1     0    0x88
   0     1    0x84
   0     0    0x80


I, too am having troubles with getting this chip to work. I'm currently using <Wire.h>, and I believe the problems are caused by the i2c address being an 8-bit byte with the high bit set, which I don;t think Wire supports.

Presumably switching to SoftI2CMaster overcomes this problem ??
Everything works with smoke. If you let it out, things stop working.

el_supremo

The addresses shown in the datasheet are NOT how they are specified to Wire.h
The low order bit of each of those addresses is the I2C Read/Write bit and is not part of the address. To specify the address to Wire.h you have to remove the Read/Write bit (Wire.h re-inserts the appropriate bit when it actually does the I/O).
For example the address 0x8C in binary is 10001100. Removing the low order bit gives 1000110 which in hex is 0x46 and that is the address you would specify to the Wire.h library.
Unless you need more than one I2C bus or you need to use A4 and A5 as analog pins, there's no need to use SoftI2CMaster.

Pete
Don't send me technical questions via Private Message.

daba

The addresses shown in the datasheet are NOT how they are specified to Wire.h
The low order bit of each of those addresses is the I2C Read/Write bit and is not part of the address. To specify the address to Wire.h you have to remove the Read/Write bit (Wire.h re-inserts the appropriate bit when it actually does the I/O).
For example the address 0x8C in binary is 10001100. Removing the low order bit gives 1000110 which in hex is 0x46 and that is the address you would specify to the Wire.h library.
Unless you need more than one I2C bus or you need to use A4 and A5 as analog pins, there's no need to use SoftI2CMaster.

Pete
Thanks for that detailed explanation Pete, it definitely isn't clear from any documentation, but you have removed all my confusions.

Since posting, I've actually re-done my sketch using Soft!2CMaster, and got it working. Don't think I'll make extra work for myself putting it back to Wire.h

I've got to follow-up the PT2258 with a 3-channel stereo mixer - combining the PT outputs does it no good at all !!   I have been searching for a similar chip (needs to be 6-channel plus = 3 stereo channels), that incorporates a mixer stage, but haven't found one yet....
Everything works with smoke. If you let it out, things stop working.

daba

I have been searching for a similar chip (needs to be 6-channel plus = 3 stereo channels), that incorporates a mixer stage, but haven't found one yet....
Found it !!

The PT2314 4-channel Input Audio Processor will serve my needs perfectly !!

And I don't need to do any soldering - I've just ordered this module off eBay

Very reasonably priced too....
Everything works with smoke. If you let it out, things stop working.

Frederic_Plante

Yeah I know it's has been a long time some one has posted here,but I just bought the chip so...

Have you consider running a I2C scanner to know what was going on under the hood? ;)

https://playground.arduino.cc/Main/I2cScanner

I'm asking so I will know what to expect when I get it.
As we fight our way northward into the great unknown, only that one thing remains certain...

Go Up