I'm trying to play a sine wave 2KHz with 64KHz sampling rate using the AMP3 PMODule. I can see a 2Khz output on headphone jacks but it is basically a square wave and is hitting the rails. I've tried scaling down the samples but still cannot get a clean sine wave output.

My sine wave generation works fine on the older i2s DAC PMODule.

I'm using standalone mode, external MCLK (16.384Mhz) 256x multiplier (sample rate at 64K) and standard i2s.

I get similar results when using BCLK as MCLK.

here is an example of the 16 bit values I'm transmitting over i2s

static const uint16_t sinTable[] = {
        0x0000, 0x00c9, 0x0192, 0x025b, 0x0324, 0x03ed, 0x04b6, 0x057f,
        0x0648, 0x0711, 0x07d9, 0x08a2, 0x096a, 0x0a33, 0x0afb, 0x0bc4,
        0x0c8c, 0x0d54, 0x0e1c, 0x0ee3, 0x0fab, 0x1072, 0x113a, 0x1201,
        0x12c8, 0x138f, 0x1455, 0x151c, 0x15e2, 0x16a8, 0x176e, 0x1833,
        0x18f9, 0x19be, 0x1a82, 0x1b47, 0x1c0b, 0x1ccf, 0x1d93, 0x1e57,
        0x1f1a, 0x1fdd, 0x209f, 0x2161, 0x2223, 0x22e5, 0x23a6, 0x2467,
        0x2528, 0x25e8, 0x26a8, 0x2767, 0x2826, 0x28e5, 0x29a3, 0x2a61,
        0x2b1f, 0x2bdc, 0x2c99, 0x2d55, 0x2e11, 0x2ecc, 0x2f87, 0x3041,
        0x30fb, 0x31b5, 0x326e, 0x3326, 0x33df, 0x3496, 0x354d, 0x3604,
        0x36ba, 0x376f, 0x3824, 0x38d9, 0x398c, 0x3a40, 0x3af2, 0x3ba5,
        0x3c56, 0x3d07, 0x3db8, 0x3e68, 0x3f17, 0x3fc5, 0x4073, 0x4121,
        0x41ce, 0x427a, 0x4325, 0x43d0, 0x447a, 0x4524, 0x45cd, 0x4675,
        0x471c, 0x47c3, 0x4869, 0x490f, 0x49b4, 0x4a58, 0x4afb, 0x4b9d,
        0x4c3f, 0x4ce0, 0x4d81, 0x4e20, 0x4ebf, 0x4f5d, 0x4ffb, 0x5097,
        0x5133, 0x51ce, 0x5268, 0x5302, 0x539b, 0x5432, 0x54c9, 0x5560,
        0x55f5, 0x568a, 0x571d, 0x57b0, 0x5842, 0x58d3, 0x5964, 0x59f3,
        0x5a82, 0x5b0f, 0x5b9c, 0x5c28, 0x5cb3, 0x5d3e, 0x5dc7, 0x5e4f,
        0x5ed7, 0x5f5d, 0x5fe3, 0x6068, 0x60eb, 0x616e, 0x61f0, 0x6271,
        0x62f1, 0x6370, 0x63ee, 0x646c, 0x64e8, 0x6563, 0x65dd, 0x6656,
        0x66cf, 0x6746, 0x67bc, 0x6832, 0x68a6, 0x6919, 0x698b, 0x69fd,
        0x6a6d, 0x6adc, 0x6b4a, 0x6bb7, 0x6c23, 0x6c8e, 0x6cf8, 0x6d61,
        0x6dc9, 0x6e30, 0x6e96, 0x6efb, 0x6f5e, 0x6fc1, 0x7022, 0x7083,
        0x70e2, 0x7140, 0x719d, 0x71f9, 0x7254, 0x72ae, 0x7307, 0x735e,
        0x73b5, 0x740a, 0x745f, 0x74b2, 0x7504, 0x7555, 0x75a5, 0x75f3,
        0x7641, 0x768d, 0x76d8, 0x7722, 0x776b, 0x77b3, 0x77fa, 0x783f,
        0x7884, 0x78c7, 0x7909, 0x794a, 0x7989, 0x79c8, 0x7a05, 0x7a41,
        0x7a7c, 0x7ab6, 0x7aee, 0x7b26, 0x7b5c, 0x7b91, 0x7bc5, 0x7bf8,
        0x7c29, 0x7c59, 0x7c88, 0x7cb6, 0x7ce3, 0x7d0e, 0x7d39, 0x7d62,
        0x7d89, 0x7db0, 0x7dd5, 0x7dfa, 0x7e1d, 0x7e3e, 0x7e5f, 0x7e7e,
        0x7e9c, 0x7eb9, 0x7ed5, 0x7eef, 0x7f09, 0x7f21, 0x7f37, 0x7f4d,
        0x7f61, 0x7f74, 0x7f86, 0x7f97, 0x7fa6, 0x7fb4, 0x7fc1, 0x7fcd,
        0x7fd8, 0x7fe1, 0x7fe9, 0x7ff0, 0x7ff5, 0x7ff9, 0x7ffd, 0x7ffe,
        0x7fff, 0x7ffe, 0x7ffd, 0x7ff9, 0x7ff5, 0x7ff0, 0x7fe9, 0x7fe1,
        0x7fd8, 0x7fcd, 0x7fc1, 0x7fb4, 0x7fa6, 0x7f97, 0x7f86, 0x7f74,
        0x7f61, 0x7f4d, 0x7f37, 0x7f21, 0x7f09, 0x7eef, 0x7ed5, 0x7eb9,
        0x7e9c, 0x7e7e, 0x7e5f, 0x7e3e, 0x7e1d, 0x7dfa, 0x7dd5, 0x7db0,
        0x7d89, 0x7d62, 0x7d39, 0x7d0e, 0x7ce3, 0x7cb6, 0x7c88, 0x7c59,
        0x7c29, 0x7bf8, 0x7bc5, 0x7b91, 0x7b5c, 0x7b26, 0x7aee, 0x7ab6,
        0x7a7c, 0x7a41, 0x7a05, 0x79c8, 0x7989, 0x794a, 0x7909, 0x78c7,
        0x7884, 0x783f, 0x77fa, 0x77b3, 0x776b, 0x7722, 0x76d8, 0x768d,
        0x7641, 0x75f3, 0x75a5, 0x7555, 0x7504, 0x74b2, 0x745f, 0x740a,
        0x73b5, 0x735e, 0x7307, 0x72ae, 0x7254, 0x71f9, 0x719d, 0x7140,
        0x70e2, 0x7083, 0x7022, 0x6fc1, 0x6f5e, 0x6efb, 0x6e96, 0x6e30,
        0x6dc9, 0x6d61, 0x6cf8, 0x6c8e, 0x6c23, 0x6bb7, 0x6b4a, 0x6adc,
        0x6a6d, 0x69fd, 0x698b, 0x6919, 0x68a6, 0x6832, 0x67bc, 0x6746,
        0x66cf, 0x6656, 0x65dd, 0x6563, 0x64e8, 0x646c, 0x63ee, 0x6370,
        0x62f1, 0x6271, 0x61f0, 0x616e, 0x60eb, 0x6068, 0x5fe3, 0x5f5d,
        0x5ed7, 0x5e4f, 0x5dc7, 0x5d3e, 0x5cb3, 0x5c28, 0x5b9c, 0x5b0f,
        0x5a82, 0x59f3, 0x5964, 0x58d3, 0x5842, 0x57b0, 0x571d, 0x568a,
        0x55f5, 0x5560, 0x54c9, 0x5432, 0x539b, 0x5302, 0x5268, 0x51ce,
        0x5133, 0x5097, 0x4ffb, 0x4f5d, 0x4ebf, 0x4e20, 0x4d81, 0x4ce0,
        0x4c3f, 0x4b9d, 0x4afb, 0x4a58, 0x49b4, 0x490f, 0x4869, 0x47c3,
        0x471c, 0x4675, 0x45cd, 0x4524, 0x447a, 0x43d0, 0x4325, 0x427a,
        0x41ce, 0x4121, 0x4073, 0x3fc5, 0x3f17, 0x3e68, 0x3db8, 0x3d07,
        0x3c56, 0x3ba5, 0x3af2, 0x3a40, 0x398c, 0x38d9, 0x3824, 0x376f,
        0x36ba, 0x3604, 0x354d, 0x3496, 0x33df, 0x3326, 0x326e, 0x31b5,
        0x30fb, 0x3041, 0x2f87, 0x2ecc, 0x2e11, 0x2d55, 0x2c99, 0x2bdc,
        0x2b1f, 0x2a61, 0x29a3, 0x28e5, 0x2826, 0x2767, 0x26a8, 0x25e8,
        0x2528, 0x2467, 0x23a6, 0x22e5, 0x2223, 0x2161, 0x209f, 0x1fdd,
        0x1f1a, 0x1e57, 0x1d93, 0x1ccf, 0x1c0b, 0x1b47, 0x1a82, 0x19be,
        0x18f9, 0x1833, 0x176e, 0x16a8, 0x15e2, 0x151c, 0x1455, 0x138f,
        0x12c8, 0x1201, 0x113a, 0x1072, 0x0fab, 0x0ee3, 0x0e1c, 0x0d54,
        0x0c8c, 0x0bc4, 0x0afb, 0x0a33, 0x096a, 0x08a2, 0x07d9, 0x0711,
        0x0648, 0x057f, 0x04b6, 0x03ed, 0x0324, 0x025b, 0x0192, 0x00c9,




Edited by Patrick Fitzpatrick

Share this post

Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

@Patrick Fitzpatrick,

Let me see if I get this right ... you are trying to output a sine wave, but getting a square wave instead?  This is a classic problem associated with having the wrong bit order.  Perhaps you have the bit order reversed?

Try this: Create a square wave by toggling one bit at a time.  Note the different sizes of the square waves that result.  You should then be able to identify which bits are which.  If the size of the square waves doesn't change then ... you've got another problem.


Share this post

Link to post
Share on other sites
  • 0

There is only one bit order on Is2, that is MSB first and I have verified that the data output is in correct order. 

The exact same bit pattern generates a perfect sine wave using the PMOD i2s module.

I think my problem may be related to the amp itself, I am just plugging in a set of headphones which I don't think will work properly on a bridged amp output?

I won't be able to hook up an actual speaker until tomorrow.


Share this post

Link to post
Share on other sites
  • 0

Problem solved. I had misread the specs as class A amplifier and was expecting to see normal sine wave output and to be able to plug a pair of headphones in directly. With class D the output is pulse width driven and the output waveform cannot be easily seen on a scope.

Once I connected a speaker I was able to hear proper output and control volume.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now