Filtering PWM

Flash735

New Member
Hi All,

I've searched the the forum and manuals. There are many pwm discussions however I am unable to find an answer.

On an rc receiver driving a brushed 11v motor; the goal is to replace the brushed motor with a brushless one.

I'm thinking, I could use picaxe to sense or filter the pwm from the positive and negative 11v motor contacts. Then convert those readings to the required 1 - 2 msec needed to run the ESC to brushless motor.

I have been playing around, experimenting, and becoming familiar with the 08m2. Can it be done with this chip?
 

srnet

Senior Member
What RC receiver ?

Does it not already put out 1-2ms pulses to drive the controller for the brushed motor ?
 

g6ejd

Senior Member
What is the frame rate of the 10uS to 950uS pulses, assume it's within the standard 50-60 hz framerate and if so, just pulse stretch the pulses, then when you get a 10uS pulse stretch it to 1mS and 950uS to 2mS, if the framerate is the same, all you need to is respond to a rising or falling leading edge of the pulse working out the new pulse width as required.

Work out a graph to do the conversions as this is an odd slope, along the lines of 10uS is 1mS and 0.95ms = 2mS then code this for the interrim positions choosing whatever resolution of interrim steps you need as it's a none exact fit.
 

Flash735

New Member
What is the frame rate of the 10uS to 950uS pulses, assume it's within the standard 50-60 hz framerate and if so, just pulse stretch the pulses, then when you get a 10uS pulse stretch it to 1mS and 950uS to 2mS, if the framerate is the same, all you need to is respond to a rising or falling leading edge of the pulse working out the new pulse width as required.

Work out a graph to do the conversions as this is an odd slope, along the lines of 10uS is 1mS and 0.95ms = 2mS then code this for the interrim positions choosing whatever resolution of interrim steps you need as it's a none exact fit.
g6ejd, framerate is 50hz. Thanks for your idea. I'll work at it and see if I can make it work.
 

srnet

Senior Member
If the pulse in is 10us to 950us, this gives a pulsin count of 1 to 95.

So if you just add 100 to the pulsin count value and use it for the servopos command, you would have a servopos value of 101 - 195, which would be the correct pulse for controlling the ESC
 

Goeytex

Senior Member
This would work if servo / servopos did not conflict with pulsin
Code:
#picaxe 08m2
#no_data
setfreq m4

pulsin c.3, 1, w0
w1 = w0 * 100/94 + 99    [COLOR=#008000] ' scale so that 1 to 95 =  100 to 200[/COLOR]
[COLOR=#008000]Now use w1 for servopos[/COLOR]
However, aren't you trying to use PWM out at 61 hz to get around the pulsin conflicts? If so then the code below
shows how to do the scaling.
Code:
#PICAXE 08M2
#NO_DATA
SETFREQ M4

pwmout pwmdiv64, 2, 250, 120

do
  for w0 = 1 to 95
    w1 = w0 * 60 / 94 + 60
    pwmduty 2, w1
    pause 200
  next
loop
The problem with the above is that there are only 60 discrete values of PWM duty that correlate
with 1ms to 2ms pulse width. In other words poor resolution.

You may be better off using Pulsout instead of pwm. But haven't I already showed you how to do that in another thread ?. The below simply converts a pulsin of 10 to 950us with a "frame" of 20ms to pulsout of 1ms to 2ms with a frame of 20ms and will give better resolution than using PWM.
Note the higher frequency to get better resolution.

Code:
#PICAXE 08M2
#NO_DATA
[COLOR=#ff0000]SETFREQ M16[/COLOR]

do
  pulsin c.3, 1,w0     [COLOR=#008000]'10us to 950us from receiver[/COLOR]
  w1 = w0 * 50/47 + 376   [COLOR=#008000]' convert to 1ms to 2ms[/COLOR]
  pulsout c.2, w1    
loop
 
Last edited:

Flash735

New Member
This would work if servo / servopos did not conflict with pulsin
Code:
#picaxe 08m2
#no_data
setfreq m4

pulsin c.3, 1, w0
w1 = w0 * 100/94 + 99    [COLOR=#008000] ' scale so that 1 to 95 =  100 to 200[/COLOR]
[COLOR=#008000]Now use w1 for servopos[/COLOR]
However, aren't you trying to use PWM out at 61 hz to get around the pulsin conflicts? If so then the code below
shows how to do the scaling.
Code:
#PICAXE 08M2
#NO_DATA
SETFREQ M4

pwmout pwmdiv64, 2, 250, 120

do
  for w0 = 1 to 95
    w1 = w0 * 60 / 94 + 60
    pwmduty 2, w1
    pause 200
  next
loop
The problem with the above is that there are only 60 discrete values of PWM duty that correlate
with 1ms to 2ms pulse width. In other words poor resolution.

You may be better off using Pulsout instead of pwm. But haven't I already showed you how to do that in another thread ?. The below simply converts a pulsin of 10 to 950us with a "frame" of 20ms to pulsout of 1ms to 2ms with a frame of 20ms and will give better resolution than using PWM.
Note the higher frequency to get better resolution.

Code:
#PICAXE 08M2
#NO_DATA
[COLOR=#ff0000]SETFREQ M16[/COLOR]

do
  pulsin c.3, 1,w0     [COLOR=#008000]'10us to 950us from receiver[/COLOR]
  w1 = w0 * 50/47 + 376   [COLOR=#008000]' convert to 1ms to 2ms[/COLOR]
  pulsout c.2, w1    
loop

Thanks everyone for all the ideas; Goeytex, yes you did help me figure out the pulsout scaling in our other thread and it works very well up to 95% of upper throttle position on the transmitter. Lower position of throttle has similar issue however since the aircraft is already on the ground the threat of crashing is neglectable.

The equation provide output (w1) of 940usec to 2.02msec. When throttle sits below 940usec (watching scope) the scope trigger flashes red as pulse drops in and out. When throttle moves above 940 usec up to 2.00msec, normal pulses. Frequency at this normal period is 490hz at the minimum point through 245 at the max before another lost of scope triggered at 2.02msec. Pulse Cnt 10 minimum to 7 at max throttle before loss of scope trigger at 2.02 msec. When throttle moves to 2.02 pulse drops to less 940usec (about 936-940usec) with loss of scope trigger. This is about at 95% high throttle. Another 5% movement at high speed flight would cause a model crash. Working Duty Cycle range: 46-49%. (Higher or Lower drops out) I have tried manipulating the equation variables, ranges, and scale without success to remove the high point loss of pulsing.


Therefore, another approach I'm thinking when I started this thread is to try is to pick up the processed signals from the brushed motor (380 type 11v). Recover the PWM signals from that end point and derive the 1 to 2msec pulses with picaxe. So in this case I'm attempting to derive the 1-2 msec from the pulses into the motor instead of the output pulses from the receiver. This may make a difference in some way why the loss of trigger. In the case of this model the brushed main and tail motors are powered an by 11v battery through what I believe maybe some type of H-Bridge with the control wires carrying the 10usec-950usec from the receiver to the H-Bridge. I have to do a lot more reading on H-Bridges. I hope all this didn't confuse anyone. Thanks again....a lot more reading for me to do on this one.
 

Goeytex

Senior Member
The equation provide output (w1) of 940usec to 2.02msec. When throttle sits below 940usec (watching scope) the scope trigger flashes red as pulse drops in and out. When throttle moves above 940 usec up to 2.00msec, normal pulses. Frequency at this normal period is 490hz at the minimum point through 245 at the max before another lost of scope triggered at 2.02msec. Pulse Cnt 10 minimum to 7 at max throttle before loss of scope trigger at 2.02 msec. When throttle moves to 2.02 pulse drops to less 940usec (about 936-940usec) with loss of scope trigger. This is about at 95% high throttle. Another 5% movement at high speed flight would cause a model crash. Working Duty Cycle range: 46-49%. (Higher or Lower drops out) I have tried manipulating the equation variables, ranges, and scale without success to remove the high point loss of pulsing.
With all respect, this is very confusing and not very well explained at all.

What frequency are you referring to? It was my understanding that the receiver output of 10 - 950us was with a frequency of 50hz. Now you mention a frequency of 490 hz ? Where does this come from ? A frequency of 490 hz has a time period of nearly 2ms so there is no room for any off time if a 2ms pulse is needed. In other words you cannnot frame a 2ms pulse in a 2ms window. Please explain the 490 hz and where it comes from ....
 

Flash735

New Member
With all respect, this is very confusing and not very well explained at all.

What frequency are you referring to? It was my understanding that the receiver output of 10 - 950us was with a frequency of 50hz. Now you mention a frequency of 490 hz ? Where does this come from ? A frequency of 490 hz has a time period of nearly 2ms so there is no room for any off time if a 2ms pulse is needed. In other words you cannnot frame a 2ms pulse in a 2ms window. Please explain the 490 hz and where it comes from ....



Goeytex, sorry for the confusion, I previously went ahead and post all the info that I was gathering, which probably caused even more confusion. My head was spinning from all the different attempts, numbers, and equations at the time. The 50hz actually was incorrect and came from another approach to get it working when I was using the wizard and could only go down to 61hz.

The actual measured receiver output is 10-950usec at 980hz.

All the other data given and the related 490hz is being measured from port c.2 running through picaxe using the equation in your post:



SETFREQ M16

do
pulsin c.3, 1,w0 '10us to 950us from receiver
w1 = w0 * 50/47 + 376 ' convert to 1ms to 2ms
pulsout c.2, w1
loop



These are some frequency readings at different throttle positions:

Low throttle stick at 5% up position = freq 490hz with 940usec pulse width

midstick freq = 245 hz with pulse width 1.70ms ;

Stick at 95% = 245hz with pulse width 2.02ms ; Any higher stick position causes loss of pulse dropping to 936usec.


I have also tried a different transmitter. Same results. There maybe a signalling requirement between the 2.4Ghz radio transmitter and the receiver to allow for full utilization of the throttle range that I am not aware of. More reading to go...
 

Goeytex

Senior Member
The actual measured receiver output is 10-950usec at 980hz.
THAT CHANGES EVERYTHING ! .... and guarantees that the code I supplied will not work !

Now that I have the correct data maybe I can fix the code
 

g6ejd

Senior Member
@flash735 I think your measurements are showing a second harmonic at the 5% stick position, it's actually still 245Hz (2 x 245 = 490!) like the 50% and 95% positions. Now the pulse widths are what should be expected, not the original 10-950uS. The results your getting are exactly what you should get.

Now your problem is to convert 1.0mS to 2.0mS pulses at 245Hz to a 0-100% PWM output.
 

Goeytex

Senior Member
Seems to me what is happening is the code I posted was based upon the assumption that the pulsin was at 50hz instead of 980hz. Therefore the loop in the code, having no delay, will jump around depending upon the width of the input pulse.

Exacerbating the problem is that at 980 hz and a pulse width of 950us (Due to Picaxe overhead) pulses will be missed at random intervals since there is not enough off time. (980 cps = a period of 1020us. 1020us - 950us puls width = 70 us between pulses. Not enough for a Picaxe running at 32mhz.

My guess also is that the 980hz is supposed to be 1Khz, but I am not sure how it was measured. ( 980hz is a rather odd frequency for a manufacturer to use? )

At this point I am not even sure what Flash is trying to accomplish. Seems like a moving target.
 
Top