Creating an RPM and Temp Sensor

Development & General Chat for the superb openxvario project.

Moderator: rainer

Thorvald
Posts: 44
Joined: Thu Aug 08, 2013 12:06 pm
Country: -

Creating an RPM and Temp Sensor

Post by Thorvald »

Hi guys, thanks to Mike for pointing this project out, I've ordered a pair of arduino's to work on. What I'm looking to create is the following:

- RPM sensor input that works the same as the sensor hub (for my nitro heli)
- temp sensor input that works the same as the sensor hub (again for nitro engine)

Frsky has a new S.Port rpm sensor but it only supports electric brushless motors apparently (bizarre).

Before I re-invent the wheel, has anyone does this and did it require anything extra (filter etc) or were you able to use the ADC built in?

Thanks
Tim

Thorvald
Posts: 44
Joined: Thu Aug 08, 2013 12:06 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by Thorvald »

Ah I see there is a branch called oXs, that has already been setup for RPM, Temp, etc. Just need to figure out the config file.

I don't understand the 3.3 and 3.4 section about DEFAULTFIELD, do I need to change it from 0x00 to 0x16 (or 0x10 for hex value of dec 16?) for RPM?

Also for the Data to Send, do I comment out the existing and just add:

#define SETUP_DATA_TO_SEND \
DEFAULTFIELD , RPM , 1 , 1 , 0

Thanks
Tim
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by mstrens »

Thorvald wrote:Ah I see there is a branch called oXs, that has already been setup for RPM, Temp, etc. Just need to figure out the config file.

I don't understand the 3.3 and 3.4 section about DEFAULTFIELD, do I need to change it from 0x00 to 0x16 (or 0x10 for hex value of dec 16?) for RPM?

Also for the Data to Send, do I comment out the existing and just add:

#define SETUP_DATA_TO_SEND \
DEFAULTFIELD , RPM , 1 , 1 , 0

Thanks
Tim
OXS is the new name for openXvario.
It has been enhanced in order to support more sensors on both Frsky protocols (Hub and SPORT).
It should normally measure RPM if you add a sensor that return a pulse (0 to 5 volt and back to 0 volt ) at each RPM. This pulse can be generated by a Hall effect sensor (very cheap on ebay).

OXS can also measure voltages. There are many temperature sensors (in different ranges) that return a voltage based on a temperature. Connecting this analog signal to an analog pin allows you to measure the temperature.
For each voltage you measure you can apply calibration parameters that allows you to get the expected values on the display as long as your sensor is linear in the range you want to measure.

OXS allows you to select which measurement is transmitted and in which telemetry field.
For some measurements, Frsky has defined telemetry field. In such a case you can define the set up using "DEFAULTFIELD". That is the case for RPM.
For voltage there is not just one telemetry field to apply because the measured voltage can be e.g. a battery voltage or a temperature sensor voltage. So in this case you can't just specify the telemetry using DEFAULTFIELD but you have to select the telemetry field you want from one list (there is a list for D serie Rx and one for X serie)

If you want to send RPM and TEMP1 for a X receiver, if you connect your temperature sensor on the analog pin you set up for VOLT1, you can use the following set up
#define SETUP_DATA_TO_SEND \
DEFAULTFIELD , RPM , 1 , 1 , 0 , \
T1_FIRST_ID , VOLT1, RPM , 1 , 1 , 0
which is in fact the same as
#define SETUP_DATA_TO_SEND DEFAULTFIELD , RPM , 1 , 1 , 0 , T1_FIRST_ID , VOLT1, RPM , 1 , 1 , 0
because ending a line by "\" is just a way to split an instruction on several lines.

There may be only one line #define SETUP_DATA_TO_SEND that remains uncommented.

Do not forget to fill in the calibration parameters for
#define offset_1 0
#define mVoltPerStep_1 1
As explained in the config file, you can just start with 0 (offset) and 1 (mVoltPerStep) and look at what you get on the Tx display. Change the parameters in order to get the expected values on the display.



I hope it is clear.
User avatar
jhsa
Posts: 19480
Joined: Tue Dec 27, 2011 5:13 pm
Country: Germany

Re: Creating an RPM and Temp Sensor

Post by jhsa »

I got some hall effect sensors from ebay and I need to find time to try them :(
I also have a tmp37 temperature sensor that measures only positive values. Difficult to find though...

João
My er9x/Ersky9x/eepskye Video Tutorials
https://www.youtube.com/playlist?list=PL5uJhoD7sAKidZmkhMpYpp_qcuIqJXhb9

Donate to Er9x/Ersky9x:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YHX43JR3J7XGW
Thorvald
Posts: 44
Joined: Thu Aug 08, 2013 12:06 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by Thorvald »

Thanks guys for all the info and help!

So for the the latest source code I see online for oxs, I only have to uncomment the rpm sensor line to get support for it then? Or is there a newer source elsewhere? (github etc).

And the defaultfield value I leave alone then at 0x00? Just use it for the send string.

---

Thankfully nearly all RPM sensors for nitro engines are Hall effect, I'm using a spektrum crankcase sensor myself:

http://www.horizonhobby.com/products/SPMA9569

Image

---

For temp sensors, most are NTC resistance based sensors so I'll have to make up a small circuit to convert them to work with oxs. Should be simple enough.

User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Creating an RPM and Temp Sensor

Post by MikeB »

If you have a table of values for the resistance of the NTC sensors against temperature, it is possible to use a single resistor with the NTC sensor and work out the temperature from the resulting voltage.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by mstrens »

Thorvald wrote:Thanks guys for all the info and help!

So for the the latest source code I see online for oxs, I only have to uncomment the rpm sensor line to get support for it then? Or is there a newer source elsewhere? (github etc).

And the defaultfield value I leave alone then at 0x00? Just use it for the send string.

---

Thankfully nearly all RPM sensors for nitro engines are Hall effect, I'm using a spektrum crankcase sensor myself:

http://www.horizonhobby.com/products/SPMA9569

Image

---

For temp sensors, most are NTC resistance based sensors so I'll have to make up a small circuit to convert them to work with oxs. Should be simple enough.
OpenXsensor is only on google.
The latest version is at
https://code.google.com/p/openxvario/so ... penxsensor

You do not have to change the value 0x00 for DEFAULTFIELD.
It is used internally to find the right telemetry field ID.
Yes Just use it for the send string.

Please note that I never tested myself the RPM sensor.
I do not know in which unit it has to be formatted.
Please test it and if you do not get a logical value on TX display, then you perhaps have to apply a scaling parameter (e.g. setting the "divider" to 60 instead of 1 in the set up of the telemetry fields.
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Creating an RPM and Temp Sensor

Post by MikeB »

It was originally set up for an optical sensor and the Tx firmware has an entry for the "number of blades". This is really just how many pulses per revolution. The value sent is the number of pulses seen per second.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
Thorvald
Posts: 44
Joined: Thu Aug 08, 2013 12:06 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by Thorvald »

Thanks guys, parts finally arrived so I put together a quick test unit and changed the config to only give me RPM. Appears to work while simply manually pulling pin 8 to Vcc with a jumper multiple times.

However it does not properly zero the RPM value, when first powered up the RPM shows 60 (blades=1 on Taranis) and after pulsing pin 8 and then leaving open, the RPM value will sit at some seemingly random value instead of dropping to zero.

With the normal hub based RPM sensor, it zeroes normally as soon as the signal is gone.
Thorvald
Posts: 44
Joined: Thu Aug 08, 2013 12:06 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by Thorvald »

Also a little confused on:

>Do not forget to fill in the calibration parameters for
>#define offset_1 0
>#define mVoltPerStep_1 1
>As explained in the config file, you can just start with 0 (offset) and 1 (mVoltPerStep) and look at what you get on the Tx display. Change the parameters in order to get the expected values on the display.

They config file indicates these are only for voltages 1 to 6 but we are reading on pin 8. Does the RPM value pull the calibration parameters from voltage 1?

Thanks
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by mstrens »

Thorvald wrote:Also a little confused on:

>Do not forget to fill in the calibration parameters for
>#define offset_1 0
>#define mVoltPerStep_1 1
>As explained in the config file, you can just start with 0 (offset) and 1 (mVoltPerStep) and look at what you get on the Tx display. Change the parameters in order to get the expected values on the display.

They config file indicates these are only for voltages 1 to 6 but we are reading on pin 8. Does the RPM value pull the calibration parameters from voltage 1?

Thanks
I think that there are some misunderstanding.
If you only want to measure RPM, you do not have to take care of the parameter for voltage and you put the value 8 on the 6 voltage lines (e.g. #define PIN_Voltage1 8).
In this case OXS will not read voltages and the lines with the calibration are just discarded.

Please not the there no relation at all between the value "8" for voltage (having the meaning " not used") and the fact that RPM sensor has to be connected to DIGTAL pin "8" on arduino.

On the other side, the title of this thread and some exchanged messages refered to measuring a temperature.
If you want to measure a temperature, then you need to ask OXS in fact to measure a voltage because the temperature sensor generates a voltage that has to be read by OXS and converted in degree.
It is only in this case that you have to specify an arduino ANALOG pin and the 2 calibration parameters that are associated to voltage.

I hope this clarify the question.
User avatar
MikeB
9x Developer
Posts: 17979
Joined: Tue Dec 27, 2011 1:24 pm
Country: -
Location: Poole, Dorset, UK

Re: Creating an RPM and Temp Sensor

Post by MikeB »

Try tying the RPM input pin to 0V and see what the RPM value displayed is then.

Mike.
erskyTx/er9x developer
The difficult we do immediately,
The impossible takes a little longer!
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by mstrens »

MikeB wrote:Try tying the RPM input pin to 0V and see what the RPM value displayed is then.

Mike.
@Mike
Is it not a good idea to connect the RPM input pin to a PPM signal on the Rx (just for testing)??
I presume, it should give a value.
Thorvald
Posts: 44
Joined: Thu Aug 08, 2013 12:06 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by Thorvald »

Hi Mike, with tied to ground it simply holds the last value displayed. I tried the "Reset Telemetry" feature but then it goes to 60 right away until the pull down to ground is removed. We may need to have a feature to calibrate the value that is read on pin 8 as simply tapping the pin with a finger causes enough of a change to register as a signal.

The initial value of 60 rings a bell for some reason, something I found in the telemetry code in OpenTx a while back, have to dig.

---

Thanks mstrens, I plan to use temp as well but just starting with RPM only for now (tackling one at a time).
Thorvald
Posts: 44
Joined: Thu Aug 08, 2013 12:06 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by Thorvald »

Now I remember, in radio/src/telemetry/frsky_d.cpp:

frskyData.hub.rpm *= (uint8_t)60/(g_model.frsky.blades+2);

60 / 1 = 60 (with blades = 1)

I did a quick test changing blades = 2 and sure enough, default value displayed is 30.
Thorvald
Posts: 44
Joined: Thu Aug 08, 2013 12:06 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by Thorvald »

Broke down and picked up a Function Generator (been meaning to get one for a while). With Blades equals 1 it reads correctly (though a little high) up to 9999 but returns to 0 once it goes above 10000. So some issue there with large numbers.

I'll next see about a method to calibrate the reading.

---

Update: When the function generator is turned off, the rpm value does return to zero.

Update2: I make a quick lua script to display the RPM raw and it also has the 9999 rpm value limitation, when rpm exceeds 9999 it gets set to 0 from then on until the value drops below 10000.

Update3: Used the 1hz step setting and the max appears to be 9975, after that it zeroes out. However its hard to tell, whatever method is used to measure the rpm signal is not stable as the reading jumps around a fair bit (not an interrupt I assume?).
Last edited by Thorvald on Wed Jul 30, 2014 2:41 am, edited 2 times in total.
Thorvald
Posts: 44
Joined: Thu Aug 08, 2013 12:06 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by Thorvald »

Also see that RPM is initially set to a value of 60 for some reason in openxsensor.ino

volatile uint16_t Rpm = 60 ;
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by mstrens »

Thorvald wrote:
Update3: Used the 1hz step setting and the max appears to be 9975, after that it zeroes out. However its hard to tell, whatever method is used to measure the rpm signal is not stable as the reading jumps around a fair bit (not an interrupt I assume?).
In file Aserial.cpp you find this code (perhaps it is not exactly the same code because I am currently working on a new version and I made some changes):
RpmCounter = 0 ;
difference = eventTime - lastEventTime ;
lastEventTime = eventTime ;
if ( difference > 400 )
{
RpmValue = 4000000 / difference ;
}
else
{
RpmValue = 0 ;
}
RpmSet = true ;
You see a test on difference > 400.
It is probably this test that force the value to become 0.
If you reduce the value 400 (e.g. using 100) you can increase the Rpm that will be returned by oxs.
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by mstrens »

Thorvald wrote: Update: When the function generator is turned off, the rpm value does return to zero.
I think there is a bug in a test.
In file openxsensor.ino, you have this code:

#ifdef MEASURE_RPM
if (millis() > ( lastRpmMillis + 200) ){ // allow transmission of RPM only once every 200 msec
if (RpmSet = true) {
RpmSet = false ;
} else {
Rpm = 0 ;
}
RpmAvailable = true ;
lastRpmMillis = millis() ;
}
#endif

The line with
if (RpmSet = true) {
should be
if (RpmSet == true) {

Please let me know if this solve the issue, so I can integrate it a new version on google.

Note : About initialisation of rpm on 60, you are right: it sould better be 0 but if other mistakes are fixed, it should not matter I think.
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by mstrens »

Thorvald wrote: Update3: ... whatever method is used to measure the rpm signal is not stable as the reading jumps around a fair bit (not an interrupt I assume?).
I think that the value returned by OXS is based on the enlapsed time between 4 pulses.
Perhaps we need measuring more pulses or (probably better) applying some smoothing function based on a time constant of about 1 sec.
I can try to do it in a new version.

@Mike,
I did not understand the code you made for OXS about the function micros(), millis().
I just assumed it works.

Still I ask myself if there will never be an issue when the timer and TotalMicros overrun in the code used for RPM
Please check and let me know.

Code: Select all

ISR( TIMER1_CAPT_vect, ISR_NOBLOCK )
{
	uint16_t elapsed ;
	uint32_t eventTime ;
	uint32_t difference ;

	if ( ++RpmCounter > 3 )
	{
		cli() ;
		uint16_t time = ICR1 ;	// Read timer 1
		sei() ;
		elapsed = time - lastTimerValue ;
  #if F_CPU == 20000000L   // 20MHz clock 
   #error Unsupported clock speed
  #elif F_CPU == 16000000L  // 16MHz clock                                                  
    		eventTime = TotalMicros + ( elapsed >> 4 ) ;
  #elif F_CPU == 8000000L   // 8MHz clock
  		eventTime = TotalMicros + ( elapsed >> 3 ) ;
    #else
    #error Unsupported clock speed
  #endif

		//eventTime = TotalMicros + ( elapsed >> 4 ) ;
		RpmCounter = 0 ;
		difference = eventTime - lastEventTime ;
		lastEventTime = eventTime ;
		if ( difference > 200 )
		{
			RpmValue = 4000000 / difference ;
		}
		else
		{
			RpmValue = 0 ;
		}
		RpmSet = true ;
	}
}
Thorvald
Posts: 44
Joined: Thu Aug 08, 2013 12:06 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by Thorvald »

mstrens wrote: The line with
if (RpmSet = true) {
should be
if (RpmSet == true) {

Please let me know if this solve the issue, so I can integrate it a new version on google.

Note : About initialisation of rpm on 60, you are right: it sould better be 0 but if other mistakes are fixed, it should not matter I think.
Good catch, that was always setting it to true, I made the change on mine.

I changed the time down from 400 to 100 and now it can read up to 40000 rpm which is better but would be good to get it right up to the maximum allowed (65535 I assume, Unsigned int). I tried lowering it to 50 but it would randomly not read the rpm at all. Will play more.

Powering up without a signal present now gives 0 rpm though any spike on pin 8 gives a reading around 60/62. We might need to add a little filtering/decoupling or a simple pull up?

---

As for the erratic reading, it always seems off by 100 or 200 rpm above 10000 and about 50 below 5000. I'll toss my scope on the function generator just to make sure the square wave is clean.

Thanks for all the help guys.

Cheers
Tim
FlyingHack
Posts: 4
Joined: Thu Sep 03, 2015 3:46 pm
Country: Norway

Re: Creating an RPM and Temp Sensor

Post by FlyingHack »

Hey there, I am reading the hall effect sensor of my DLE ignition for RPM via a optocoupler (which you would not need on a nitro), and that is working great.
I have only tested it on the ground and up to 8800 revs, but I could easily hook up my function generator and try to bump it to 65000rpm to see how the code behaves.
I am by no means a "professional" programmer or electrician for that matter, but one thing I may note about your ISR is that it may take too long to execute to catch all the interrupts to get full RPM.

I also added a current sensor and isolated voltage measurements of the ignition battery, so now I can get a warning after xx mAh or when at xx voltage, since it's a life battery it suddenly drops voltage faaast when empty.
On the RX side I will maybe add a current sensor also, in case of servo lockups I could get an alarm. And of course I have GPS for speed and in case of crash, barometer for altitude and some temperature sensors since it's so darn cheap when you DIY!

Lovin' my Taranis!
FlyingHack
Posts: 4
Joined: Thu Sep 03, 2015 3:46 pm
Country: Norway

Re: Creating an RPM and Temp Sensor

Post by FlyingHack »

My last post has not been approved yet, so I cannot edit but I am back with my findings.

In my code I use both interrupt 0 and 1, because I measure ignition battery voltage with a frequency up to 2.2kHz.
I had no problem measuring battery voltage and at the same time having an RPM of a little over 65k, then the variable overflowed I guess.
Not the best resolution at 65k though, it jumped around 120revs up and down. But the stability may be because of my cheap ass Chinese function generator ;)

You may have overcome your problems, but I will post my code here anyway in case anyone else struggles with the same.
I got inspiration for the interrupt code after looking at someone else's code(don't remember who's though), it had a couple of flaws that I fixed and now it is serving me well!

As you can see I calculate frequency every 500ms, multiply it by 2 to get Hz. I update the telemetry variables at the same time when the ISR is disabled, but that is not shown here,
telemetry.send() is by itself in the loop.

Code: Select all

  if (millis() - lastmillis >= 500){
    detachInterrupt(0);
    detachInterrupt(1);
    RpM = Revs*2 * 60;
#ifdef DEBUG
    Serial.print("RPM =\t");
    Serial.print(RpM); 
    Serial.print("\t Hz=\t");
    Serial.println(Revs); 
#endif
    Revs = 0; 

    int analogreading = 0;
    for(byte i=0; i < 10; i++)
    {
      analogreading += analogRead(0);
    }
    analogreading = analogreading/10;
    Voltage = (analogreading / 1023.0) * 5100; // Gets you mV
    Amps = ((Voltage - ACSoffset) / mVperAmp);

    voltage = (frequency*2*faktor)/1000.0;

#ifdef DEBUG
    Serial.println(frequency*2);
    Serial.println(voltage);
#endif

    frequency = 0;
    if(Amps < 0)
    {
      Amps = 0;
    }

    lastmillis = millis();
    attachInterrupt(0, voltage_isr, FALLING);
    attachInterrupt(1, rpm_isr, FALLING);
  }

void rpm_isr()
{
  Revs++;
}

void voltage_isr()
{
  frequency++;
}
FlyingHack
Posts: 4
Joined: Thu Sep 03, 2015 3:46 pm
Country: Norway

Re: Creating an RPM and Temp Sensor

Post by FlyingHack »

Change if (millis() - lastmillis >= 500){ to 1000 and remove the multiplication below to get 60rpm resolution. Increase sampling time for more resolution but slower response.
raleighcoter
Posts: 23
Joined: Mon Apr 18, 2016 10:40 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by raleighcoter »

Looking to do this on an arduino pro with hall sensor and standard rtd for temp. Did you or anyone ever get this working?
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by mstrens »

As far I know, it works.
If you get an issue, let me know and I can try to solve it.
Best is to try with the latest version of oXs (available in master branch on github)
raleighcoter
Posts: 23
Joined: Mon Apr 18, 2016 10:40 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by raleighcoter »

Any recommendation on the resistor to use in the required voltage divider? How do i map the resulting voltage to temperature? Is there some documentation i can read?
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by mstrens »

Which component do you plan to use to measure the temperature?
Do you know which voltage this temperature sensor will deliver?
Do you know if the voltage provided by the temperature sensor varies based on the voltage used to power up the temperaure sensor.

What is the source of power supply to Arduino pro mini? Is the voltage for arduino:
- always higher than 5.5 volt
- always stable (e.g. provided by a voltage regulator from a ESC)
- varying quite a lot (e.g. direct voltage provided by a 4.8 Volt NiMh battery.

The answer to those questions has an impact on using a setup in oXs in order to measure voltage based on Arduino Vcc or based on Arduino internal voltage reference (and on the resistors to use for a voltage divider)
raleighcoter
Posts: 23
Joined: Mon Apr 18, 2016 10:40 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by raleighcoter »

Using a life battery to power the arduino pro. Will use a 100k ntc rtd with a series resistor around 10k wired between regulated 3.3v and ground and measure voltage across the voltage divider. I'm interested in 100-300 F so i'll fit a linear curve in that range. Does that sound about right?
mstrens
Posts: 1435
Joined: Fri Dec 27, 2013 7:49 pm
Country: -

Re: Creating an RPM and Temp Sensor

Post by mstrens »

So I presume you will use a 8 MHz 3.3 volt arduino pro mini (and not a 16 Mhz 5 volt).
This should be ok for RPM and temperature.
oXs could then best be configured to measure voltage based on Arduino Vcc.
Do you have the exact reference of the 100k ntc or do you know (at least aproximately) the resistances of the NTC at 100 F and at 300 F.

Can you eventually use a 10 k ntc instead of a 100 k? This would probably be better for Arduino input.

Post Reply

Return to “OpenXVario - an open source vario supported by the open source firmwares!!”