RC Receiver PWM input "without using pulse in"
Shawna
Posts: 508
Has anyone written a RC Receiver "pwm input" program in BlocklyProp yet? I'm sure a person could use the pulse in command but I haven't tried it yet. I was hoping to come up with something to read 6 or 8 channels with a single core. A long time ago I wrote one in spin and it was too slow, I attempted to write one in PASM and then adopted Jason Dorie's. I am not sure if C is fast enough to read the channels with good resolution. I have put the blocks together in BlocklyProp but have not had time to test it.
On the BlocklyProp Demo site there is a user defined code block which I have used to perform floating point math in C, the block works pretty slick. I'm wondering if a person could use this block to insert PASM code to read the 6 or 8 channels.
Some might ask why not just use spin, well........ BlocklyProp is so easy to use and it is helping me to learn C. Also I am working on the activity bot with my son, its actually his bot, but I think I play with it more than he does. LOL
I am just brainstorming here with my time too tinker limited.
After I have time to test what I have written I will share it on the BlocklyProp site.
I think a block to read pwm signals from a RC Receiver would be a good addition.
Thanks
Shawn
On the BlocklyProp Demo site there is a user defined code block which I have used to perform floating point math in C, the block works pretty slick. I'm wondering if a person could use this block to insert PASM code to read the 6 or 8 channels.
Some might ask why not just use spin, well........ BlocklyProp is so easy to use and it is helping me to learn C. Also I am working on the activity bot with my son, its actually his bot, but I think I play with it more than he does. LOL
I am just brainstorming here with my time too tinker limited.
After I have time to test what I have written I will share it on the BlocklyProp site.
I think a block to read pwm signals from a RC Receiver would be a good addition.
Thanks
Shawn
Comments
I am not sure if the If then statements will be fast enough in the "Calc_Rx_Us" function.
I am using a spectrum DX6 TX and a RX that matches. If I recall correctly, the rising edge of all 6 channels start at the same time, if they don't this program definitely will not work.
Here is a link to it if anyone wants to take a look.demo.blockly.parallax.com/blockly/projectlink?id=2023&key=90253fe1-8674-4d7c-8fd9-ac9931360bee
The link doesn't seem to work, here is the SVG. Just delete the .zip off of the end of the file.
I think I am going to switch gears and try to use the built in counters to capture two Rx channels with one cog. I have never used the counters, but there are blocks in blocklyprop for them. If anyone has used them before with blockly I would love to see your code.
I have been studying this app note for the counters.
https://parallax.com/sites/default/files/downloads/AN001-P8X32ACounters-v2.0.pdf
What exactly are you trying to decode, and where in the chain ?
A typical RC unit uses Pulse Position Modulation, that becomes Pulse Width Modulation, in sequence.
https://hackaday.io/project/2465-manucon-a-glove-based-controller/log/8254-ppm-output
You could decode either.
PPM needs a single pin, but they are less commonly provided as outputs.
If you have 6-8 PWM pins, they are sequential, which means you could use a Hi-Gated counter, called '%01000 POS detector'
If you map PWM1 to CTRA and PWM2 to CTRB, you can wait for PWM1 to complete, then read, and remap pin to PWM3, whilst PWM2 is reading.
Likewise, PWM2 reads and re-maps to PWM4 whilst PWM3 is reading. So you alternate/walk through as many channels as you like, with 1 pair of counters.
The way I understand it is, that the signal is pwm because there is 1signal wire for each of the 6 channels.
The signal has a period of 20ms or 50hz and the high time is between 1ms and 2ms depending on the transmitters stick position. That sounds like pulse width modulation to me. I may be wrong though, wouldn't be the first time.Lol
I was messing with the counters last night but had no luck. I haven't quite wrapped my head around the counters yet. I don't understand how to read the high time using the counter.
I am going to mess with it today, I have a long weekend and 3/4 of a day with no one at home. Which doesn't happen very often.
The important detail is, the PWMs arrive one after the other. If you have a scope, display 2 channels at the same time to check.
If you report even a single low-byte from the counter, over a serial port, you should be able to see if it counts, or freezes, on the state of a pin.
That's the mode you want, so it counts on pin=hi, and holds last value on pin=lo. In the data that's POS detector
Thanks for your help, I learned something new, I didn't realize or know what PPM was, I had heard of it before.
I have 1 channel working with BlocklyProp, adding the other channels doesn't sound too hard now that I understand PPM.
I did have problems trying to sync the read and clear of the Accumulation Register. I had the problem of trying to read and clear the accumulation register while it was still accumulating. I think I solved the problem, not sure if there is a better way to do it though. I have attatched a screen shot and a zipped svg of the program if you would or anyone would like to look at it and learn me something new. In the program I am waiting for a transition of low to high and then high to low on channel 1 before I read and clear the accumulation register. Is there a better way to do that?
Thanks for your help
Shawn
blockly.parallax.com/blockly/projectlink?id=51752&key=54ae948b-80e9-4388-ac22-293448d1047d
In the 2 channel alternating version, you would Select/prime the other channel when earlier channel is seen to be hi, then when it goes low, you infer the other channel has gone hi, and read the first channel.
You might be able to do the waitpin in one line in Blockly ? (I've not used that) **
If you have a scope, you could shift the line where pin6 goes low, to after the IP=LO test exit, to show the time to read/save the pulse, so you can confirm that is fast enough. (Should be no problem)
Also confirm one pulse starts exactly when the previous one ends. The HW gate nature of this, is somewhat tolerant of modest overlaps or delays.
** Addit Hmm..., strange .
A quick scan of the docs finds System.Wait until, but that seems to apply to WAITCNT only, not WAITPNE etc ?
Other vendors Blockly suggest there is a Wait until input [] possible, but that's not showing in Prop docs ?
I wonder if the code above compiles down to the ideal 1 line of PASM ie WAITPEQ, or WAITPNE ?
If I try to change the pin to Pin1 by adding a 1 instead of a zero i get no accumulation in counterA. CounterA = %01000 << 26 + 1
I can change the + 0 to any value with no luck except pin 0.
Am I not understanding the bit orientation of the register.
The plus 0 in the picture was a + 1, + 0 does work
Look to me like those braces are going to shift left 27
Duh, sorry about that. Will teach me not to give snappy answers early in the morning after a very late night and before finishing my morning coffee.
The "%01000 << 26" sets the counter mode to POS detector
The "+ 1" selects I/O pin 1
This will cause counter A to count the system clock pulses whenever pin 1 is high. Is this what you wanted to do?
Yeah, that is exactly what I want it to do, but the only pin I can get the counter to work with is pin0. That is why I think I am configuring something wrong for the counter. I know there is a signal there also because I am using Pin6 as an indicator and the prop is seeing signal transition LO-High and High-LO. I'm stumped.
That was the problem, I should have seen that, to busy overthinking stuff.
Thanks
Operator precedence strikes again. One could reasonably expect the shift to be performed first and then for 1 to be added to the result, but that is a compiler implementation choice, so not a sure thing. For that reason I generally use brackets to ensure the desired precedence. Of course it helps to put the brackets in the right spots.
Here is a link to a working 6 channel Rx Rc Blockyprop program.
I need to comment it better. I also need to hook a scope up and see if it is reading at 50hz, I believe it is.
Project Name is.............. RC Receiver 6 Channel Input Using Counter A and B "WORKING"
blockly.parallax.com/blockly/projectlink?id=52824&key=b07565ee-951a-4b80-9f34-094e82b34d2f