Change Motor Pin Order

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
Movo
Posts: 12
Joined: Sun Feb 08, 2015 1:24 pm

Change Motor Pin Order

Post by Movo »

Hello,
I've got the problem, that pin 9 on my FC (http://www.hobbyking.com/hobbyking/stor ... ouse_.html) is broken. Now i tried to change the pin order in the output.cpp. The Image in the Gui changed but no signal is send at the pin. I read posts (this one: viewtopic.php?f=8&t=1382) about changing the pin order but not for my FC. Please tell me where i have to change what.
Thanke you, I hope its not to difficult!

TheBum
Posts: 35
Joined: Wed Dec 03, 2014 9:53 pm

Re: Change Motor Pin Order

Post by TheBum »

You'll likely have to change PWM_PIN and writeMotors(). Do you know what Arduino board type it is?

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

Re: Change Motor Pin Order

Post by Hamburger »

TheBum wrote:You'll likely have to change PWM_PIN and writeMotors(). Do you know what Arduino board type it is?

If you have detailed knowledge on how to do this, maybe you could write up some howto on "Change pin order" for the wiki?
This question pops up again and again, more often from users with obviously so little knowledge one is tempted to advise to buy a new board. Others only lack the easy route in the MWii code's whereabouts and are good to go with few simple pointers.

TheBum
Posts: 35
Joined: Wed Dec 03, 2014 9:53 pm

Re: Change Motor Pin Order

Post by TheBum »

I've been going through the Output.cpp code to find out if I can steal one of the timers for HoTT telemetry transmission, so I'm beginning to develop an understanding for how motor and servo output works. I can understand why someone hasn't come up with clear instructions; the code is pretty intimidating. I could sure give it a shot...after I finish with my telemetry mods.

Movo
Posts: 12
Joined: Sun Feb 08, 2015 1:24 pm

Re: Change Motor Pin Order

Post by Movo »

My board has the Atmega32u4 so i have to use leonardo in arduino. Hope you can fix it, this code is to complex and hard to read for me :)

TheBum
Posts: 35
Joined: Wed Dec 03, 2014 9:53 pm

Re: Change Motor Pin Order

Post by TheBum »

Yeah, the PROMICRO code is especially convoluted because it has to make lemonade out of lemons (limited resources). The PROMINI code is a little less convoluted. That's one advantage I've seen to using a Mega: there aren't any special cases that depend on number of motors and number of servos; there are some dual use resources, but they're static.

Does the normal pin order start with 9, 10, 5, 6? Also, which aircraft type is it?

Movo
Posts: 12
Joined: Sun Feb 08, 2015 1:24 pm

Re: Change Motor Pin Order

Post by Movo »

yeah it starts with 9,10,5,6 and its a quadx.

User avatar
skypup
Posts: 7
Joined: Mon Sep 01, 2014 3:15 pm

Re: Change Motor Pin Order

Post by skypup »

First step, "def.h".

#elif defined(QUADP) || defined(QUADX) || defined(Y4)|| defined(VTAIL4)
#define NUMBER_MOTOR 4

Change to:

#elif defined(QUADP) || defined(QUADX) || defined(Y4)|| defined(VTAIL4)
// #define NUMBER_MOTOR 4
#define NUMBER_MOTOR 8 // Change Pin Order


Second step, "Output.cpp".


******** Specific PWM Timers & Registers for the atmega328P (Promini) ************/
#if defined(PROMINI)
#if (NUMBER_MOTOR > 0)
#ifdef EXT_MOTOR_RANGE // 490Hz
OCR1A = ((motor[0]>>2) - 250);
#elif defined(EXT_MOTOR_32KHZ)
OCR1A = (motor[0] - 1000) >> 2; // pin 9
#elif defined(EXT_MOTOR_4KHZ)
OCR1A = (motor[0] - 1000) << 1;
#elif defined(EXT_MOTOR_1KHZ)
OCR1A = (motor[0] - 1000) << 3;
#else
OCR1A = motor[0]>>3; // pin 9
#endif


Change to:

/******** Specific PWM Timers & Registers for the atmega328P (Promini) ************/
#if defined(PROMINI)
#if (NUMBER_MOTOR > 0)
#ifdef EXT_MOTOR_RANGE // 490Hz
OCR1A = ((motor[0]>>2) - 250);
#elif defined(EXT_MOTOR_32KHZ)
OCR1A = (motor[0] - 1000) >> 2; // pin 9
#elif defined(EXT_MOTOR_4KHZ)
OCR1A = (motor[0] - 1000) << 1;
#elif defined(EXT_MOTOR_1KHZ)
OCR1A = (motor[0] - 1000) << 3;
#else
#if defined(QUADX)
OCR1A = motor[3]>>3; // Change Pin
#else
OCR1A = motor[0]>>3; // pin 9
#endif
#endif

User avatar
skypup
Posts: 7
Joined: Mon Sep 01, 2014 3:15 pm

Re: Change Motor Pin Order

Post by skypup »

First step, "def.h".

#elif defined(QUADP) || defined(QUADX) || defined(Y4)|| defined(VTAIL4)
#define NUMBER_MOTOR 4


Change to:

#elif defined(QUADP) || defined(QUADX) || defined(Y4)|| defined(VTAIL4)
// #define NUMBER_MOTOR 4
#define NUMBER_MOTOR 8 // Change Pin Order


Second step, "Output.cpp".

******** Specific PWM Timers & Registers for the atmega328P (Promini) ************/
#if defined(PROMINI)
#if (NUMBER_MOTOR > 0)
#ifdef EXT_MOTOR_RANGE // 490Hz
OCR1A = ((motor[0]>>2) - 250);
#elif defined(EXT_MOTOR_32KHZ)
OCR1A = (motor[0] - 1000) >> 2; // pin 9
#elif defined(EXT_MOTOR_4KHZ)
OCR1A = (motor[0] - 1000) << 1;
#elif defined(EXT_MOTOR_1KHZ)
OCR1A = (motor[0] - 1000) << 3;
#else
OCR1A = motor[0]>>3; // pin 9
#endif


Change to:

/******** Specific PWM Timers & Registers for the atmega328P (Promini) ************/
#if defined(PROMINI)
#if (NUMBER_MOTOR > 0)
#ifdef EXT_MOTOR_RANGE // 490Hz
OCR1A = ((motor[0]>>2) - 250);
#elif defined(EXT_MOTOR_32KHZ)
OCR1A = (motor[0] - 1000) >> 2; // pin 9
#elif defined(EXT_MOTOR_4KHZ)
OCR1A = (motor[0] - 1000) << 1;
#elif defined(EXT_MOTOR_1KHZ)
OCR1A = (motor[0] - 1000) << 3;
#else
#if defined(QUADX)
OCR1A = motor[3]>>3; // Change Pin
#else
OCR1A = motor[0]>>3; // pin 9
#endif
#endif


Change other pin:

#if (NUMBER_MOTOR > 6) //note: EXT_MOTOR_RANGE not possible here
atomicPWM_PINA2_highState = ((motor[6]-1000)>>2)+5;
atomicPWM_PINA2_lowState = 245-atomicPWM_PINA2_highState;
#if defined(QUADX)
atomicPWM_PIN12_highState = ((motor[1]-1000)>>2)+5; // Change Pin
#else
atomicPWM_PIN12_highState = ((motor[7]-1000)>>2)+5;
#endif
atomicPWM_PIN12_lowState = 245-atomicPWM_PIN12_highState;
#endif

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

Re: Change Motor Pin Order

Post by IamTheVector »

this is the correct answer. Worked for me :

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

Post Reply