atomicServo declared and written but never used for HW PWM?

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
User avatar
Hamburger
Posts: 2578
Joined: Tue Mar 01, 2011 2:14 pm
Location: air
Contact:

atomicServo declared and written but never used for HW PWM?

Post by Hamburger »

Hi,
I just uploaded HW PWM servo generation code for the a32u4 mcu. I mostly followed the implementation route for the mega hw pwm servo code that was already there. But I think I found an old error, I would like your comments on:

1. in Output.ino around line 50:

Code: Select all

/**************************************************************************************/
/***************         Software PWM & Servo variables            ********************/
/**************************************************************************************/
#if defined(PROMINI) || (defined(PROMICRO) && defined(HWPWM6)) || \
  (defined(MEGA) && defined(MEGA_HW_PWM_SERVOS))  || (defined(PROMICRO) && defined(A32U4_4_HW_PWM_SERVOS))
  #if defined(SERVO)
    #if defined(AIRPLANE) || defined(HELICOPTER)
      // To prevent motor to start at reset. atomicServo[7]=5 or 249 if reversed servo
      volatile uint8_t atomicServo[8] = {125,125,125,125,125,125,125,5};
    #else
      volatile uint8_t atomicServo[8] = {125,125,125,125,125,125,125,125};
    #endif
  #endif

this initializes atomicServo[] even for HW PWM servo use. Some lines later in writeServos() new values are written into atomicServo[]. But atomicServo[] would only ever get used in the ISR(SERVO_ISR) function which is only initialized for soft pwm servo generation ?!?

In essence, I think the macro conditions from the beginning must exclude the HW_PWM_SERVO cases; so really must read like this:

Code: Select all

#if defined(PROMINI) || (defined(PROMICRO) && defined(HWPWM6)  && !defined(A32U4_4_HW_PWM_SERVOS)) || \
  (defined(MEGA) && !defined(MEGA_HW_PWM_SERVOS))  || (defined(PROMICRO) && !defined(A32U4_4_HW_PWM_SERVOS))


That would remove the entire atomicServo[] code for hw pwm servo use. All this hardware / interrupt handling is way over my head, so I ask for comments from the experts, please.

Mis
Posts: 203
Joined: Fri Apr 01, 2011 12:23 am

Re: atomicServo declared and written but never used for HW P

Post by Mis »

Yes, you're hight. atomicServo is not used with HW_PWM.
But little simplify your condition:

Code: Select all

/**************************************************************************************/
/***************         Software PWM & Servo variables            ********************/
/**************************************************************************************/
#if defined(PROMINI) || (defined(PROMICRO) && defined(HWPWM6) && !defined(A32U4_4_HW_PWM_SERVOS) || (defined(MEGA) && !defined(MEGA_HW_PWM_SERVOS))
  #if defined(SERVO)
    #if defined(AIRPLANE)|| defined(HELICOPTER)
...
...

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

Re: atomicServo declared and written but never used for HW P

Post by Hamburger »

Mis wrote:Yes, you're hight. atomicServo is not used with HW_PWM.

ok. thanks for clarifying. I will try and find proper cpp conditionals for all code segments in question.

Alexinparis
Posts: 1630
Joined: Wed Jan 19, 2011 9:07 pm

Re: atomicServo declared and written but never used for HW P

Post by Alexinparis »

Hamburger wrote:
Mis wrote:Yes, you're hight. atomicServo is not used with HW_PWM.

ok. thanks for clarifying. I will try and find proper cpp conditionals for all code segments in question.


there is an error in your last mod here : && !defined(MEGA_HW_PWM_SERVOS)

Mis
Posts: 203
Joined: Fri Apr 01, 2011 12:23 am

Re: atomicServo declared and written but never used for HW P

Post by Mis »

Hamburger, please extend

Code: Select all

#if defined(MEGA) && defined(MEGA_HW_PWM_SERVOS)
  #undef SERVO_1_HIGH                                    // No software PWM's if we use hardware MEGA PWM
#endif
in "def.h" to

Code: Select all

#if (defined(MEGA) && defined(MEGA_HW_PWM_SERVOS)) || (defined(PROMICRO) && defined(A32U4_4_HW_PWM_SERVOS))
  #undef SERVO_1_HIGH                                    // No software PWM's if we use hardware MEGA PWM
#endif

and stop writing tons of "!defined(A32U4_4_HW_PWM_SERVOS)" conditions.

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

Re: atomicServo declared and written but never used for HW P

Post by Hamburger »

@mis
? I already did that in my first mod r1464.
edit: I get the idea though, now using HW_PWM_SERVOS

@Alex
sure. I only ever thought 'servo' but missed the motors' variables setup was being done in the same code section.
hopefully fixed now.
Last edited by Hamburger on Fri Jun 14, 2013 10:11 am, edited 1 time in total.

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

Re: atomicServo declared and written but never used for HW P

Post by Hamburger »

couple questions:
1.
for mega, is soft servo pwm still required or could that be removed?

2.
for promicro hw servo pwm I had to have a new motor[0] pin, so I changed it to

Code: Select all

    #elif defined(A32U4_4_HW_PWM_SERVOS)
      uint8_t PWM_PIN[8] = {6,9,10,11,5,13,SW_PWM_P3,SW_PWM_P4};   //
    #else
      uint8_t PWM_PIN[8] = {9,10,5,6,11,13,SW_PWM_P3,SW_PWM_P4};   //for a quad+: rear,right,left,front
    #endif

The first is obvious then, but for the other pins I used the same as for the servos, without really knowing what I was doing. What would be a meaningful sequence of pwm pins and how to get it?

Post Reply