Change motor pin

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
KW272
Posts: 4
Joined: Fri Apr 25, 2014 10:19 am

Change motor pin

Post by KW272 »

Hi,

I build my quad with the Hobbyking ATmega 2560 V2.0 Controller. But my PWM output for motor 4 is broken.
I tried to change the output to anpther pin, but I couldnt figure it out how to do it.

Does someone know how to change the motor pins on MultiWii 2.3?

QuadBow
Posts: 532
Joined: Fri Jan 04, 2013 10:06 am

Re: Change motor pin

Post by QuadBow »

KW272 wrote:Does someone know how to change the motor pins on MultiWii 2.3?

Yes, I do.
However, it requires significant changes in the file output.cpp, and therefore, is not that simple.
Furthermore, it limits your expansion possibilities (e.g. shifting to a hex or octo configuration).
In case you can claim for warranty, do so and get a new board.
In case you have broken the pin-out yourself, provide the information of your configuration:
- copter type
- motor pins still available
- servos required

KW272
Posts: 4
Joined: Fri Apr 25, 2014 10:19 am

Re: Change motor pin

Post by KW272 »

Hi QuadBow, thank you for your reply.

I can not return the board therefore I would be very pleased, if you help me to change the code.

I have a QUADX. The broken pin is pin 6, (for the 4th motor).
I dont need any servos.

waltr
Posts: 733
Joined: Wed Jan 22, 2014 3:21 pm
Location: Near Philadelphia, Pennsyvania, USA

Re: Change motor pin

Post by waltr »

What is broken? the physical connector pin? or the Atmega output?
Is just the connector pin then it may be best to replace the connector.
If the Atmega output is bad then changing the code is the only way to fix it.
I have never tried this so do not know how its done. I think I've seen other threads here about this.

KW272
Posts: 4
Joined: Fri Apr 25, 2014 10:19 am

Re: Change motor pin

Post by KW272 »

No its the ATmega output. I have read the threads about changing the motor pins, but they are for older Multiwii versions. It does not work with multiwii 2.3

QuadBow
Posts: 532
Joined: Fri Jan 04, 2013 10:06 am

Re: Change motor pin

Post by QuadBow »

KW272 wrote:The broken pin is pin 6, (for the 4th motor).

OK, pin 6 is related to motor number 2 due to the programming schema.
I show you how to hijack the pin 7, which can't be used without confusion any more for a hex or an octo.

Look for the following code in the file output.cpp:

Code: Select all

     #if (NUMBER_MOTOR > 2)
      #ifndef EXT_MOTOR_RANGE
        OCR4A = motor[2]<<3; //  pin 6
      #else
        OCR4A = ((motor[2]<<4) - 16000);
      #endif
    #endif


and replace it by:

Code: Select all

      #if (NUMBER_MOTOR > 2)
      #ifndef EXT_MOTOR_RANGE
        OCR4B = motor[2]<<3; //  pin 7
      #else
        OCR4B = ((motor[2]<<4) - 16000);
      #endif
    #endif


Furthermore, you have to swap the pin assignment as follows:

Code: Select all

#if defined(MEGA)
  uint8_t PWM_PIN[8] = {3,5,7,2,6,8,9,10};      //for a quad+: rear,right,left,front   //+ for y6: 7:under right  8:under left
#endif


And the initialisation shown below

Code: Select all

    #if (NUMBER_MOTOR > 2)
      // init 16bit timer 4
      TCCR4A |= (1<<WGM41); // phase correct mode
      TCCR4A &= ~(1<<WGM40);
      TCCR4B |= (1<<WGM43);
      TCCR4B &= ~(1<<CS41); // no prescaler
      ICR4   |= 0x3FFF; // TOP to 16383;   
      TCCR4A |= _BV(COM4A1); // connect pin 6 to timer 4 channel A
    #endif


has to be changed to:

Code: Select all

    #if (NUMBER_MOTOR > 2)
      // init 16bit timer 4
      TCCR4A |= (1<<WGM41); // phase correct mode
      TCCR4A &= ~(1<<WGM40);
      TCCR4B |= (1<<WGM43);
      TCCR4B &= ~(1<<CS41); // no prescaler
      ICR4   |= 0x3FFF; // TOP to 16383;   
      TCCR4A |= _BV(COM4B1); // connect pin 7 to timer 4 channel B
    #endif


That should it be. I hope I have not forgotten anything.
But, I have only derived it from the code, I have not tested it.
So, I do not guarantee anything. All changes you adapt are at your own risk.
Have much success!

KW272
Posts: 4
Joined: Fri Apr 25, 2014 10:19 am

Re: Change motor pin

Post by KW272 »

I changed the code, but still the same problem, just at pin 7.

I think the timer is broken. pin 6 and 7 are both connected to timer 4. I tried to connect pin 6 to timer 5. but now my motor starts and stops really quick.

Timer 2 (pin 9 and 10) is an 8 bit timer.

How can i change the timer of pin 6?

User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

Re: Change motor pin

Post by Hamburger »

You cannot.
Configure a hex and use your private mixing with avoiding the motor[x] which relates to broken pin.
If you cannot figure that out buy new board

User avatar
shikra
Posts: 783
Joined: Wed Mar 30, 2011 7:58 pm

Re: Change motor pin

Post by shikra »

^^ neat idea..

mathieu974
Posts: 3
Joined: Thu Jun 05, 2014 8:50 pm

Re: Change motor pin

Post by mathieu974 »

Hey guys
Ive the same problem, my pin 6 seems to be dead (crius aiop)...
Is there a software solution because i would like to use my board in a tricopter and i should have a yaw servo pin allocation...
Does the hexa solution work for a quad?
What is the "private mixing"?

Note : i have 2.2volts at each pin but 4.2volts at the pin 6...


Thx a lot

User avatar
haydent
Posts: 583
Joined: Sun Jun 17, 2012 1:35 am
Location: NSW, AU

Re: Change motor pin

Post by haydent »

Hamburger wrote:You cannot.
Configure a hex and use your private mixing with avoiding the motor[x] which relates to broken pin.
If you cannot figure that out buy new board


this works easy enough :)

concept is, enable copter type that has more motors, then specify layout file so extra available motors have same values as broken pin/s

http://www.multiwii.com/wiki/index.php? ... ual_Mixing

have a look at output.cpp to find layouts default mix

IamTheVector
Posts: 7
Joined: Mon May 25, 2015 5:53 pm

Re: Change motor pin

Post by IamTheVector »

this is the correct answer. Worked for me :

viewtopic.php?f=16&t=1681&p=66138#p66138

No "extra pin enabled" or other strange methods .

Post Reply