Using Teensy's DSP instructions

Status
Not open for further replies.

Kuba0040

Well-known member
Hello!
So, the Teensy 3.0 and 4.0 boards have a pretty cool CPUs on them with a lot of useful DSP instructions that can speed up many tasks dramatically. I'd like to take advantage of these. Thankfully, the Audio library comes with a very neat dspinst.h file, where all the DSP instructions are nicely explained and made easy to use.

The only problem is, I can't really seem to get them to work. I wrote a simple test sketch using one instruction (signed_multiply_32x16b, I did try signed_multiply_32x16t as well but still no luck) as a test. I included the dspinst.h file into my project. However, what I get at the output is all zeros. I know that the instruction asks for an int32_t value, while I am providing it only with a int16_t one. However, looking at what it does it should still work, as we are only shifting the multiplication result by 16 bits.

So here is my question, what did I do wrong? Do I have to enable the dsp instructions somehow? If anybody knows please let me know.
Thank You.

Here is my code. I have the dspinst.h file copied into the same folder as my .ino file. I am using a Teesny 4.0

Code:
#include <dspinst.h>

void setup() 
{
  Serial.begin(115200);
}

int16_t osc=0;
uint16_t control_pot=0;


void loop() 
{
  osc=osc+500; //Simple saw wave oscillator for testing
  
  control_pot=analogRead(A0)*64; //Control data

  Serial.println(signed_multiply_32x16b(osc,control_pot)); //Perform operation

  delayMicroseconds(1); //The teensy is so ultra fast we need this delay or arduino ide will crash
}
 
I ran your code here (but edited the include to Audio.h rather than copying the file) on a Teensy 4.0 with a pot connected to pin 14/A0.

Seems to work fine.

screenshot.png
 
Status
Not open for further replies.
Back
Top