Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 7 of 7

Thread: Teensy 4.0 SoftPWM example fails

  1. #1
    Junior Member
    Join Date
    Oct 2019
    Location
    Netherlands
    Posts
    3

    Teensy 4.0 SoftPWM example fails

    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.

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,530
    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...

  3. #3
    Junior Member
    Join Date
    Oct 2019
    Location
    Netherlands
    Posts
    3
    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.

  4. #4
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,530
    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.

  5. #5
    Junior Member
    Join Date
    Oct 2019
    Location
    Netherlands
    Posts
    3
    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.

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,675
    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.

  7. #7
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,675
    Indeed SoftPWM is in the list of libraries not yet updated for Teensy 4.0:

    Teensy-4-0-First-Beta-Test … Post #4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •