Main Site Documentation

Measuring the width between pulses


#1

I’m playing around with a Hobby Zone receiver, trying to interpret the signals it is receiving to manually control the servos myself. Playing around with an oscilloscope I’ve found that it is encoding the signals received by raising 4 pulses repeatedly. If the left rudder is applied the 4th pulse will move slightly to the left, if the down elevator is applied the 3rd will move left (space between 2nd and it will change), etc. I attached a pic of what it looks like on the scope.

Below is the code I’m trying out but the numbers I get printed out don’t seem to have any pattern, unlike what I see on the oscilloscope. Any tips?

		
void inputHandle_OnInterrupt(uint data1, uint state, DateTime time)
{
            if (state == 0)
            {
                pulseCount++;
                ticks = time.Ticks;

                if (pulseCount >= 4)
                    pulseCount = 0;
          }
            else
            {
                if (pulseCount > 0)
                {
                    spaceSinceLast = (int)(time.Ticks - ticks);
                    Debug.Print(spaceSinceLast.ToString());
                }

                ticks = time.Ticks;
            }
}

Here are the numbers that get printed out before it starts failing due to allocation errors (I’m assuming because it can’t allocate memory fast enough comapred to how fast ticks come in). I’m ok with that because once I figure it out I won’t have the debug statements in there.

4220
24022
8764
4920
1158
1642
5579
1030
1834
2998
4999
36012
1387
8271
3620
5466
1049
9971
12681
17951
8744
5253
57433
13732
3645
9273
11618
9736
7834
4081
7231
1274
1481
2869
3841
46099
2121
8786
6526
4242
2966
30361
1314
1089
9421
4678
3658
46449
6498
1718
5421
6917
57154
1000
1967
1733
12434
25120
11951
2739
1030
7065
1038
9602
55109
1692
75349
3492
2505
8112
1434
1030
42903
5820
4709
6843
2043
16412
21835
10856
1617
1957
1205
1841
6041
7891
2699
31688
15898
2148
1693
1485
1030
5550
6517
46636
1545
971
1029
11100
4911
39333
4419
8222
1281
1635
1029
8459
33182
2709
971
3773
15721
13154
13263
3831
2971
12943
3245
3008
45145
1889
1261
1744
1914
2556
1446
8019
5997
1029
13348
1849
1015
2599
6798
15016
12691
14992
2228
8186
8197
27487
4938
1712
6106
3595
1733
9111
15844
30231
1015
1038
1029
973
6295
21884
3788
1000
3332
5226
Failed allocation for 17 blocks, 204 bytes

#### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (3) ####
#### Message: 
#### System.Globalization.CultureInfo::get_CurrentUICulture [IP: 0003] ####
#### System.Globalization.NumberFormatInfo::get_CurrentInfo [IP: 0003] ####
#### System.Int32::ToString [IP: 000c] ####
#### RadioReporterMicro.PulseWidthMeasure::inputHandle_OnInterrupt [IP: 0068] ####

Failed allocation for 5 blocks, 60 bytes

Failed allocation for 5 blocks, 60 bytes

Failed allocation for 5 blocks, 60 bytes


#2

Take a look at this, shouldn’t be hard to convert:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1193927390


#3

You may try using the pincapture class http://www.ghielectronics.com/downloads/NETMF/Library%20Documentation/Index.html

You can tell it to start capturing at a specific state, how many changes you want to capture and the timeout. I found it reliable.

An example : http://code.tinyclr.com/project/289/dht11---temperature-and-humidity-sensor/

If you want to stick with interrupts, here is an example here : http://code.tinyclr.com/project/267/infrared-sender-and-receiver/

Good luck !

PS : is your scope a DSO nano ?


#4

The PinCapture class works really well, thanks for the tip. Scope is a Lecroy, pretty expensive unit I bought at an electronics store but can automatically range in and save to a USB thumb drive which is nice.


#5

Ok I posted the code for it at the below URL. It’s a cheapo RC receiver but it encodes all the info on a single wire which is kind of cool.

http://code.tinyclr.com/project/332/hobbyzone-receiver-controller/