If you enjoy our forum, why not join us? :) Login removes all the ads too! Click here to register in a few simple steps

Login to remove this ad | Register Here
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inverting PWM Signal BlHeli_S
#1
I am using a brushed flight controller and I am converting it to brushless operation. 
The pwm motor outputs are reversed when the board is converted, so if I reverse the PWM signal on cleanflght, It will be reversed again by the board and come out the right way?

Am I correct in the above?

I tried the command TIM_OCPolarity_High and it was invalid. What should I do?
#2
First of all, let us know what firmware target you're using for your board, and the exact board name or a link.
Your idea is generally right, but i think you could undo the inversion in hardware by removing the inverters.
Reply
#3
What is the command for TIM_OCPolarity_High in cleanflight?

ok here is the link.
http://www.banggood.com/Eachine-32bits-F...ds=myorder
Reply
Login to remove this ad | Register Here
#4
Ok, watched the video, now I understand why the signal is inverted. Tell me your target name and I'll look into CF code to determine what needs to be modified in order to get active-low PWM on motor outputs.
TIM_OCPolarity_High is not a command, it's a value for initialization of PWM timer in flight controller source code, to change it you need to modify code and recompile it.
Reply
#5
What is a target name and how can I find what mine is?
Reply
#6
Have you flashed your FC to the latest CleanFlight/BetaFlight? Then you should know the target name, e.g. SPRACINGF3EVO.
P.S. Your's indeed is SPRACINGF3EVO. You'll have to modify CleanFlight code and flash your FC to this modified version.
Reply
Login to remove this ad | Register Here
#7
How do I do that?

I have just about Zero coding experience.
Reply
#8
It seems like you need to study lots of basics before moving onto this task. I could tell you what to modify in CleanFlight/BetaFlight code, but I'm afraid it won't make much sense for you.
In case of latest BF, as far as I understand, it should be enough to change the following lines in the SPRACINGF3EVO/target.c file from
Code:
DEF_TIM(TIM2,  CH1,  PA0,  TIM_USE_MOTOR, 1 ),  // PWM1 [TIM2_CH1 (D1_CH5)]
DEF_TIM(TIM2,  CH2,  PA1,  TIM_USE_MOTOR, 1 ),  // PWM2 [TIM2_CH2 (D1_CH7)] [TIM15_CH1N (D1_CH5)]
DEF_TIM(TIM2,  CH3,  PA2,  TIM_USE_MOTOR, 1 ),  // PWM3 [TIM2_CH3 (D1_CH1)] [TIM15_CH1  (D1_CH5)]
DEF_TIM(TIM15, CH2,  PA3,  TIM_USE_MOTOR, 1 ),  // PWM4 [TIM2_CH4 (D1_CH7)]
to
Code:
DEF_TIM(TIM2,  CH1,  PA0,  TIM_USE_MOTOR, 1 | TIMER_OUTPUT_INVERTED ),  // PWM1 [TIM2_CH1 (D1_CH5)]
DEF_TIM(TIM2,  CH2,  PA1,  TIM_USE_MOTOR, 1 | TIMER_OUTPUT_INVERTED ),  // PWM2 [TIM2_CH2 (D1_CH7)] [TIM15_CH1N (D1_CH5)]
DEF_TIM(TIM2,  CH3,  PA2,  TIM_USE_MOTOR, 1 | TIMER_OUTPUT_INVERTED ),  // PWM3 [TIM2_CH3 (D1_CH1)] [TIM15_CH1  (D1_CH5)]
DEF_TIM(TIM15, CH2,  PA3,  TIM_USE_MOTOR, 1 | TIMER_OUTPUT_INVERTED ),  // PWM4 [TIM2_CH4 (D1_CH7)]

It should give you active-low PWM signal on motors 1-4.
Reply
#9
So how do I change that in the code? Do I find the hex file and then just delete the first ones and add the bottom ones?

Where do I find the hex file?
Reply
Login to remove this ad | Register Here
#10
HEX is already compiled, you need to edit the C source code.
This particular file is here: https://github.com/betaflight/betaflight...O/target.c
Reply
#11
So I download the file, then find the part of the code that looks like this:
Code:
DEF_TIM(TIM2, CH1, PA0, TIM_USE_MOTOR, 1 ), // PWM1 [TIM2_CH1 (D1_CH5)]
DEF_TIM(TIM2, CH2, PA1, TIM_USE_MOTOR, 1 ), // PWM2 [TIM2_CH2 (D1_CH7)] [TIM15_CH1N (D1_CH5)]
DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 1 ), // PWM3 [TIM2_CH3 (D1_CH1)] [TIM15_CH1 (D1_CH5)]
DEF_TIM(TIM15, CH2, PA3, TIM_USE_MOTOR, 1 ), // PWM4 [TIM2_CH4 (D1_CH7)]

and replace it to look like this:

DEF_TIM(TIM2, CH1, PA0, TIM_USE_MOTOR, 1 | TIMER_OUTPUT_INVERTED ), // PWM1 [TIM2_CH1 (D1_CH5)]
DEF_TIM(TIM2, CH2, PA1, TIM_USE_MOTOR, 1 | TIMER_OUTPUT_INVERTED ), // PWM2 [TIM2_CH2 (D1_CH7)] [TIM15_CH1N (D1_CH5)]
DEF_TIM(TIM2, CH3, PA2, TIM_USE_MOTOR, 1 | TIMER_OUTPUT_INVERTED ), // PWM3 [TIM2_CH3 (D1_CH1)] [TIM15_CH1 (D1_CH5)]
DEF_TIM(TIM15, CH2, PA3, TIM_USE_MOTOR, 1 | TIMER_OUTPUT_INVERTED ), // PWM4 [TIM2_CH4 (D1_CH7)]


Am I right?
Reply
#12
You need to download the whole BetaFlight source code, find this file, modify it, compile the whole source code for your SPRACINGF3EVO target and flash your FC with the resulting file.
Just get 4 transistors and build 4 signal inverters like suggested in this article:
https://quadmeup.com/simplest-hardware-i...ontroller/
Reply
Login to remove this ad | Register Here
#13
Will they work?
Reply
#14
That's what they are supposed to do, why wouldn't they?
Reply
#15
I know this is asking a LOT, but I was wondering, if by any chance you had the time, could do the coding for me as I have a lot to learn before I can start doing this kind of thing by myself?
Reply
Login to remove this ad | Register Here