Portenta H7 Sampling Rate

Can anyone help me figure out why my sampling rate is so much slower than what it should be?? Right now, I'm topping out at 5k. I am using a lookup table to generate a sine wave and then outputting it using pin A6. Below is my code for reference. Thanks in advance.

---------------------------code-----------------------------------
int a[arraySize] = {2048,2305,2557,2802,3035,3252,3450,3626,
3777,3901,3996,4060,4092,4092,4060,3996,
3901,3777,3626,3450,3252,3035,2802,2557,
2305,2048,1791,1539,1294,1061,844,646,
470,319,195,100,36,4,4,36,
100,195,319,470,646,844,1061,1294,
1539,1791,2048};

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

void loop(void) {
for (i = 0; i < arraySize; i++
analogWrite(A6, a[i]);

}

Please post the running code. I get a sine-like wave on A6 with a frequency of about 12 kHz using the M7 core. With 51 samples per cycle I get to a an update rate of 612 kHz. Did you use the serial port in your loop-function?

const int arraySize = 51;
int a[arraySize] = {2048,2305,2557,2802,3035,3252,3450,3626,3777,3901,
                    3996,4060,4092,4092,4060,3996,3901,3777,3626,3450,
                    3252,3035,2802,2557,2305,2048,1791,1539,1294,1061,
                    844,646,470,319,195,100,36,4,4,36,
                    100,195,319,470,646,844,1061,1294,1539,1791,
                    2048};

void setup() {
  analogWriteResolution(12);
}

void loop() {
  for (int i = 0; i < arraySize; i++) {
    analogWrite(A6, a[i]);
  }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.