Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. PWM frequencies on pin 9,10,11

PWM frequencies on pin 9,10,11

Scheduled Pinned Locked Moved Hardware
7 Posts 6 Posters 3.4k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    boozz
    wrote on last edited by
    #1

    Hi All,

    I use pro-mini's in many different projects, and of course for mysensor nodes and repeaters and so on. All of them are the 16 MHz 5 VDC versions with a boot loader that makes them think they're Arduino Uno's..:stuck_out_tongue_winking_eye:
    I use them as a standard, which enables me to pick any pro-mini lying around in my workspace and use it to test a new revision in my sensors...

    Now for the question: for a specific project I want to change the frequencies of the PWM pins 9, 10 and 11. As a default they seem to be 490.20 Hz and I need some kHz. What happens if I want to reuse these pro-mini's with altered PWM frequencies for a my-sensor node.
    Are the PWM pins set by the mysensors (library) code automatically?

    Thanks for your answers,

    Boozz

    1 Reply Last reply
    0
    • mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      By default, pins 9, 10 and 11 are used by the nrf radio but they can be remapped using softspi. See https://www.mysensors.org/build/ethernet_gateway for instructions.

      As long as the pins are not used by the radio, MySensors shouldn't affect the pins. Changing the pwm speed can affect the timers though, which can have an impact on the MySensors code. I am not sure which timers are used by MySensors, but timer1 is used by almost anything so changing that will probably have side-effects.

      See https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM and http://playground.arduino.cc/Code/PwmFrequency for details on different PWM settings.

      1 Reply Last reply
      2
      • scalzS Offline
        scalzS Offline
        scalz
        Hardware Contributor
        wrote on last edited by scalz
        #3

        and you will need to be careful in sketch because if you need to change your pwm freq, you will certainly need to change prescaler settings for interrupt as @mfalkvidd rightly told you. And that would need more care if you use softspi for radio...because of timings etc...but that's doable :)
        imho I would prefer use hardware spi for radio (more reliable I think) and use other pins for pwm.

        I have never done this in arduino yet (multiple software pwm) but I did it on microchip mcu few years ago. I was able to pwm almost all pins on these 8bit mcu. For this, like explained in links above, I was using output compare registers and I was updating the needed pins in interrupthandler. You can use the howto explained of course, but if you use an interrupthandler you can play with others pins when interrupt triggers.
        So it was sort of "blink without delay" using output compare mode timers and few optimizations..like this you can pwm lot of pins ;)

        Note : I was not using things like pinwrite ...but was directly writing in the corresponding 8bit PORT pin, faster than the function which takes cycles and sometimes you want something precise...

        1 Reply Last reply
        1
        • greglG Offline
          greglG Offline
          gregl
          Hero Member
          wrote on last edited by
          #4

          I was having some probs with the led dimmer sketch the other night beacuse i wanted to use PIN6 rather than PIN3.
          My LED strip would flicker....had me puzzled for a bit until i remembered the mysensors v2 beta ( im using quite an old cut of it ) uses pin 6 for the RX/TX/ERR leds...
          So i just reassiged them in my sketch...and problem solved!
          #define MY_DEFAULT_TX_LED_PIN A2
          #define MY_DEFAULT_RX_LED_PIN A3
          #define MY_DEFAULT_ERR_LED_PIN A4

          This may not be relevant to your posts... but i thought it was a PWM frequency issue initially!

          C 1 Reply Last reply
          1
          • B Offline
            B Offline
            boozz
            wrote on last edited by
            #5

            Thanks for the answers.

            I'm not planning using soft-spi, as it would affect all of the hardware I've made so far (approx 30-40 PCB's for adaption of pro-mini and nrf's as well as some standard temperature and analog in connection).

            I guess at the moment it's the best for me to label the pro-mini's involved or add some extra code in the setup() part of the arduino code. I used this site for the examples how to set the pwm frequencies for the different pins.

            BR,

            Boozz

            1 Reply Last reply
            0
            • greglG gregl

              I was having some probs with the led dimmer sketch the other night beacuse i wanted to use PIN6 rather than PIN3.
              My LED strip would flicker....had me puzzled for a bit until i remembered the mysensors v2 beta ( im using quite an old cut of it ) uses pin 6 for the RX/TX/ERR leds...
              So i just reassiged them in my sketch...and problem solved!
              #define MY_DEFAULT_TX_LED_PIN A2
              #define MY_DEFAULT_RX_LED_PIN A3
              #define MY_DEFAULT_ERR_LED_PIN A4

              This may not be relevant to your posts... but i thought it was a PWM frequency issue initially!

              C Offline
              C Offline
              chickey
              wrote on last edited by
              #6

              You my friend are a genius, i was having flickering on my dimmer and couldn't get to the bottom of it. I was using pin 6 for controlling my LED strip.

              @gregl said:

              I was having some probs with the led dimmer sketch the other night beacuse i wanted to use PIN6 rather than PIN3.
              My LED strip would flicker....had me puzzled for a bit until i remembered the mysensors v2 beta ( im using quite an old cut of it ) uses pin 6 for the RX/TX/ERR leds...
              So i just reassiged them in my sketch...and problem solved!
              #define MY_DEFAULT_TX_LED_PIN A2
              #define MY_DEFAULT_RX_LED_PIN A3
              #define MY_DEFAULT_ERR_LED_PIN A4

              This may not be relevant to your posts... but i thought it was a PWM frequency issue initially!

              1 Reply Last reply
              1
              • M Offline
                M Offline
                MikeF
                wrote on last edited by
                #7

                I've found that adding this to setup() can cure flickering:

                  //Increase Timer frequency to prevent flicker in Pins 5,6 PWM
                  TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00); 
                
                1 Reply Last reply
                2
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                21

                Online

                11.7k

                Users

                11.2k

                Topics

                113.1k

                Posts


                Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • MySensors
                • OpenHardware.io
                • Categories
                • Recent
                • Tags
                • Popular