CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

16F688 INTERNAL CLOCK UART PROBLEM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dodang8811



Joined: 04 Mar 2014
Posts: 4

View user's profile Send private message

16F688 INTERNAL CLOCK UART PROBLEM
PostPosted: Tue Mar 04, 2014 6:43 pm     Reply with quote

This is my code but MCU sends wrong message.
Code:

#include <16F688.H>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT, NOMCLR
#use delay(internal=4M)
#use rs232(baud=9600,parity=N,xmit=PIN_C4,rcv=PIN_C5,bits=8)
#define PMIC_RST   PIN_A2

//===========================================
void main()
{
   for(;;)
   {
      putc('1');
      putc('2');
      putc('3');
      putc('4');
      putc('5');
      putc('6');
      putc('7');
      putc('8');
      putc('9');
      putc('\n');
      putc('\r');

      //printf("hello\n");
      delay_ms(1000);
   }
}

I wanna send
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x0a,0x0d
( 1 2 3 4 5 6 7 8 9 \n \r)

but terminal received
0x39,0x32,0x33,0x36,0x35,0x36,0x37,0x3e,0x39,0xca,0xcd
( 9 2 3 6 5 6 7 > 9 ? ?)

And if I use
printf("hello\n");

it sends
" n e n n o ? "

How can I solve this problem?
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 04, 2014 8:21 pm     Reply with quote

It could be a 'timing' problem. The internal osc (currently 4MHz) could be off a bit, also since the internal osc can be selected as 8MHz, I'd use that.
2 options to try...

1) use a real 4MHz xtal (and 2 caps), alter code, recompile and test.

2) use your current setup but try 1200 Baud. Slower speeds tend to be more 'forgiving'.

You do have a 'max232' type interface chip between the PIC and PC ?

Another test is to remove PIC, jumper the TTL rx to the TTL tx pins and 'loopback' the PC terminal hardware to prove there's nothing wrong on that 'side' of the project.

Please post back what happens and we can help you from there.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Mar 05, 2014 1:44 am     Reply with quote

What voltage are you running the chip?. What temperature?.

The internal oscillator, on this chip, is guaranteed to be accurate enough for RS232, _if you are running at 3.5v_. Otherwise it 'may be accurate enough' at 5v and room temperature (but is getting borderline), but outside this, it is well outside the required accuracy.....

Best Wishes
dodang8811



Joined: 04 Mar 2014
Posts: 4

View user's profile Send private message

Thank you but I can't solve the problem yet.
PostPosted: Wed Mar 05, 2014 6:27 pm     Reply with quote

First, I have 3 16f688 chips and the results are all same.

//temtronic

I'm using max3232 chip between PC and PIC.
All frequencies(1M, 2M, 4M, 8M...) sends wrong data.

1) I can't use xtal because the chip is in a product. It's smd type circuit and I can't change it.

2) 1200 Baud send worse data like "fe fe fe fe fe ...."
I can't understand why slower speed results are worse.

3) Loopback test is OK.

//Ttelmah

When I used 3.5V, I got worse data.


Please give me more advice~
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 05, 2014 7:18 pm     Reply with quote

hmm..
well this is curious !!
I don't have a 16F688 so I 'white breadboarded' a 16F887 which has same/similar internal oscillator section, grabbed your code, made appropriate changes for the UART pins., and used the 887 device header file.

It works fine for me. I'm using Realterm for the PC terminal program and a TTL<>USB module for the interface.

Though it's a long shot, perhaps the fail-safe oscillator is enabled?
I would select the fuse 'NOFCMEN' though I didn't in my test.

Another question. Did you compile under MPLAB in 'debug' or 'release' mode?
If you compiled under 'debug'( the supplied default) , your code will NOT run correctly,usually slow.
I ran into this 'debug/release' issue a few years ago and my default is 'release' as I debug code in the real world not in simulations.

I'll keep the board up and running, but 'on the surface' I can't see anything wrong in your code or hardware setup.

hth
jay
dodang8811



Joined: 04 Mar 2014
Posts: 4

View user's profile Send private message

It works well on smd type.
PostPosted: Wed Mar 05, 2014 7:55 pm     Reply with quote

Is smd type chip more accurate?

Actually, yesterday I tested on DIP type chip, breadboard and max3232.

And I tested on my product few minutes ago.

In the product, PIC sends data to CPU.

And I checked data from CPU. It's working well now.

"123456789", "hello"

I don't know why, but thank you very much for your concerning.
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Mar 05, 2014 8:14 pm     Reply with quote

Glad it's up and running.
I'm always happy to help.

Jay
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

Re: It works well on smd type.
PostPosted: Thu Mar 06, 2014 7:00 am     Reply with quote

dodang8811 wrote:
Is smd type chip more accurate?

Actually, yesterday I tested on DIP type chip, breadboard and max3232.

And I tested on my product few minutes ago.

In the product, PIC sends data to CPU.

And I checked data from CPU. It's working well now.


Hi,

No, the package style itself would not explain your issue. My guess is that you have some sort of a wiring error on your breadboard!

John
dodang8811



Joined: 04 Mar 2014
Posts: 4

View user's profile Send private message

Thank you~!
PostPosted: Fri Mar 07, 2014 1:42 am     Reply with quote

//ezflyr

Thanks. I'll test on a new breadboard and jumper later.

Have a good day~!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group