Teensy 3.0 Audio and Interrupts

Status
Not open for further replies.

MDashdotdashn

New member
Hi Everyone,

First attempt in the direction of using Teensy 3 for audio was successful after a bit of digging but I have a question left.

This generates properly a dirty 8 bit saw wave:

Code:
#include "IntervalTimer.h"

const int pwmPin = 3;       // PWM output pin 

uint8_t value = 0;

void timerCallback0() 
{
  value++;
  analogWrite(pwmPin, value);
}

const unsigned long SAMPLE_RATE = 31250;

void setup() {
  Serial.begin(true);
  delay(200);
  pinMode(pwmPin, OUTPUT);
  analogWriteFrequency(pwmPin,SAMPLE_RATE);
  IntervalTimer timer0;
  timer0.begin(timerCallback0, 1000000 / SAMPLE_RATE);
}

void loop() 
{
}

However I set both the PWM frequency and the timer callback to the same period and was wondering if it wasn't overkill. Can I attach to the pwm interrupt directly ? I haven't found any examples for this.

Thanks for any comment. I'm super hyped about trying more and this first set up was way more easy to achieve than what I expected !

Cheers
Marc.
 
Status
Not open for further replies.
Back
Top