Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Data out of sync only after receiving input

Status
Not open for further replies.

mik3ca

Member
I have an at89C4051 chip attached to the PC serial port via 3V conversion. The reason for this is because eventually I'll connect to a radio module instead of PC and the radio module won't work past 3.9V.

When its time to output data to the serial port, I set R4 to equal #OUTPUTCHAR and accumlator high nibble to the data itself. R2 represents the sequence number from 0 to 15 to sync the data and is always supposed to count from 0 to 15 then reset to 0 and repeat that counting pattern on every call to the code.

Now when I call another function to collect data inputted from the serial port, I notice that my output data continuously skips sequence 1.

This is example of data transmitted to the PC that's ok:

10 41 32 23 34 45 46 47 58 49 6a 4b 7c 4d 8e 4f

and this is bad data after calling the function to collect serial data:

1f 10 32 23 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f

IR2 is R2's address. If I modify the location of IR2, or R2, then R2 is modified.

The strange thing is, I never modified the contents of the above in any other function, so the only thing that comes to my mind is that 57.6kbps baud is too high for a 22.1184Mhz crystal?

cjne R4,#OUTPUTCHAR,nooutc
cjne R2,#3h,sudest1
mov A,MEL ;MEL=20h
sudest1:
cjne R2,#2h,sudest2
mov A,MEH ;MEL=30h
sudest2:
orl A,R2
clr TI
mov SBUF,A
inc R2
anl IR2,#0Fh
jnb TI,$
nooutc:

Is there another thing that could cause such skipping?
 
I'd like to help you, but there is so much information you do not divulge..

A code snippet doesn't help... I need to see serial setup and data extraction... I also need to see your RS232 convertor schematics....
 
circuit.png

This is my converter circuit. I connected pins 1, 4, and 6 together on the serial port and I connected pins 7 and 8 together on the serial port so that it always satisfies the PC when it wants to go into hardware shaking mode. The OS I'm using is linux. My circuit uses a large ground plane and the metal casing of the on-board serial port plug is also grounded.

I used 1N4007 diode because I'm afraid if I didn't use one that's strong enough then I might make a faulty circuit, but then again, maybe I could change the diode. I used 47nF capacitor because thats the highest ceramic I have on hand and I think if I use too high of value then the port won't function properly?

I also begin to wonder if the UARTs themselves are the culprits. I have a feeling my PC uses 16550A uart and the AT89C4051 uses an older style 8250 uart and I read that the 8250 issues an interrupt for every character where as the 16550A issues an interrupt for every 14 characters.

If anyone has a good answer I'll look into it, but in the meantime I'll play with the serial settings in linux and see if I can tweak them to make my project work.

Right now, I'm using 57600bps speed for tests.
 
Are you sure that circuit can handle 57600?... What is Vcc?.... For a good communication you really need +9V ~ -9V minimum... That is a crass circuit..... Try 9600 first and see if it improves...

The 47nf may be fast but you need a 1uf polarised to get the voltage swing...
 
Are you sure that circuit can handle 57600?

This circuit is similar to the following URL except they use different resistor values and they claimed to have transfer a large chunk of data over 115200bps: http://picprojects.org.uk/projects/simpleSIO/ssio.htm

... What is Vcc?....
For me, it is 3.3V because later I'll be replacing the adapter with an HM-TRP wireless module to use with my microcontroller.

For a good communication you really need +9V ~ -9V minimum... That is a crass circuit.....
Does that 9V requirement only apply to long cable lines? I'm willing to shorten my cable length if that's the case.

Try 9600 first and see if it improves...
I remembered once trying 9600 with no improvement but today what shocked me was that the data between the micro and the PC is correct but that was before I started running other programs in the session. I bet my PC with linux is the culprit.

The 47nf may be fast but you need a 1uf polarised to get the voltage swing...
This is when I feel a calculator can come in handy because you're suggesting 1uF but I don't know why specifically 1uF and not 0.1uF or 2uF. And can the cap be anything polarized or certain types?
 
You are bouncing the voltage... Now I know polyester caps are used with dedicated RS232 chip..( Use them myself ) But they have twice the bounce... once to -5v and +10 and -10v... I think the idea is to get the -v from the txd line the polarised cap will allow that to happen better... The +pin is connected to ground... so the cap can be charged negatively..
 
Ok, but then why specifically the 1uF value? Is there some time constant between C and a connecting resistor I should follow that directly affects maximum transmission speed?
 
No! I use them as the are the smallest electrolytic cap you can get... As some Ic's use 10uf, I suppose 0,1uf to 10uf seems to be okay..

But!! As I said.. try 9600 or 2400 first... If the signal is fine at lower speeds, then you know its the circuit..
 
I used 1N4007 diode because I'm afraid if I didn't use one that's strong enough then I might make a faulty circuit, but then again, maybe I could change the diode.

Use a 1N4148 diode, as in the original circuit.
A 1N4007 is a low frequency rectifier diode and will not work at 10s of kilohertz as you are trying to do.

JimB
 
I have to see what is going on with my computer or something because I still get the same results (of one skipping character per 15 bytes), and now I can't factor cable length because I did a direct connection to my circuit from the PC serial port. I also changed the diode. I will try to up the capacitance and see if that helps
 
1N914 as also a slow blocking diode
Not really Ian, the 1N914 is described in the datasheets as a "Small signal fast switching diode", ideal for this application.

JimB
 
Not really Ian, the 1N914 is described in the datasheets as a "Small signal fast switching diode", ideal for this application.

JimB
I use them for every product.... As flywheel diode... I've always assumed they were just rectifiers.. Well, You learn something every day...
 
Ok, what specs do I need to look for in the datasheet to determine if the diode is correct? ideally the speed I want to transmit data at is 115200bps
 
what specs do I need to look for in the datasheet to determine if the diode is correct?
If you are looking for a low frequency (50 or 60Hz) power rectifier, you need to look at things like:

Maximum repetitive peak inverse voltage (Vrrm)
Maximum RMS voltage (Vrms)
Maximum DC blocking voltage (Vdc)
Maximum average forward rectified current If(av)

I got these from the Vishay datasheet for the 1N4007


If you are looking for a diode to rectify high frequencies (greater than say 1kHz), you would first look at similar parameters for voltage and current, and then you would look for parameters like:

Reverse recovery time (Trr)

The Vishay datasheets for the 1N914 and 1N4148 both specify this parameter (4ns), the datasheet for the 1N4007 does not.
From this and other numbers in the 1N4007 datasheet, experience tells us that it is not suitable for high frequencies.

You are looking for 115200 bits per second, as a quick approximation, if you had a binary 101010101 pattern, the fundamental frequency of that waveform would be 115200/2 = 57.6kHz which is very fast for a 1N4007.

A period of 4nS corresponds to a frequency of 250MHz. For rectifying we would want our frequency to be a lot less than half of this, say 100MHz.
So for a low power application such as yours, a 1N4148 or 1N914 would be a good choice.


1N4007, reverse recovery and high frequency switching.

Because of its slow reverse recovery time, the 1N4007 can be used as a cheap RF switching diode for non-critical applications.
When forward bias is applied to the 1N4007, current flows.
When an RF signal is superimposed on the bias, the RF passes through the diode, EVEN WHEN THE DIODE IS REVERSE BIASED by the RF voltage being greater than the bias voltage.
This is all down to this reverse recovery thing, the charge carriers in the semiconductor material do not have enough time to recombine and this allows the diode to keep on conducting in the reverse direction.
PIN diodes are made to maximise this effect and are used for RF switching.

JimB
 
Ok, it turns out the big problem here is my linux machine. After reading up more on stty and online sources, it turns out my machine was eating up bytes because of the characters being received such as 11h. It had software flow control on by default which wrecked things. see: https://linux.die.net/man/1/stty

I turned off flow control and enabled raw settings. While the project isn't 100% perfect, at least all nibbles are transmitted as expected at 56k.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top