Problem interfacing rc reciever with microcontroller T89C51AC2

Thread Starter

Lateral

Joined May 31, 2009
9
hi all,

i've got a project with my team to build an rc submarine and since we have few channels on the remote but lots of things to control, we want to get the microcontroller to read the PWM signal from the rc reciever and use it to decide what stuff to turn on and off etc. I've included the code in assembler. The microcontroller is from the 8051 series, T89C51AC2 - we didn't pick it, it was just what we had from the equipment we bought for a lab course and we had lots of documentation on it so we just went with it.

We had successfully had the microcontroller produce a software PWM that matches exactly the characteristics of the signal the reciever gives and when we attach a servo to the breadboard and connect the white wire to the microcontroller output we get exactly what we want - the servo moves as expected.

however, when we try to read the input PWM and try to copy it at the output (for proof of concept), we get an output that is erratic and not at all a binary sequence, which is what would be expected if the microcontroller was just doing the math wrong. We've checked the output of the reciever (input to the micro) and its perfectly ok when its connected to the microcontroller. We've also tried stabilizing it by connecting the following circuit:

http://mcu-programming.blogspot.com/2006/09/servo-motor-control.html

but although we know it does stabilize the waveform (we tried the successful PWM output and it was somewhat cleaner when we used this circuit) it did little to stabilize the input (we just did it in case it fixed the problem) and less to stabilize the erratic output PWM that was supposed to mirror the input.

we've clipped the code and tried each part seperately and we know it can produce a clean PWM. we also know that whatever else we're doing is not indirectly interfering with the software PWM. To be specific, we use Timer2 to count the full period, Timer1 to count the pulse width and we reload these with values from the PCA counter (unit 0) which, through interrupts and a bit of math, records the pulse width and period of the input. Using just timers 1 and 2 works great, even with the PCA IRQ code in place and running. Its just when we have the timers (timer1 to be exact) reload themselves with the values of the input PWM after these are calculated properly (since the input measures the time and we want them to overflow at FFFFh, we have to subtract from the latter to get a useful reload value for our timers).
What's really odd is that with a steady input we get a really unsteady output. In one case the width of the output pulses seems to almost oscillate rapidly from a small duty cycle to a large one. Also, the pulses at the output seem to be jagged, somewhat like the output voltage isnt steady. we're assuming that is caused both by the fast switching (though to be honest, its only about 50Hz on a 12Mhz crystal) and some instabilities that present themselves even with the good PWM output (there is a slight slope at the low bottom of the pulses, like something is charging slowly from 0 to 1 and gets interrupted early - we're using Visual Analyzer connected to a USB sound card and thats all we have for an oscilloscope - we've already been told we would have to switch to a sound card with a line-in input to get proper readings).

at other times the output was like a very subtle sine wave, with spikes where the pulse should start and end. This is very weird cause it seems like its a PWM but with only spikes to indicate the pulse's position. The period and pulse width change properly and the period and lengths are all exactly right. it's just that its not a pulse train but rather like the PWM integrated (since there is a positive spike where the pulse starts 0->1 and a negative spike where the pulse ends 1->0). The same code has managed to produce both kinds of output in our experience and we haven't linked it to anything yet. We've made sure no other part of the circuit (the rest of the stuff we have on the breadboard) is either connected directly or indirectly to the micro or the reciever or servo.

we cant figure out what's causing the erratic output - we've gone throug the code many many times and found some errors but nothing that fixed this.

the only other thing i can mention that might be of interest is that somehow through magic or something, the servo that we connected to the breadboard seems happy to respond directly to the recievers commands when the red and black wires are properly connected to the reciever (when it's on ofcourse - thankfully we can still apply natural laws to that...) and the white wire is connected to the output circuit of the microcontroller, when the microcontroller is without power, the circuit that stabilizes is connected to absolutely nothing and there is no power to the breadboard. however the servo won't run if any of the 3 wires is disconnected or is connected in any other way other than power and ground at the reciever's end and the white wire either on the microcontroller output (the non-powered microcontroller) or at 5 volts (when we power the breadboard). whenever its connected this way, it responds as if its normally connected to the reciever, directly.

sorry for the extremely long post, but we're pretty desperate - this project has been stabbing us left and right with bizarre issues since the beginning

thanks in advance
 

Attachments

bertus

Joined Apr 5, 2008
22,270
Hello,

Is it possible to post a schematic?
It looks like the power (switch pulses) are triggering the MCU in some way.
This may cause the instability.

Greetings,
Bertus
 

Thread Starter

Lateral

Joined May 31, 2009
9
um that was insanely fast - like you were reading it while i was typing :eek:

i'll do you one better than a schematic (or one worse, depends) i've got nude pics of the breadboard.

dont have much time right now for a schematic but i could do one tomorrow if its necessary - in which form do you want it? i can do it in multisim or circuit simulator (http://www.falstad.com/circuit/)

in the pics you can see the micro with its basic circuit connected in the middle part of the breadboard. the middle and right section have their power and ground lines connected, the one at the left is isolated cause it has a 555 chip wired to run a brushless dc motor. at the time we were trying out the servos we made sure we had nothing connected to that part (lower right, from the potentiometer and down). the blue-purple wires you see connected to the + - lines on the left are not connected to anything

in any case, the servo was either wired directly to the reciever or the microcontroller supply which is regulated and on the other side. the two pairs of red and black wires are from the servo and reciever (the one in the middle left is the reciever). when i took the pic we had the reciever output power cable disconnected (thats why the red wire is in the air) so it wouldnt mess with the input or other servo. the bright blue wire at the near top left is the one that is connected to P1.2 and the reciever is connected to P1.3 (if i remember correctly) through the purplish wire (the color most wires in the pic have).

edit - oops forgot to ask what you mean exactly - are you saying that the power pulses from the reciever are interfering? oh btw, we made sure that both reciever and micro are working at the exact same voltage levels (TTL)
 

Attachments

bertus

Joined Apr 5, 2008
22,270
Hello,

Do you have used decoupling capacitors?
These should be 0.1μF each, mounted close to the Vcc and ground pins of each chip.
(as far as I can see there are none).
These are used to prevent pulses to travel along the leads to other parts.
Motors can create stong pulses.

Greetings,
Bertus
 

Thread Starter

Lateral

Joined May 31, 2009
9
well generally we dont use decoupling capacitors for every chip, certainly havent thought of doing it for the reciever. the problems arise only when the reciever is connected to the micro so we thought that if anything is at fault, its that.

the max232 is connected normally and the only other chip is the 555 which is completely disconnected from the micro and the rest of the I/O circuitry for the servo and reciever. the motor is also disconnected completely - if you mean capacitors on its leads.
 

bertus

Joined Apr 5, 2008
22,270
Hello,

Perhaps the reciever is reacting on the pulses created by the MCU on the powersupply.
Try a decoupling capacitor at the powerpoints of the MCU.
Try a decoupling capacitor also at the powerpoints of the reciever.

Greetings,
Bertus
 

Thread Starter

Lateral

Joined May 31, 2009
9
hmm we did scope the reciever's end both right at the point it connects to the board and where it meets the mc's port and it's signal seems almost completely clear besides that slight slope on the low output

its an idea though, thanks ^_^ we'll try it - hope it works :)
 
Top