Change engine to another 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
pachucho1024
Posts: 16
Joined: Wed Mar 14, 2012 5:16 pm

Change engine to another pin.

Post by pachucho1024 »

Hello friends, I'm Spanish.

It broke my arduino pin 5 MEGA and I broke the pin 10 of Arduino Pro Mini, they are both motor output.

I do not know MULTIWII change the code to change the pin engine, anyone know how? someone can tell me where I can read and learn?

I just need to change a motor.

Thanks, I hope to get lucky, I can fly my quadricopter.

PatrikE
Posts: 1976
Joined: Tue Apr 12, 2011 6:35 pm
Location: Sweden
Contact:

Re: Change engine to another pin.

Post by PatrikE »

In Output.pde

Code: Select all

#if defined(PROMINI)
  uint8_t PWM_PIN[8] = {9,10,11,3,6,5,A2,12};   //for a quad+: rear,right,left,front
#endif
#if defined(PROMICRO)
  #if !defined(HWPWM6)
    uint8_t PWM_PIN[8] = {9,10,5,6,4,A2,A0,A1};   //for a quad+: rear,right,left,front
  #else
    uint8_t PWM_PIN[8] = {9,10,5,6,11,13,A0,A1};   //for a quad+: rear,right,left,front
  #endif
#endif
#if defined(MEGA)
  uint8_t PWM_PIN[8] = {3,5,6,2,7,8,9,10};      //for a quad+: rear,right,left,front   //+ for y6: 7:under right  8:under left
#endif

pachucho1024
Posts: 16
Joined: Wed Mar 14, 2012 5:16 pm

Re: Change engine to another pin.

Post by pachucho1024 »

PatrikE Thanks! no one had answered this question.

The version I use is MultiWii_dev_20120203, the variable 'PWM_PIN uint8_t [8]' does not exist. Any version of multiwii is good for me, I have no sensors.

Can you tell me which version you use?
which is the version where the variable appears 'PWM_PIN uint8_t [8]'?

Thank you !!

PatrikE
Posts: 1976
Joined: Tue Apr 12, 2011 6:35 pm
Location: Sweden
Contact:

Re: Change engine to another pin.

Post by PatrikE »

It's in the V2 pre versions.

In older realeases it's in def.pde.

Code: Select all

  #define MOTOR_ORDER                3,5,6,2,7,8,9,10   //for a quad+: rear,right,left,front  

ronco
Posts: 317
Joined: Thu Aug 18, 2011 2:58 pm

Re: Change engine to another pin.

Post by ronco »

Hi,

it isnt that esay .. on the promini there are just 4 usable PWM pins .. if you broke pin 10 there is no real replacement .. it is possible to use software PWM on other pins but this would require a large code manipulation.

on the mega are more PWM pins .. but since we dont use analoWrite anymore its also not that easy.


the simplest way is to chose a free PWM pin on this list https://spreadsheets.google.com/pub?key ... GPkA&gid=0
witch is driven by timer 1 (pin 11, pin 12 or pin 13) or timer 5 (pin 44, pin 45 or pin 46)

and use it like this:

in output.pde

Code: Select all

void writeMotors() { // [1000;2000] => [125;250]
  #if defined(MEGA)// [1000:2000] => [8000:16000] for timer 3 & 4 for mega
    #if (NUMBER_MOTOR > 0)
      #ifndef EXT_MOTOR_RANGE
        OCR3C = motor[0]<<3; //  pin 3
      #else
        OCR3C = ((motor[0]<<4) - 16000) + 128;
      #endif
    #endif


    #if (NUMBER_MOTOR > 1)
      #ifndef EXT_MOTOR_RANGE
        //OCR3A = motor[1]<<3; //  pin 5
        analogWrite(chosenPin,motor[1]>>3);
      #else
        //OCR3A = ((motor[1]<<4) - 16000) + 128;
        analogWrite(chosenPin,((motor[1]>>2) - 250) + 2);
      #endif
    #endif
  ...


chosenPin = the free PWM Pin

regards felix
Last edited by ronco on Mon Mar 19, 2012 3:37 pm, edited 1 time in total.

pachucho1024
Posts: 16
Joined: Wed Mar 14, 2012 5:16 pm

Re: Change engine to another pin.

Post by pachucho1024 »

I will try as soon as possible
It seems much easier than I imagined, but unknowingly ...
I'll tell you when I can prove it. I will use the V2 multiwii

PatrikE Thanks!

pachucho1024
Posts: 16
Joined: Wed Mar 14, 2012 5:16 pm

Re: Change engine to another pin.

Post by pachucho1024 »

PatrikE Thanks for your help, but that way I get nothing.

ooooOOOOooooOOOOOOOoo ...... thanks ronco !!! Your code by convincing. I tried several times to change, but I could not.
I'm programmer and work in Java, the language of multiwii do not know, but I see you're in control.

With your help I will be able to mount a quadricopter with MEGA :D :D , a pity that I can not take advantage of the PRO MINI for tricopter :(

Thank you very much ronco !! I'll tell you when to fix it.

Good forum with good people, no one before I answered this question.

ronco
Posts: 317
Joined: Thu Aug 18, 2011 2:58 pm

Re: Change engine to another pin.

Post by ronco »

Hi,

if you "just" want to use the promini (with the broken pin 10) for a tricopter it is more easy! because the yaw servo is still powerd with soft pwm.

and for the mega .. i have none so i cant test it .. if you tell me your setup (tri or quad or hexa...) i may give you a working code but with such changes you will have to add it in each new version you want to use...


regards felix

ronco
Posts: 317
Joined: Thu Aug 18, 2011 2:58 pm

Re: Change engine to another pin.

Post by ronco »

... if you have some soldering skills you may connect pin 10 of the promicro direct on the chip
but be careful ;)
Attachments
pin10.jpg

PatrikE
Posts: 1976
Joined: Tue Apr 12, 2011 6:35 pm
Location: Sweden
Contact:

Re: Change engine to another pin.

Post by PatrikE »

There's a hack you can do to get PROMINI to work.
Add a mitorPin.
In def.h change to 4 motors.

Code: Select all

#elif defined(TRI)
  #define NUMBER_MOTOR     4 // Change from 3 To 4
  #define PRI_SERVO_FROM   4 // Move servo  from 6 to 4.
  #define PRI_SERVO_TO     4


And move servo to D12
In output. change to.

Code: Select all

  #ifdef TRI
    motor[0] = PIDMIX( 0,+4/3, 0); //REAR
    motor[1] = PIDMIX(-1,-2/3, 0); //RIGHT
    motor[2] = PIDMIX(+1,-2/3, 0); //LEFT
    motor[3] = motor[1];          // Copy RIGHT motor to D3 

// Change servo to D12 =servo[3]
    servo[3] = constrain(tri_yaw_middle + YAW_DIRECTION * axisPID[YAW], TRI_YAW_CONSTRAINT_MIN, TRI_YAW_CONSTRAINT_MAX); //REAR
  #endif


This will Copy Pin 10 to Pin 3.
Servo will be moved to pin 12.

/Patrik

pachucho1024
Posts: 16
Joined: Wed Mar 14, 2012 5:16 pm

Re: Change engine to another pin.

Post by pachucho1024 »

ronco Thanks, your solution seems a sure thing.

First I will try the solution Patrik, but if I fail, as I said welding ronco.

Patrik as you know so much code? thanks for your solution and time, I think this week I can fix it perfectly.

Good people around here willing to help ....

Thanks to all friends.

Zarquon
Posts: 3
Joined: Wed Apr 25, 2012 1:58 am

Re: Change engine to another pin.

Post by Zarquon »

I’m still not clear on how to do this.

I’m using a Crius lite board and seem to have problems with the traces for pin D11. Since the documentation for the board seems to say it supports hexcopters, I was hoping to shift the quad to use either D5 or D6 as a replacement for D11. I tried switching the order of the PWM_PIN set and it did not work. Is there something else I’m missing?

Post Reply