OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

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
ampere-dieter
Posts: 5
Joined: Wed Oct 12, 2011 12:31 pm

OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by ampere-dieter »

hello all,

I would like to inform you about my work to make Alex famous MultiWii software a little bit better.
Alex, you did a great job.
Originally I want to optimize the servo outputs only, but by the time it becomes a little bit more.

Then came out:
* PROMINI: 16 bit very low-jitter software PWM for 8 motors + 3 servos.
* MEGA: 16-bit pure hardware PWM - 12 channels, 400Hz. background operation, without IRQ-/CPU load.
* For both: 0.5 us time resolution for normal RX / SUM_PPM Rx.
Spectrum Sat routine extended to 12 channels (both frames used).
Works to reduce Jitter:
Replacement of the API functions for time delays and time measurements (disables all timer0_IRQs)
Some optimations in ISR routines to reduce interrupt time.
Replacement of timer polling code (heavy interrupt blocking cli , sei) by interruptable delay routines.


Here some more in detail:

PWM Promini:Output with 16 bit timer1, 8 channels for motors / 3 channels for servos with software PWM.
Now it is possible to use OCTOs with ProMini plus Camstab and Camtrigger.
There is no distinction made between servos / motors in PWM output handling.
PWM channels are fairly distributed to both Compare Modules A / B.
PWM output is realized in the ISR (TIMER1_COMP? _vect) in a chained method.
In one IRQ call output PWMA_n-1 is set low and PWMA_n is set high. So we have only half of IRQ load as now realized.
We have a resolution of 0.5us in puls lenght.
The repetition rate is due to the process variable and depends on the number of channels in each compare unit and pulse duration.
For a QUADRO with Camstab we have 222Hz@1.5ms.
For the OCTOs with Camstab we have 133Hz@1.5ms.
The accuracy of the pulse length is the most significant parameter. Only these value will be evaluated by the ESC.
The repetition rate determines the dynamic behavior of the copter.

The ISR for compare module A is as follows:
ISR(TIMER1_COMPA_vect) {
static uint8_t state = 0;
if (state == 0) {
PWMA0_lo;
PWMA1_hi;
OCR1A+= PWM_A1;
state++ ;
} else if (state == 1) {
PWMA1_lo;
PWMA2_hi;
OCR1A+= PWM_A2;
state++ ;
if (state == NO_PWMA) state = 0;
} else if (state == 2) {
PWMA2_lo;
PWMA3_hi;
OCR1A+= PWM_A3;
state++ ;
if (state == NO_PWMA) state = 0;
} else if (state == 3) {
PWMA3_lo;
PWMA4_hi;
OCR1A+= PWM_A4;
state++ ;
if (state == NO_PWMA) state = 0;
} else if (state == 4) {
PWMA4_lo;
PWMA5_hi;
OCR1A+= PWM_A5;
state = 0;
}
}



PWM-MEGA:Output with four 16-bit timer1,3,4,5. PWM in pure hardware with PWMwaveform 14.
12 channels total, of which nine channels have 400Hz repetition rate, 3 channels have 32Hz repetition rate.
All PWMs are running in background. No Timer IRQs neccesary. Update is realized with double bufferd compare-registers.
We can write to this registers at any time.
Some smaller topo modification are neccesary for OCTO motors 6,7. Motors 6,7 are moved to the 16-bit ports D11/D12.
It's very easy to change the repetition rates of the PWM triple by tuneing the ICRn values.

API-timer/delay substitute:
API micros() ----> micros16() or micros32()
API millis() ----> millis32
API delay(uint16_t ms) ----> delay0(uint16_t ms)
API delayMicroseconds(uint32_t us) ----> delayMicroseconds0(uint32_t us)


@Alex:
in zip file you find the new mega OCTO configuration (motor 6,7 mod)
and you have the configurations for the OCTO ProMini.
In the excel sheet you see the configuration for Pauls ARDDUINO mega.
My software mod is based on version MultiWii_dev_20120121.
Please push the PWM4-files to the code reviews page.

zip file: http://www.modfly.de/MultiWii/MultiWii_dev_20120121_PWM4.zip

Image

enjoy, dieter

Danal
Posts: 137
Joined: Tue Oct 18, 2011 5:15 pm

Re: OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by Danal »

Thanks Dieter! I'm re-writing the Spektrum to be more compatible with the new serial handlers. I've also taken out any library calls for Spektrum timing. This code also parses any/all frames and channels. My first draft is in the Danal branch.

And... I'll take a look in the zip and see what you did.

Cheers,

Danal

User avatar
aBUGSworstnightmare
Posts: 115
Joined: Mon Jun 27, 2011 8:31 pm
Location: Munich, Germany

Re: OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by aBUGSworstnightmare »

Hi Dieter,

sounds very promising! I will have a look at your sources and also test the new PWM with some piece of new hardware I'm currently developing 8-)

Rgds
aBUGSworstnightmare

User avatar
dramida
Posts: 473
Joined: Mon Feb 28, 2011 12:58 pm
Location: Bucharest
Contact:

Re: OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by dramida »

Awsome development Dieter! You have my appreciation sir! In the meantime you just reset the standards for mwc hardware market!

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

Re: OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by ronco »

Hi,

its really nice done :)

eaven with new error messages :P
/def.h:386:10: error: #error "to use OCTO with serial RX, you MUST use and configure SUM_PPM-/Spektrum_SAT-/SBUS-receiver or BTSERIAL"


but .. i did some quick indoor flight tests (small quad with WMP only) and i cant get a stable flight.. to have no oszillations i need lower P and I so much that its no longer stable :(

alex dev20120121 P=3,4 I=28 D=32

with yours p=2,1 I=15 D=32

or did i miss something?


regards Felix

User avatar
ampere-dieter
Posts: 5
Joined: Wed Oct 12, 2011 12:31 pm

Re: OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by ampere-dieter »

hi Felix,

you can get the error message "to use OCTO with serial RX, you MUST use and configure SUM_PPM-/Spektrum_SAT-/SBUS-receiver or BTSERIAL" only if you set a #define OCTO in config.h.
For your setup you have to uncomment a #define QUARDX / #define QUARDP in config.h.
I changed only the output routine. The calculation inside WultiWii software is not affected.

regards dieter

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

Re: OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by ronco »

Hi Dieter,

i know .. i did the define OCTO just to see how the pwm signals look..

my flight results are with quad x defined

regards Felix

User avatar
ampere-dieter
Posts: 5
Joined: Wed Oct 12, 2011 12:31 pm

Re: OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by ampere-dieter »

hi Felix,

if you use OCTO with normal receivers (even for test only), than ports D4, D5, D6, D7 are outputs for the motors.
What happend with your connected receiver???

regards, dieter

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

Re: OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by ronco »

i did it with an seperate pro mini.. with no reciver connected ;)

regards felix

ziss_dm
Posts: 529
Joined: Tue Mar 08, 2011 5:26 am

Re: OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by ziss_dm »

Hi,

but .. i did some quick indoor flight tests (small quad with WMP only) and i cant get a stable flight.. to have no oszillations i need lower P and I so much that its no longer stable

alex dev20120121 P=3,4 I=28 D=32

with yours p=2,1 I=15 D=32


I think, it is quite explainable:
1) Jitter > 8us
2) reduced update rate for esc's makes them to respond slower

regards,
ziss_dm

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

Re: OCTO ProMini, 11Bit PWM, 0.5us RX Resolution

Post by Alexinparis »

Hi,

ampere-dieter wrote:PWM Promini:Output with 16 bit timer1, 8 channels for motors / 3 channels for servos with software PWM.
Now it is possible to use OCTOs with ProMini plus Camstab and Camtrigger.
There is no distinction made between servos / motors in PWM output handling.
PWM channels are fairly distributed to both Compare Modules A / B.
PWM output is realized in the ISR (TIMER1_COMP? _vect) in a chained method.
In one IRQ call output PWMA_n-1 is set low and PWMA_n is set high. So we have only half of IRQ load as now realized.
We have a resolution of 0.5us in puls lenght.
The repetition rate is due to the process variable and depends on the number of channels in each compare unit and pulse duration.
For a QUADRO with Camstab we have 222Hz@1.5ms.
For the OCTOs with Camstab we have 133Hz@1.5ms.
The accuracy of the pulse length is the most significant parameter. Only these value will be evaluated by the ESC.
The repetition rate determines the dynamic behavior of the copter.

I think the ESC refresh rate is probably more important than the signal resolution.
Beside this, the pulse jitter seems to affect a lot the stability.
A true hardware pwm has no jitter at all, and I still don't see a software pwm that behaves better while in the air.
ronco and ziss_dm tested this fact in another thread.

PWM-MEGA:Output with four 16-bit timer1,3,4,5. PWM in pure hardware with PWMwaveform 14.
12 channels total, of which nine channels have 400Hz repetition rate, 3 channels have 32Hz repetition rate.

You can see visually the worse effect of a 32Hz servo refresh rate instead of a 50Hz one.

All PWMs are running in background. No Timer IRQs neccesary. Update is realized with double bufferd compare-registers.
We can write to this registers at any time.

I didn't dig a lot in the pwm stuff, but what about the arduino default config ?
Is there an advantage of using another pwm setting except the timing ?

API-timer/delay substitute:
API micros() ----> micros16() or micros32()
API millis() ----> millis32
API delay(uint16_t ms) ----> delay0(uint16_t ms)
API delayMicroseconds(uint32_t us) ----> delayMicroseconds0(uint32_t us)

You're right, some optimization can probably done on the original arduino functions which are definitively not optimized at all.

@Alex:
in zip file you find the new mega OCTO configuration (motor 6,7 mod)
and you have the configurations for the OCTO ProMini.
In the excel sheet you see the configuration for Pauls ARDDUINO mega.
My software mod is based on version MultiWii_dev_20120121.
Please push the PWM4-files to the code reviews page.

I will put this file in the trunk contribution repository if you want.
But I'm still in favor with ronco code as it uses all the hardware pwm capabilities, and only software ones when needed.

Post Reply