Teensy 4.0 SoftPWM example fails

ednl

New member
Hi, I loaded the SoftPWM_Arduino_LED_Blink example and it fails to compile:
Code:
/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/SoftPWM/SoftPWM.cpp: In function 'void SoftPWMSet(int8_t, uint8_t, uint8_t)':
/Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/SoftPWM/SoftPWM.cpp:247:42: error: cannot convert 'volatile uint32_t* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
     _softpwm_channels[firstfree].outport = portOutputRegister(digitalPinToPort(pin));
                                          ^

In addition, it says "multiple libraries found" but the one it apparently used is also the only one I can find: /Applications/Arduino.app/Contents/Java/hardware/teensy/avr/libraries/SoftPWM

This is on macOS 10.14.6 with Arduino 1.8.10 and Teensyduino 1.48. I successfully loaded and ran the basic Blink example before this.
 
Perhaps a silly thought from my side: The Teensy 4 has 4 flexpwm modules with 4 independent sub modules which have 3 independent channels, each. That makes already 48 hardware PWM channels. Then, there are 4 universal timer modules with 4 independent channels each. Makes 16 more opportunities for PWM. Even though not all of these 64 potential PWM signals are brought out to pins, there doesn’t seem any reason to waste CPU cycles with software PWM...
 
Sure. I don't think they can be used for the built-in LED, though. Also I'm sure the code will work, at least to some degree, if I just insert a cast. My point was more that this basic example fails which rather discouraged me and might others.
 
The built-in LED is on pin 13 which is a hardware capable PWM pin. So you can easily use the Teensyduino core features like analogWrite(), analogWriteResolution(), analogWriteFrequency() without having a library to include.
 
Thank you. Yes, that works. I made this for a ~linear looking heartbeat:
Code:
#define BASE 7.5

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

void loop()
{
	float x = 0.0, inc = 0.01, amp = 255.0 / (BASE - 1);
	int y;
	while (x >= 0 && x <= 1) {
		y = (int)(amp * (pow(BASE, x) - 1) + 0.5);
    Serial.println(y);
		analogWrite(13, y);
		x += inc;
		if (x >= 1) {
			x = 1;
			inc = -inc;
		} else if (x <= 0) {
			x = 0;
			inc = -inc;
		}
		delay(15);
	}
}
but I'm afraid my point remains. It's just that a basic example doesn't work out of the box and that could be discouraging. It was, for me: "Why does this simple example not even work?" This issue could be low priority and there's a lot to do obviously, but worth mentioning anyway, I thought.
 
There is an IDE 1.8.10 issue falsely reporting the 'Multiple Libraries Found'. It is only a user confusion issue - everything builds properly.

That code works properly in IDE 1.8.9 - a change in the IDE broke the proper reporting of that.

You can check the initial posts on the T4_Beta thread and see if SoftPWM is shown there as known to not work. If so - it is on the list. If not post here or on that thread and it will get added.
 
Back
Top