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,
};
  • @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 Sep 10 '17 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 – Sanu - Open Maker Sep 10 '17 at 14:56
  • The Micro layout: pighixxx.com/test/portfolio-items/micro – Jot Sep 10 '17 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 Sep 11 '17 at 0:04
1

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.