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

Sanity check please

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



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

Sanity check please
PostPosted: Wed Sep 15, 2004 9:47 am     Reply with quote

About a week ago everything I compiled was trash. It compiled OK but didn't run. I wrote this Hello World program and found (by oscilloscope) that the baud rate was about 2900 baud vs the declared 9600 baud. The clock is from an external source and is definately 20MHz. Finally I just uninstalled the compiler and re-installed it and evereything was fine. Now a week later it has happened again!
Has anyone else seen this? Am I doing something stupid? Is there any better solution than simply re-installing the compiler? The compiler version is 3.104 but I can't get the MBA's that run this place to update it. I have my old trusty 2.7x PCB but it won't support the 16C771. The PC is running win2000 ver 5.00.2195.

Code:

#include <16C771.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOBROWNOUT,NOPUT,NOPROTECT

#use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1)

void main() {
short foo;

   fputs ("U Hello world \n\r");

   while (1) {                                  //Main polling loop
      delay_ms(10);
      output_bit(PIN_B0,foo++);
   } //while(1)
} //main()

_________________
The search for better is endless. Instead simply find very good and get the job done.
alexbilo



Joined: 01 Jun 2004
Posts: 39
Location: Trois-Rivi�res

View user's profile Send private message

PostPosted: Wed Sep 15, 2004 9:56 am     Reply with quote

I found that when these problems arise, looking at the assembly code listing is of great help. You can take a look at the code generated by the compiler to configure the RS232 module to see if the baud rate config seems correct. If you don't know assembly langage, you can even post the configuration code snippet and I'll take a look at it.

Good luck,
_________________
Alex
hillcraft-I am not logged
Guest







RS232 problems
PostPosted: Wed Sep 15, 2004 10:20 am     Reply with quote

We do 90% of our work on 18F458 vs RS232 @ 19200 BAUD.

I have found that the PC (Windows - RS232 UART) actually loses its mind sometimes and that a reboot is the only answer, this happens mostly with a laptop and Delphi after many compiles.

Another thing to look at is ground loops and earthing. We sometimes have very strange results with a project when the project is connected to the PC via USB and the RS232 port...It gets worse when we connect the PC based logic analyzer.

The best thing I have found to test the validity of a RS232 PIC based device when the PC looks like its losing its mind, is to test it against a Palm or an IPAQ, at least you eliminate ground loops, earthing and Windows XP.

Another thing you can do is to short 2 and 3 of the DB9 RS232 cable to one another and type a couple of characters on the PC. You should get the character echoed back properly. When my Compaq is in its 'mindless state', it actually echos garbage back.
Ttelmah
Guest







Re: Sanity check please
PostPosted: Wed Sep 15, 2004 10:50 am     Reply with quote

SherpaDoug wrote:
About a week ago everything I compiled was trash. It compiled OK but didn't run. I wrote this Hello World program and found (by oscilloscope) that the baud rate was about 2900 baud vs the declared 9600 baud. The clock is from an external source and is definately 20MHz. Finally I just uninstalled the compiler and re-installed it and evereything was fine. Now a week later it has happened again!
Has anyone else seen this? Am I doing something stupid? Is there any better solution than simply re-installing the compiler? The compiler version is 3.104 but I can't get the MBA's that run this place to update it. I have my old trusty 2.7x PCB but it won't support the 16C771. The PC is running win2000 ver 5.00.2195.

Code:

#include <16C771.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOBROWNOUT,NOPUT,NOPROTECT

#use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1)

void main() {
short foo;

   fputs ("U Hello world \n\r");

   while (1) {                                  //Main polling loop
      delay_ms(10);
      output_bit(PIN_B0,foo++);
   } //while(1)
} //main()

I'd switch to using the EC fuse, rather than HS for an external oscillator. I have seen problems in the past, because with HS selected, the internal amplifier is set to fairly high gain, on the assumption it is receiving a reasonably attenuated sinusoid, and if you drive the input directly, with a CMOS clock chip, odd 'clipping' can result. Normally this gives an 'overfrequency' behaviour, rather than underfrequency, but it might cause your type of problem.
It may be that the uninstall/reinstall, has nothing to do with the problem, but that the delay between retrying, that this generates, does.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 15, 2004 10:51 am     Reply with quote

Read this thread -- especially Darren's comment about different
device files. Have you recently been installing different versions
of the compiler ?
http://www.ccsinfo.com/forum/viewtopic.php?t=19614
Guest








PostPosted: Wed Sep 15, 2004 10:55 am     Reply with quote

Your transmit pin is B0 what is the external IT input, too. Probably sometimes the ext it is (unexpectly) enabled and every transmit bit causes an IT. In this case the default CCS IT handler is executed (context saving, do nothing then context restore). Just my 2 cent.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Sep 15, 2004 12:18 pm     Reply with quote

Sad
Using the EC clock fuse, rebooting and un-installing and re-installing the compiler have had no effect. Not only is the baud rate bad, but the 10ms square wave (the while loop) only runs one cycle, then nothing happens untill aparently the watchdog resets (despite the NOWDT fuse) in about 2 seconds.
I guess I will dig out an old PC and put PCW on it and see what it gives.
_________________
The search for better is endless. Instead simply find very good and get the job done.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Sep 15, 2004 12:25 pm     Reply with quote

I have found out, by my own mistake and hair loss, that if I enable an interrupt without having a ISR defined that the PIC will go brain dead when a delay() function is called. Make sure that you have a routine for EVERY interrupt that you have enabled.

Ronald
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Sep 15, 2004 1:17 pm     Reply with quote

I tried a different PC and added
disable_interrupts(Global);
with no difference in behavior. Oddly disabling the interrupts made this change in the code to toggle the port pin:
Code:

  ....................    while (1) {                                  //Main polling loop
  ....................       delay_ms(10);
  006A:  MOVLW  0A
  006B:  MOVWF  27
  006C:  GOTO   03D
  ....................       output_bit(PIN_B0,foo++); 
  006D:  BSF    03.6
  006E:  COMF   30,F
  006F:  BCF    03.6
I !> 0070:  MOVF   20,W
D <! 0070:  MOVF   22,W
  0071:  ANDLW  01
  0072:  XORLW  00
  0073:  BTFSS  03.2
  0074:  GOTO   077
  0075:  BCF    06.0
  0076:  GOTO   078
  0077:  BSF    06.0
  0078:  BSF    03.5
  0079:  BCF    06.0
  ....................    } //while(1) 

That was the only change disabling interrupts made in the .lst file beyond the statement itself. Foo is declared a short so foo++ should toggle it, right?
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 15, 2004 1:21 pm     Reply with quote

There are a few things about your test program that I would change.

1. I would use Pin B0 as the recv pin of the soft USART, and Pin B1
as the xmit pin. This gives you the option of using the external
interrupt to detect an incoming start bit. (ie., #int_ext)

2. You're incrementing a "short" variable. Is this operation defined ?
A 1-bit "short" is an invention of CCS. I would regard doing
anything except setting it and reading it, as extremely risky.
I looked at the ASM code for "foo++" and I don't know what its
doing. I don't think it's doing what's intended.

I would change "foo" from a short, to a char. Then the ASM code
looks clean.

3. You're toggling the xmit pin of the soft usart in your while() loop.
I'm not sure why. I would have done several lines of putc('U').
That will test the soft usart.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

Curiouser and curiouser
PostPosted: Wed Sep 15, 2004 2:26 pm     Reply with quote

The plague is spreading! A board that has been running for weeks sealed in a watertight housing has suddenly come down with the same problem. It seemed to suddenly stop sending data but upon opening the housing I find that the embedded PC that takes the data from the PIC and combines it with other data and sends it in packets up to the surface is rejecting the data because the baud rate is about 3300 instead of the original 9600 baud!
Somehow it is a hardware problem, not a compiler problem. Time to roll out another set of tools.

Thanks to all that tried to help.
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 15, 2004 2:45 pm     Reply with quote

That's about one third the baud rate. This suggests a crystal that is
supposed to operate in 3rd overtone mode is actually running in
fundamental mode. I would check the external oscillator.

You mentioned a water-tight container. This implies possibly cold
temperatures at an undersea location.

I would open up the suspect unit on the bench and freeze the oscillator
with freeze-mist. Then check the output frequency.

----
Edited for a typo.


Last edited by PCM programmer on Wed Sep 15, 2004 3:10 pm; edited 1 time in total
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Sep 15, 2004 3:04 pm     Reply with quote

Actually there are two PICs on the PCB. One is a trusty 16C58B that runs the sonar transmitter off of a 20MHz crystal. The other is the troublesome 16C771. The 16C771 gets its clock from the OSCOUT (pin 15) of the 16C58B which is a rock steady 20MHz when I put a scope on it. In this case the sonar transmitter is idle so there is no EMI from that.

I have three 16C771s on my desk:
A) a windowed part several weeks old that the original development was done on and still has the program.
B) an OTP part that worked for a few weeks and just stopped.
C) another windowed part of the same lot as A but recently programmed.

All three chips verify OK by my Dataman 48 programmer with VCC +/-10%. But A works fine. B & C run slow. Both windowed parts have stickers on the windows.

Maybe tomorrow I will try a different programmer, and a laboratory 20MHz TTL source. But now its 5:00.....Miller time!
_________________
The search for better is endless. Instead simply find very good and get the job done.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 15, 2004 3:24 pm     Reply with quote

I had assumed that "external oscillator" meant it was coming from
a "can". It's actually tapped off the oscillator circuit of the 16C58B.
That's adding a load onto the oscillator circuit.
I would now definitely suspect some interaction that might
cause the oscillator to start up at 6.67 MHz.


This thread on the Microchip forum discusses running 2 or more PICs
from one crystal.
http://forum.microchip.com/tm.asp?m=41722
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