Strange SerOut Problem


Closed Thread
Results 1 to 40 of 40

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Posts
    34

    Unhappy Strange SerOut Problem

    Gday,

    I have been programming the 16F628A to control servo's, with instructions being received from a PC. I had mostly everything in working order, and then everything started to deteriorate.

    I had SerIn and SerOut in almost perfect working order, with the only problem being the accuracy of all characters. Upon more testing, the quality of the transmissions from the PIC to the PC deteriated. For example, i was receiving the words "Declared Variables" from the PIC without any problems. Then I started receiving "Declared Var******", with the asterisks being random characters. I have now changed this to the alphabet for testing purposes.

    As of now, the PC does not acknoweledge any communications from the PIC, as if the serial cable is unplugged.

    I have stripped the program down to the basics, as shown below.
    Code:
    PORTA = 0
    PORTB = 0
    CMCON = 7 ' Set comparators off
    
    include "modedefs.bas"
    
    i var byte
    light var PORTB.0
    
    'Startup routine
    high light
    for i = 0 to 10
    	toggle light
    	pause 100
    next i
    low light
    
    pause 1000
    high light
    serout PORTA.1,N300,["AbcdefghijklmnopqrstuvwxyZ",10] 'Output lots of data slowly
    serout PORTA.1,N300,["AbcdefghijklmnopqrstuvwxyZ",10]
    serout PORTA.1,N300,["AbcdefghijklmnopqrstuvwxyZ",10]
    serout PORTA.1,N300,["AbcdefghijklmnopqrstuvwxyZ",10]
    low light
    pause 500
    
    end
    The LED flashes as expected, and the LED lights while the PIC is meant to be sending data to the serial port, slowly. Hyperterminal does not receive anything, and neither does my control program written in VB6.

    PORTA.1 is connected to the RX pin of the PC's serial port, ground is connected to the PC's serial port too. I have checked this many times, changed pins, changed cables, changed ports and even changed PIC's.

    I cannot see any problems with the code above, or the hardware used. The configuration bits i've set are 3F18.

    What I can't work out is why the SerOut command WAS working initially, but is not working anymore.

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    The configuration bits i've set are 3F18
    The internal oscillator of the 628A is not accurate enough for reliable asynchronous transmission - switch to a crystal or resonator and all should be well
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Apr 2007
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    Ok, I will try that when I can get my hands on a Resonator.

    What i can't understand is that it DID work, and then deteriorated. And even with a new chip, it doesnt work at all anymore.

    If anyone has any other suggestions in the meantime, please let me know.
    Thanks in advance!

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Something else probably changed, input voltage, temperature, shocked the PICs a bit, seasonal changes, humidity, whatever. Apparently, it was running close enough to 4mhz to keep the timing right to work at 300baud. Now the internal oscillator isn't running at 4mhz.
    The fact that you said it DID work just fine, then it would work for a few characters before it started sending random characters, and now it doesn't work at all suggests that the framing of the characters is getting farther and farther off the longer you are transmitting.

    Try using SEROUT2, with a mode # of 3332 (which is optimal). Then try shifting 3332 up and down a bit and see what happens. Eventually you'll hit on a range of numbers that does seem to work. Take the middle one and use it.

    My advice (as well as others I'm sure)...use an external crystal.
    Last edited by skimask; - 17th April 2007 at 12:14.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Have you checked the PC port or the signal from the cable?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Apr 2007
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    I'm using COM1 to send/receive data to the PIC, and i'm also using COM1 to program the PIC (using only one program at a time of course). So there's nothing wrong with the COM port because it programs the PIC fine.

    I've tried another computer also, with no different results.

  7. #7
    Join Date
    Apr 2007
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    I have PORTA.1 connected directly (with a resistor) to the RX pin on the serial port COM1 (pin 2 if I remember correctly) and using Hyperterminal for the time being.

    Do I use 'Driven True' (T300) or 'Driven Inverted' (N300)?

    skimask, you suggested Driven True. Is this right for my setup?

    Thank again.

  8. #8
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    If your pic is directly connected to the PC, you need inverted (idle low)
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  9. #9
    Join Date
    Apr 2007
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Try using SEROUT2, with a mode # of 3332 (which is optimal). Then try shifting 3332 up and down a bit and see what happens. Eventually you'll hit on a range of numbers that does seem to work. Take the middle one and use it.
    I have tried SerOut2 with the following modes: 3322, 3327, 3332, 3337, 3342 and 3347 (+5 increments).
    And then again with the following modes (inverted): 19706, 19711, 19716, 19721, 19726 and 19731.

    I would have thought I'd get something on the PC, but still nothing. Is this range too big? or too small? If this doesn't work, the is the resonator really going to fix all this?

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by masosi View Post
    I have tried SerOut2 with the following modes: 3322, 3327, 3332, 3337, 3342 and 3347 (+5 increments).
    And then again with the following modes (inverted): 19706, 19711, 19716, 19721, 19726 and 19731.

    I would have thought I'd get something on the PC, but still nothing. Is this range too big? or too small? If this doesn't work, the is the resonator really going to fix all this?
    Probably....but the main thing would be to put some sort of counter on it, 'scope, freq-meter, anything and write a program to see how fast the clock is really going.

    Failing that, write a program that counts up in seconds. Let it run for a few hours, compare it with a stopwatch and see how far off it is. Maybe it's actually so far out in the weeds that you can't even get into the ball park.

    What happens if you write a program to toggle an LED on and off once per second? Does it actually toggle once per second?

    Did you smoke the PC's serial port? Have the right COM1 port selected, etc.?
    Simple little things...we all know how it goes...but ya never know..could be something stupid that's tripping you up...

  11. #11
    Join Date
    Apr 2007
    Posts
    34


    Did you find this post helpful? Yes | No

    Default

    I'll try those ideas soon, thanks.

    Another thought...
    I'm running the 16F628A at 5.0V DC. After looking at the electrical information, it seems that I should be running it at 3.5V. This would run the internal oscillator at a more precise speed. Is this correct?

    Please make sure I'm getting this right.
    5V supply... 3.5V drop across the PIC... Voltage drop of 1.5V... PIC runs at 150mA
    R = V / I
    R = 1.5 / .15
    R = 10 ohms (1/4 watt)

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by masosi View Post
    I'll try those ideas soon, thanks.
    Another thought...
    I'm running the 16F628A at 5.0V DC. After looking at the electrical information, it seems that I should be running it at 3.5V. This would run the internal oscillator at a more precise speed. Is this correct?
    Please make sure I'm getting this right.
    5V supply... 3.5V drop across the PIC... Voltage drop of 1.5V... PIC runs at 150mA
    R = V / I
    R = 1.5 / .15
    R = 10 ohms (1/4 watt)
    What electrical information is telling you to run it at 3.5v?
    If you're talking about parameter F13, that's for 'jitter' not 'accuracy'.
    Last edited by skimask; - 21st April 2007 at 01:56.

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. Strange Serout Behaviour
    By bluesmoke in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th August 2009, 04:12
  4. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  5. Replies: 11
    Last Post: - 13th July 2005, 19:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts