Page 1 of 1
RSSI PWM Input - solution needed
Posted: Sun Jun 02, 2013 12:57 pm
by nhadrian
Hi All,
I have an FRSKY futaba compatible receiver which has a PWM RSSI output.
I tried to add PWM RSSI reading:
in config.h added:
Code: Select all
#define RX_PWM_RSSI
#define PWM_RSSI_PIN 46
in def.h added:
Code: Select all
#define PWM_RSSI_PINMODE pinMode(PWM_RSSI_PIN, INPUT);
in void setup() added:
in Multiwii.ino added:
Code: Select all
void PWM_RSSI_Read() {
static uint8_t ind = 0;
static uint16_t rvec[RSSI_SMOOTH], rsum;
uint16_t r = pulseIn(PWM_RSSI_PIN, HIGH) >> 2;
#if RSSI_SMOOTH == 1
analog.rssi = r;
#else
rsum += r;
rsum -= rvec[ind];
rvec[ind++] = r;
ind %= RSSI_SMOOTH;
r = rsum / RSSI_SMOOTH;
analog.rssi = r;
#endif
}
in Multiwii.ino taskOrder added:
Code: Select all
case 5:
taskOrder++;
#if defined(RX_PWM_RSSI)
PWM_RSSI_Read();
#endif
break;
Of course this line must be modified from this:
to this:
I'm sure this is not the most elegant way and also maybe NOT MATCH the Multiwii coding rules, but I'm not familiar with port handling.
Could someone help making PWM RSSI reading compatible with Multiwii coding?
BR
Adrian
Re: RSSI PWM Input - solution needed
Posted: Sun Jun 02, 2013 6:17 pm
by Alexinparis
What is the problem with the existing rssi code in _shared ?
Re: RSSI PWM Input - solution needed
Posted: Sun Jun 02, 2013 8:33 pm
by nhadrian
Alexinparis wrote:What is the problem with the existing rssi code in _shared ?
For me it was unusable without an R-C filter (100nF + 10kOhm) applied. (the value was far too glitchy when measured by analog input)
With R-C filter I still had to apply 32 for moving average...
But instead of applying R-C filter to average the PWM signal phisically it would better to measure the signal length since it is a PWM input.
With the modified code part I apply only 16 for moving average and the RSSI value is rock solid!
Unfortunatelly pulseIn is slow mneasuring method. That's why it would be better to have something faster, like RC channel handling for example.
BR
Adrian
ps.: this problem only occures when the RSSI signal is PWM and analog reading is not working very well.
Re: RSSI PWM Input - solution needed
Posted: Thu Jun 06, 2013 7:58 am
by dramida
Adrian, your filter has 160Hz cut off frequency, and that won't filter 50 Hz pwm or even the third armonic so the signal passes as a square wave:)
Abut RC filter, i use 4.7uF smd capacitor with 100K smd rezistor. It works perfect for FRsky RSSI. It has about 3 second time constant or 0.34 Hz cutoff . more details here
http://www.ekswai.com/en_lowpass.htm
Re: RSSI PWM Input - solution needed
Posted: Thu Jun 06, 2013 1:07 pm
by kataventos
Hi,
viewtopic.php?f=8&t=2918&start=310#p33006The one I made for myself works just fine and is tiny.
Note: It does not have the R2 1K as in draw. This is to use on Minim OSD when soldering on ATmel pin, this way the capacitor will not discharge all at once.Also the picture is inverted to the draw.



-KV
Re: RSSI PWM Input - solution needed
Posted: Fri Jun 07, 2013 4:44 am
by nhadrian
Thanks for all your reply.
But still, why make a physical filter instead of reading the PWM signal itself with the controller?
I think that would be much easier. BTW, my solution works, the only problem is that pulsein takes time to "run".
But we already have PWM reading for RC signals, so I think that would be quite easy to implement the RSSI reading too... the only problem for me that I don't have time enoughn to understand that code part...
BR
Adrian
Re: RSSI PWM Input - solution needed
Posted: Fri Jun 07, 2013 11:44 pm
by Mis
If You want measure pulse time without waste time, You must use interrupts like PCINT and micros variable or any other timer value. You must write interrupt handler function, and inside "setup" function you must configure and enable PCINT interrupt. The interrupt handler must detect input high/low state, measure high and low time (simply micros from last interrupt). The calculation can be done in main loop, for shorter interrupt time. Interrupt should only measure high and low pulse time. That's all.

Re: RSSI PWM Input - solution needed
Posted: Sat Jun 08, 2013 5:38 am
by nhadrian
Yes, I'm talking about something like this.
Please correct me, but if I'm right, this is already done in RC channel reading.
If yes, one other input should be defined and that's all. Can anybody help doing this?
BR
Adrian
Re: RSSI PWM Input - solution needed
Posted: Sat Jun 08, 2013 7:46 pm
by Mis
RC reading is little more complicated, but work with PCINT interrupts in similar way.
About help... This is easy with one configuration, like Mega2560 board with standard RC. But we have three different hardware versions (328, 32U4, 2560) and two receiver standards (normal and PPM-SUM) that use PCINT (other receivers not use PCINT's, and not collide with it). This number of combinations a headache, because PCINT interrupts share two or three interrupt vectors, and we must detect the interrupt source inside interrupt handler. Lot of checks, work, and tests. Interrups are delicate matter.
My conclusion. Forgot it and use RC filter, and analog input

Re: RSSI PWM Input - solution needed
Posted: Sun Jun 09, 2013 2:19 pm
by nhadrian
Mis wrote:RC reading is little more complicated, but work with PCINT interrupts in similar way.
About help... This is easy with one configuration, like Mega2560 board with standard RC. But we have three different hardware versions (328, 32U4, 2560) and two receiver standards (normal and PPM-SUM) that use PCINT (other receivers not use PCINT's, and not collide with it). This number of combinations a headache, because PCINT interrupts share two or three interrupt vectors, and we must detect the interrupt source inside interrupt handler. Lot of checks, work, and tests. Interrups are delicate matter.
My conclusion. Forgot it and use RC filter, and analog input

Hi,
yes you are right.
The only thing I don't understand, why is it such a big problem?
The RX inputs are "readed" on the same way aren't? And the handlings are already written to any used boards.
The only thing should be done is to extend the RX inputs with one more channel, called RSSI.
BTW, forget my wish, I'll use RC filter....
BR
Adrian
Re: RSSI PWM Input - solution needed
Posted: Mon Jun 10, 2013 2:11 am
by kataventos
Hi,
After seeing Mis last post I looked to the code for some time trying to see if I could help on that ( it would be nice...)
And... yep

the RCFilter works just fine and it can be a "tiny" part with almost no significance
Probably no worthy the work around that.
-KV
Re: RSSI PWM Input - solution needed
Posted: Thu Dec 05, 2013 9:04 am
by haydent
Mis wrote:If You want measure pulse time without waste time, You must use interrupts like PCINT and micros variable or any other timer value. You must write interrupt handler function, and inside "setup" function you must configure and enable PCINT interrupt. The interrupt handler must detect input high/low state, measure high and low time (simply micros from last interrupt). The calculation can be done in main loop, for shorter interrupt time. Interrupt should only measure high and low pulse time. That's all.

im going to have a crack at this for the mega
Re: RSSI PWM Input - solution needed
Posted: Fri Dec 06, 2013 7:46 am
by haydent
ok so reading in another pwm via for example an aux channel would be easy, as all the interrupt and timing code is already there for the recievers servo signals, even if you had to make some small changel for a pulse rate / duty cycle 'midly' outside the normal 1000-2000 microsecond servo signals
but then i hit this road block:ive found a few mentions of the frequency it puts out (110 kHz or 9.8 microsecond cycle) now split that 9.8 mics into 100 increments and you need a pretty fine resolution reader and fast processor, likely making the mega 2560 not up to the task, as i believe the best it 'may' be able to do is 1 mic resolution though possibly as 'poor' as 4 mics
to put this in perspective a servo signal is 1000-2000 mics duty with a 20000mic gap
why the heck frsky would choose such a fast rate seems silly to me...
Some FrSky receivers (D4R-II, D8R-XP, ...) provide RSSI as a PWM signal. The issue is that the frequency of the signal is way to high to be decoded by the ATmeg328 (110 kHz).
http://code.google.com/p/minoposd/wiki/AnalogRSSIstill researching though
Re: RSSI PWM Input - solution needed
Posted: Fri Dec 06, 2013 7:54 am
by haydent
oh and nhadrian you didnt have a chance with the pulseIn() function (disregarding blocking) as it turns out it only has a resolution down to 10 microseconds i read here:
http://arduino.cc/en/Reference/pulseIn
Re: RSSI PWM Input - solution needed
Posted: Tue Dec 31, 2013 1:28 am
by haydent
update on this, x8r reciever puts out a pwm rssi signal that would be ok to read, not as fast as others mentioned in this thread.