0

I am using Arduino Micro. Is there any way to use PWM on pin 4 instead of Pin3 ?

I tried to change pins_Arduino.h but didnt worked.

//#define digitalPinHasPWM(p)         ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11 || (p) == 13)

#define digitalPinHasPWM(p)         ((p) == 4 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11 || (p) == 13)

and

const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
    NOT_ON_TIMER,   
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    ////////////////////////modified///////////////
    //TIMER0B,      /* 3 */
    //NOT_ON_TIMER,
    NOT_ON_TIMER,
    TIMER0B,        /* 4 */
    ////////////////////////////////////////////////////
    TIMER3A,        /* 5 */
    TIMER4D,        /* 6 */
    NOT_ON_TIMER,   

    NOT_ON_TIMER,   
    TIMER1A,        /* 9 */
    TIMER1B,        /* 10 */
    TIMER0A,        /* 11 */

    NOT_ON_TIMER,   
    TIMER4A,        /* 13 */

    NOT_ON_TIMER,   
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,

    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
};
4
  • @Majenko has answered your question. What many do not realize is that there are many Aruidno boards with a number of different processors. It is difficult to make them all work alike. That is, using the "Arduino set of software" (Libraries, boot loaders, ect), it is difficult to abstract the hardware to make all Arduino boards act exactly like the original Arduino Uno. I think you can do what you want on an Arduino Mega board.
    – st2000
    Commented Sep 10, 2017 at 14:05
  • i am willing to modify the abstraction layers. Just want to make sure that it will work if i modify the libraries Commented Sep 10, 2017 at 14:56
  • The Micro layout: pighixxx.com/test/portfolio-items/micro
    – Jot
    Commented Sep 10, 2017 at 15:16
  • 1
    You need to understand both the hardware and software before starting. It may be that no matter what you do there isn't PWM hardware on pin 4 of the micro you are using. However, if you understand what you goals are you may be able to implement a software PWM. But, likely, you would have to use interrupts for timing. And that might interfere with other Arduino features / functions. At some point it may just be easier to use a more feature rich micro. Especially if this is a one off project.
    – st2000
    Commented Sep 11, 2017 at 0:04

1 Answer 1

1

You cannot. There is no PWM on that pin. PWM is generated by hardware. The hardware simply does not exist.

8
  • even something slimier to 'Software Serial' not available? Commented Sep 10, 2017 at 14:55
  • Software PWM is possible but quite intensive. Servo.h does it but only for very low duty cycles.
    – Majenko
    Commented Sep 10, 2017 at 14:57
  • my intention is to control a dc motor driver(TB6612FNG) that needs PWM inputs Commented Sep 10, 2017 at 14:58
  • You get glitches is software PWM which makes it a poor choice for motor control.
    – Majenko
    Commented Sep 10, 2017 at 14:59
  • sad to hear that, and thank you so much for your support Commented Sep 10, 2017 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.