PDA

View Full Version : 12F683 serout timing



Hobie Cat
- 20th December 2009, 02:36
Hello all,

I have been searching for a solution to this problem and found some answers that sounded promising but ended up not doing the trick.

As some others have posted - I too am having trouble with the serout timing of the 12f683. I'm sending to a MAX232 and receiving with a PC running serial terminal. If I use a 16F877A it works fine, so I think the MAX is OK. Some Hex characters (below $08 and above $FC) work fine, but the ones in between are not the correct code. For instance I send $13 and the receiver gets $35. The data seems very consistent, just mostly wrong. I would prefer to not use the external resonator (behavior is the same using the internal 8MHZ clock (with OSCCON %01110000), but I wanted to try an external resonator to just to see if it would help - it did not.), but this code shows it with a external resonator.



Include "modedefs.bas" ' Mode definitions for Serout

' Define ADCIN parameters
Define ADC_BITS 8 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 200 ' Set sampling time in uS

'config_hs_osc 'do I need this?
define osc 8

ANSEL =%00110100 ' Set Internal clock, Set AN2 analog, rest digital
CMCON0 =%00000111 'analog comparator off
ADCON0 =%10001001 'right justify, channel 2 analog, a/d converter on
OSCCON =%01111001 '8 mhz external resonator
OSCTUNE=%00000000 'varied between %00000011 and %00011100 no help

adval var byte ' Create adval to store result

loop:

ADCIN 2, adval ' Read channel 2 to adval

pause 500

serout2 GPIO.0, 396, [$13] 'receiver is seeing $35
serout GPIO.0, T2400, [$13] 'same thing


Goto loop ' Do it forever

End

I have seen in some of the other posts about tuning the ocillator, that doesn't seem to help. I tried varying the baud around 396 (I'm doing 2400 baud - driven true), no help.

I think it's a timing issue, but I don't know what else to change, any ideas?

Thanks!

Archangel
- 20th December 2009, 05:23
Hello Hobie Cat,
Osctune is where you tweak the OSC,
from the data sheet below:
OCSTUNE = 0' runs at calibrated freq.
OSCTUNE = %00001111 ' OSC TWEAKED TO FREQ + x percent
OSCTUNE = %00010000 ' OSC tweaked to FREQ - x percent




REGISTER 3-2: OSCTUNE: OSCILLATOR TUNING REGISTER
U-0 U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0
— — — TUN4 TUN3 TUN2 TUN1 TUN0
bit 7 bit 0
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
bit 7-5 Unimplemented: Read as ‘0’
bit 4-0 TUN<4:0>: Frequency Tuning bits
01111 = Maximum frequency
01110 =



00001 =
00000 = Oscillator module is running at the calibrated frequency.
11111 =



10000 = Minimum frequency

Hobie Cat
- 20th December 2009, 17:24
Thanks Joe,

I tried varying the OSCTUNE around %00000000, it seemed to work best with no tuning, if my idea of best is right. With the tuning at 0, Hex chars below $08 and above $FC work fine it's just all the ones in between that are the wrong code, it's the same every time, just wrong. If I adjust OSCTUNE or the baud rate the characters received do change, but none of them are right, and sometimes they get jumbled, so I'm guessing that means no tuning of OSCTUNE or baud is helping.

I'm trying to find out if there is a pattern to the wrongly received codes, like 2x or something like that. I'll let you know if I find out anything.

Thanks!

Archangel
- 20th December 2009, 18:58
Hello Hobie Cat,
Make sure the idle state of the ports are correct for the communication mode you are using. TRUE data idles HIGH and requires a pull up resistor. INVERTED data idles LOW and requires a pull down resistor.

Dennis
- 21st December 2009, 02:22
Hi Hobie Cat

Just did a forum search on "12f683 serout" ..plenty results like this one

http://www.picbasic.co.uk/forum/showthread.php?t=12239&highlight=12f683+serout
Have you maybe tried with the internal clock

http://www.picbasic.co.uk/forum/showthread.php?t=11824&highlight=12f683+serout
and a few more tips

http://www.picbasic.co.uk/forum/showthread.php?t=8623&highlight=12f683+serout

Hope this helps

Dennis

Hobie Cat
- 21st December 2009, 06:06
Hello Joe and Dennis,

Thanks for the ideas. After an exhaustive day of the same results I gave up and took a nap. When I came back I tried a new chip and it works just fine.
So, I guess somewhere I messed up some internal thing while programming maybe? The rest of the functions of the chip seem to work fine on all the ports just no correct serout on any port.

I'm glad I bought a bunch of chips when I was doing the buying... Sorry to waste your time:o

Dennis
- 21st December 2009, 07:28
Hey Hobie Cat

Glad you solved the problem :-)

Check my thread regarding a 16F690 ...
I still haven't resolved my problem on that one .. I eventually decided to try a different chip so also (temporarily) just gave up on it.
I intend to get hold of another 16F690 to eliminate whether or not it's the chip or not.

Thanks for the info and update :-)

Keep well
Dennis

Archangel
- 21st December 2009, 16:57
Hello Joe and Dennis,

Thanks for the ideas. After an exhaustive day of the same results I gave up and took a nap. When I came back I tried a new chip and it works just fine.
So, I guess somewhere I messed up some internal thing while programming maybe? The rest of the functions of the chip seem to work fine on all the ports just no correct serout on any port.

I'm glad I bought a bunch of chips when I was doing the buying... Sorry to waste your time:o
#1. Glad you have it working, a nap's almost always a good idea.
#2. It's never a waste of my time if you make me think. Helps keep the machinery oiled ;) and besides, I cannot even see my bench right now, I don't want to get too rusty.