1. 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.
    Dismiss Notice

Data out of sync only after receiving input

Discussion in '8051/8951' started by mik3ca, Oct 27, 2017.

  1. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    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:

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

    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?

    Is there another thing that could cause such skipping?
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,245
    Likes:
    911
    Location:
    Rochdale UK
    ONLINE
    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....
     
  3. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    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.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,245
    Likes:
    911
    Location:
    Rochdale UK
    ONLINE

    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...
     
  6. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    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

    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.

    Does that 9V requirement only apply to long cable lines? I'm willing to shorten my cable length if that's the case.

    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.

    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?
     
  7. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    Also, should I be concerned with capacitor ESR rating here?
    and How would polarized cap make the circuit improve vs a non-polarized one?

    I was thinking of upgrading to this kind of capacitor:
    http://futurlec.com/Capacitors/C1000UMC.shtml
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,245
    Likes:
    911
    Location:
    Rochdale UK
    ONLINE
    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..
     
  9. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    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?
     
  10. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,245
    Likes:
    911
    Location:
    Rochdale UK
    ONLINE
    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..
     
  11. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    It probably is the combination of the circuit and data because I look here: http://picprojects.org.uk/projects/simpleSIO/ssio.htm

    and it states transmitting a lot of nulls discharges the capacitor completely and it even mentions about lowering 100nF to 47nF or even 22nF for high data rates because of distortion. I should probably increase my resistor values
     
  12. JimB

    JimB Super Moderator Most Helpful Member

    Joined:
    Sep 11, 2004
    Messages:
    6,353
    Likes:
    586
    Location:
    Peterhead, Scotland
    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
     
  13. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    I dont have immediate access to a 1N4148 but I do have a 1N914 which I will try
     
  14. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    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
     
  15. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,245
    Likes:
    911
    Location:
    Rochdale UK
    ONLINE
    1N914 as also a slow blocking diode... You need a fast recovery diode..
     
  16. JimB

    JimB Super Moderator Most Helpful Member

    Joined:
    Sep 11, 2004
    Messages:
    6,353
    Likes:
    586
    Location:
    Peterhead, Scotland
    Not really Ian, the 1N914 is described in the datasheets as a "Small signal fast switching diode", ideal for this application.

    JimB
     
  17. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,245
    Likes:
    911
    Location:
    Rochdale UK
    ONLINE
    I use them for every product.... As flywheel diode... I've always assumed they were just rectifiers.. Well, You learn something every day...
     
  18. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    now im confused
     
  19. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    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
     
  20. JimB

    JimB Super Moderator Most Helpful Member

    Joined:
    Sep 11, 2004
    Messages:
    6,353
    Likes:
    586
    Location:
    Peterhead, Scotland
    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
     
  21. mik3ca

    mik3ca Member

    Joined:
    Jun 24, 2017
    Messages:
    180
    Likes:
    1
    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.
     

Share This Page