How to interface with RC receiver, please?

abenn

Senior Member
I want to build a simple switch that will switch an LED on and off when the throttle in my RC system passes about the halfway mark. I'm using the Picaxe 08 proto board with output to an LED via a transistor, and signal input from the RC receiver to pin 1 of the 08M2 via a 22k resistor, and a capacitor between pin 1 and ground (can't remember, but I must have picked that up from one of the circuits in the manual). Anyway, here's the code I'm using:

Code:
main:

let b13=0

checkinput:

pulsin 1,1,b13
if b13> 100 then high 2
else
  low 2
endif
goto checkinput
This way, the LED stays lit whatever the position of my throttle. If I change the if line to b13< 100, the LED stays off whatever the throttle.

What have I got wrong, please? Is is the code, or is it the number in the if line?
 

alband

Senior Member
Pulsin requires a word variable. Try replacing all your "b13s" with a word variable, e.g. "w0".
Could also try changing the "100" value?

Hope that helps
 

abenn

Senior Member
OK, I've used "w0" instead of "b13" (but we're dealing with numbers here, aren't we, so I don't understand why a word variable is needed?), and changed the number to 1 and 5000 instead of 100, with same result. I don't quite understand how receivers interface with servos, though I do believe it's something to do with pulse width, whereas what pulsin is doing is measuring the number of pulses in a set time. So I'm thinking my simple code is not enough to measure the changes.

Edit: I've just found elsewhere that the number I should be using is between about 75 and 225, with mid point being 150. So maybe there's something wrong with my circuit, rather than the program.
 
Last edited:

alband

Senior Member
Some reading material:

http://www.digitalnemesis.com/info/docs/rcservo/ How servos and receivers work/talk.

http://www.picaxe.com/docs/picaxe_manual2.pdf Good old manual 2 has never failed me.

Just some quick answers (but DO read at least the first link and the relevant bits in manual 2 (pulsin and variables would be good places to start):

[As far as I'm aware] byte variables (b0, b1 etc) store a number between 0 and 255. Word variables (w0, w1 etc) are just bigger byte variables, nothing to do with "words". They store numbers between 0 and 65535. (So try changing the 5000 to 50000 and see if there's a difference?). A note of caution though, "w0" is just a combination of "b0" and "b1". Similarly "w1" is "b2" & "b3" etc. So if you are using byte and word variables in your code, make sure they don't "overlap" with each other. You can't use b0 or b1 if you're also using w0 in the same bit of code.

The pulsin command measures pulse width, not number of pulses (which would be the "count" command I think, could be wrong).
 

Armp

Senior Member
and signal input from the RC receiver to pin 1 of the 08M2 via a 22k resistor, and a capacitor between pin 1 and ground
How big is the capacitor? I'd keep it to < 5nF, but not sure why its there at all?

TC = 5nF *22K = 110uS, Risetime = 2.2 TC or ~ 0.25mS
 

abenn

Senior Member
Thanks for the references, alband. I've been refering to the picaxe manual regularly, but I'm still stumped by some of it. But now that you mention it, I remember the difference between byte and word variables, and that would explain why it wouldn't accept a fraction of a number when I was using b13 as the variable. Anyway, I've got no overlaps, for what you see code-wise is all I've got at the moment, until I can get it working and then incorporate it into a bigger program. I had already tried 5000 but, as I mention in my previous edit, I've found a source elsewhere that tells me I should be looking between 75 and 225 for standard RC receiver output.

The cap is so small I can't read its value, Armp. Anyway, I've removed it just a few minutes ago, and it makes no difference. Tomorrow I'm going to strip all the components off my proto board (there's three transistors and several jumpers from a previous project) and re-wire it from scratch, for I'm sure the issue must be there somewhere. With a value of 150 in the if statement, the led is flickering for all throttle positions, though it does occasionally go off at certain stick positions.
 

srnet

Senior Member
This way, the LED stays lit whatever the position of my throttle
Seems likely.

From the manuals, the default frequency of M2 parts is 4Mhz.

At 4Mhz pulsin returns the width of the pulse in 10uS units.

So a 1ms pulse, normally low throttle or idle, would give you a count of 100.

So if you wanted to test for mid throttle you really want;

pulsin 1,1,b13
if b13> 150 then high 2
 

abenn

Senior Member
Well, thanks for your patience guys. Turns out I had one, and probably more, issues, none of which were to do with the Picaxe code! First, my transmitter was set for PCM output instead of PPM, so my receiver wasn't responding correctly (servos simply juddered, in all channels); and secondly there was possibly a short between tracks or my added components somewhere in my proto board. Anyway, I set my transmitter to PPM mode then stripped all my components off the proto board, cleaned the solder off the tracks, connected my receiver input to pin 3 via a 10k resistor (it had been 22k previously) and connected a single output transistor to pin 2.

Needless to say, the LED now switches on/off at approximately 50% throttle when the module is plugged into the throttle channel of my receiver. Thank you.
 
Top