T4 inconsistent pwm width on different pins

Status
Not open for further replies.

charonme

New member
I encountered a strange issue regarding the actual output length of PWM pulses from Teensy 4.0:
Code:
void setup() {
	analogWriteResolution(7);
	pinMode(6, OUTPUT);
	pinMode(7, OUTPUT);
	pinMode(8, OUTPUT);
	pinMode(9, OUTPUT);
	pinMode(10, OUTPUT);
	pinMode(11, OUTPUT);
	pinMode(12, OUTPUT);
	pinMode(13, OUTPUT);
	analogWriteFrequency(6, 101867.58);
	analogWriteFrequency(7, 101867.58);
	analogWriteFrequency(8, 101867.58);
	analogWriteFrequency(9, 101867.58);
	analogWriteFrequency(10, 101867.58);
	analogWriteFrequency(11, 101867.58);
	analogWriteFrequency(12, 101867.58);
	analogWriteFrequency(13, 101867.58);
	// 1s/101867.58/128 = 76.69ns, *2=153.39ns, *3=230.08ns, *4=306.77ns
	analogWrite(6, 1); //73ns
	analogWrite(7, 2); //153.2ns
	analogWrite(8, 3); //226.5ns
	analogWrite(9, 4); //306ns
	
	analogWrite(10, 1); //73ns
	analogWrite(11, 2); //146.5ns
	analogWrite(12, 3); //226.5ns
	analogWrite(13, 4); //299ns
}

void loop()                     
{
}

PWM pins 1,2,3,4,5,6,7,8,9,22,23 behave slightly differently than pins 10,11,12,13,14,15,18,19 at a frequency = 101867.58 and higher

at 101867.57Hz the pins 10-15,18,19 start to behave the way 1-9,22,23 do

anyway the odd values are still slightly off of what I would expect (73ns instead of 76-77ns, 226.5ns instead of 230ns)

what's going on? why do the two groups of pins behave differently? what's special about 101867.58Hz? And what's the highest frequency I should use if I want consistent pulse widths?
 
Status
Not open for further replies.
Back
Top