PDA

View Full Version : [Question(s)] Reading RC receiver values on a Cubloc ?



balbaro
05-19-2013, 11:58 PM
Reading Pulse Length from a RC receiver (http://cubloc.com/phpBB3/viewtopic.php?f=2&t=4183#p11884)



Hello all,

Could somebody please help me with this :

I bought a second hand 2 wheeler T-Bot from Robo3.com with the Cubloc integrated but without any software or documentation.

Module = Cubloc CB280 (Comfiletech.com)

I manage to generate a PWM signal to control 2 motor controllers via PWM channel 4 and 5.
Now i want to intercept the signal from a 2 channel RC receiver and send to my PWM outputs when valid and needed.

If i understand correctly i have to obtain the pulselength in ms of the input pins signal.
I use Pin 22 and 23 to intercept the RC signals via interrupt 2 and 3.
I set the state of the interrrupts to catch both low and high states.

How can i time the length of the high state pulses of the two pins in the interrupt routine ?
There is no RTC in the CB280

There are not much tutorials available for the Cubloc.

Anyone with experience of these modules ?

jwatte
05-20-2013, 12:05 PM
I assume the CB280 has a timer of some sort? Else it wouldn't really be able to output PWM waveforms...

So, set up a timer running at a known frequency. Read the value of the timer when the rising edge is detected; read it again when the falling edge is detected; subtract and you have the duration of the pulse (approximately -- there will be some interrupt jitter.) Remember that unsigned subtraction wraps, so "133 - 65280" actually makes sense (and has the value 389.)

The internet thinks the CB280 is based on the Atmega128, which has 16-bit timers. If I remember correctly, it's easy to set a 16 bit timer to run so it ticks about two times per microsecond, which should give you both sufficient accuracy and duration for those pulses.

Xevel
05-20-2013, 07:46 PM
Just to add a little precision to what Jwatte just said:
The product page says "High Speed Counters 2 Channel 32-bit Counters (up to 2Mhz)", identify how to use them with the programming language they use (BASIC? really ? >_>) and do what he said.
Depending on how you can configure them, you might want to watch out of overflows too.


EDIT: Just had a better look at the user manual... Honestly my guess it that you won't have access to anything fast and real-time enough to measure the pulses accurately and in an elegent way. And what I just said is irrelevant.

The user timer is 10ms, which is a little too slow to be of use since RC pulses are between 0.5 and 2ms. and occure every 20ms.

balbaro
05-20-2013, 10:31 PM
EDIT: Just had a better look at the user manual... Honestly my guess it that you won't have access to anything fast and real-time enough to measure the pulses accurately and in an elegent way. And what I just said is irrelevant.

The user timer is 10ms, which is a little too slow to be of use since RC pulses are between 0.5 and 2ms. and occure every 20ms.

Thats what i was afraid of, i'm thinking of using a Arduino Uno to receive the pulses and translate to a serial command or could i use a I2C RTC , could i obtain a timer fast enough from a I2C RTC ?
Never used a I2C module so i dont know much about the protocol.
Thanks very much for the help.

Always learning :)

jwatte
05-21-2013, 12:11 AM
could i obtain a timer fast enough from a I2C RTC

No. For two reasons:

1) The I2C protocol runs typically at 400 kHz (there's a slower mode at 100 kHz, and a faster mode at 1 MHz.) A transaction typically takes half a dozen bytes or more, and each byte typically needs about 12-16 clock intervals, depending on how fast the source and destination are Thus, the resolution of commands is nowhere near enough for decoding the fine pulse resolution needed for RC pulses.

2) An RTC typically only gives you seconds. Sometimes, they give you milliseconds, I guess, but they very seldom give you microseconds, which is what you really need. The point of a RTC is to remember "what time it is" while the power is off, and to advance "what time it is" for wall clock time at a higher precision than a microcontroller can do.

Your best bet is either to see whether you can re-program the Atmega128 directly, using an ICSP (there may be some pins/headers you can hook up to to do that,) or to replace that board with a board that you can program at the low enough level to do the deode.
Another option would be to implement the decode on an Arduino board, and use serial or I2C to communicate the decoded data to your controller. The benefit of that is that, doing a single thing (decoding RC pulses) means you can worry less about interrupt latencies (but there's still some annoying problems from the Arduino library timer handlers.)

balbaro
05-21-2013, 09:53 PM
Thanks for the response jwatte.
I'll use a Uno or maybe a Propeller to intercept the RC values and send the pulse width values via serial to the Cubloc module.
Reprogramming the Atmega128 is to advanced for me.
I want to keep the Cubloc cause of the CUSB-22D (http://cubloc.com/product/03_02cusb22d.php) it is used on.
Thinking of it, i can even send the values to my laptop wich will be used for the wifi connection to a desktop.