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 support@ccsinfo.com

SERIAL BUG or PIC Problem???????????????????
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

SERIAL BUG or PIC Problem???????????????????
PostPosted: Wed Feb 09, 2005 10:56 am     Reply with quote

Hi,

I have a problem with my project in 18F4620 20Mhz, I need to obtain data from UART (C6,C7) to 115k and the fgetc NOT WORK. I try with FORCE_SW and this clausule work in 57600 but not in 115k. I remove the directive #ZERO_RAM and fgetc work in 115k without clausule FORCE_SW.

The other problem with solution is that I can not comunicate with my serial device (C1,C2) to 115k, the solution is put the clausule SAMPLE_EARLY in the #USE definition. This is a bug from compiler or a bug from Microchip 4620?

Somebody know which is the problem with ZERO_RAM clausule.

I hope that this information help to you in found the solution.

Thank you very much!

Best Regards,
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Wed Feb 09, 2005 10:56 am     Reply with quote

CONTINUE....

I send a simple program for test the fgetc

This LST not work fgetc (BAD)
Code:

MPASM

CCS PCH C Compiler, Version 3.218, 25972               09-Feb-05 03:41

               Filename: Test.LST

               ROM used: 132 bytes (0%)
                         Largest free fragment is 65404
               RAM used: 6 (0%) at main() level
                         6 (0%) worst case
               Stack:    0 locations

0000 EF02 F000      00001 GOTO   0004
0000                00002 ....................  #include <18F4620.h>
0000                00003 ....................  //////// Standard Header file for the PIC18F4620 device ////////////////
0000                00004 .................... #device PIC18F4620
0000                00413 .................... #list
0000                00414 ....................
0000                00415 .................... #device *=16
0000                00416 .................... #device adc=8
0000                00417 .................... #case
0000                00418 .................... #use delay(clock=20000000)
0000                00419 .................... #fuses  HS,NOWDT,NOLVP,PROTECT
0000                00420 .................... #opt 11
0000                00421 .................... #zero_ram
0000                00422 ....................
0000                00423 .................... #use rs232( BAUD =  115200, PARITY = N, XMIT = PIN_C6, RCV = PIN_C7, BITS = 8, STREAM = SERIAL_2 ) //, FORCE_SW, ERRORS )
0000                00424 ....................
0000                00425 .................... void main()
0000                00426 .................... {
0004 6AF8           00427 CLRF   FF8
0006 9ED0           00428 BCF    FD0.7
0008 0EFE           00429 MOVLW  FE
000A 6E00           00430 MOVWF  00
000C 0E10           00431 MOVLW  10
000E 6E01           00432 MOVWF  01
0010 6AEA           00433 CLRF   FEA
0012 0E02           00434 MOVLW  02
0014 6EE9           00435 MOVWF  FE9
0016 6AEF           00436 CLRF   FEF
0018 2AE9           00437 INCF   FE9,F
001A B4D8           00438 BTFSC  FD8.2
001C 2AEA           00439 INCF   FEA,F
001E 2E00           00440 DECFSZ 00,F
0020 D7FA           00441 BRA    0016
0022 2E01           00442 DECFSZ 01,F
0024 D7F8           00443 BRA    0016
0026 6AEA           00444 CLRF   FEA
0028 6AE9           00445 CLRF   FE9
002A 50C1           00446 MOVF   FC1,W
002C 0BC0           00447 ANDLW  C0
002E 090F           00448 IORLW  0F
0030 6EC1           00449 MOVWF  FC1
0032 0E07           00450 MOVLW  07
0034 6EB4           00451 MOVWF  FB4
0036 50B4           00452 MOVF   FB4,W
0038 9CA1           00453 BCF    FA1.6
003A 86B8           00454 BSF    FB8.3
003C 0E2A           00455 MOVLW  2A
003E 6EAF           00456 MOVWF  FAF
0040 0E26           00457 MOVLW  26
0042 6EAC           00458 MOVWF  FAC
0044 0E90           00459 MOVLW  90
0046 6EAB           00460 MOVWF  FAB
0000                00461 ....................     //
0000                00462 ....................     // Defino variables locales
0000                00463 ....................     //
0000                00464 ....................     char cCh;
0000                00465 ....................
0000                00466 ....................     fprintf( SERIAL_2, ">" );
0048 0E3E           00467 MOVLW  3E
004A A89E           00468 BTFSS  F9E.4
004C D7FE           00469 BRA    004A
004E 6EAD           00470 MOVWF  FAD
0000                00471 ....................     cCh = fgetc( SERIAL_2 );
0050 AA9E           00472 BTFSS  F9E.5
0052 D7FE           00473 BRA    0050
0054 CFAE F006      00474 MOVFF  FAE,06
0000                00475 ....................     fprintf( SERIAL_2, "%c\n\r", cCh );
0058 5006           00476 MOVF   06,W
005A A89E           00477 BTFSS  F9E.4
005C D7FE           00478 BRA    005A
005E 6EAD           00479 MOVWF  FAD
0060 0E0A           00480 MOVLW  0A
0062 A89E           00481 BTFSS  F9E.4
0064 D7FE           00482 BRA    0062
0066 6EAD           00483 MOVWF  FAD
0068 0E0D           00484 MOVLW  0D
006A A89E           00485 BTFSS  F9E.4
006C D7FE           00486 BRA    006A
006E 6EAD           00487 MOVWF  FAD
0000                00488 ....................
0000                00489 ....................     fprintf( SERIAL_2, "\n\r" );
0070 0E0A           00490 MOVLW  0A
0072 A89E           00491 BTFSS  F9E.4
0074 D7FE           00492 BRA    0072
0076 6EAD           00493 MOVWF  FAD
0078 0E0D           00494 MOVLW  0D
007A A89E           00495 BTFSS  F9E.4
007C D7FE           00496 BRA    007A
007E 6EAD           00497 MOVWF  FAD
0000                00498 ....................     while( TRUE );
0080 D7FF           00499 BRA    0080
0000                00500 .................... }
0000                00501 ....................
0082 0003           0502 SLEEP

Configuration Fuses:
   Word  1: C200   HS IESO FCMEN
   Word  2: 1E1F   BROWNOUT NOWDT BORV21 NOPUT WDT32768
   Word  3: 8700   CCP2C1 PBADEN LPT1OSC MCLR
   Word  4: 0081   STVREN NODEBUG NOLVP NOXINST
   Word  5: C000   PROTECT NOCPD NOCPB
   Word  6: E00F   NOWRT NOWRTD NOWRTC NOWRTB
   Word  7: 400F   NOEBTR NOEBTRB

SYMBOL TABLE
  LABEL                             VALUE

_RETURN_                          00000001
main.cCh                          00000006
PSP_DATA                          00000F83
C1OUT                             00000FB4
C2OUT                             00000FB4
CCP_2                             00000FBB
CCP_2_LOW                         00000FBB
CCP_2_HIGH                        00000FBC
CCP_1                             00000FBE
CCP_1_LOW                         00000FBE
CCP_1_HIGH                        00000FBF
main                              00000004

MEMORY USAGE



This LST work fgetc (GOOD)

Code:

MPASM

CCS PCH C Compiler, Version 3.218, 25972               09-Feb-05 03:42

               Filename: C:\Documents and Settings\cfernandez\Escritorio\Metro AM\ftes\AMDK-Test\iMFR\iMFR-BAD\Test.LST

               ROM used: 102 bytes (0%)
                         Largest free fragment is 65434
               RAM used: 6 (0%) at main() level
                         6 (0%) worst case
               Stack:    0 locations

0000 EF02 F000      00001 GOTO   0004
0000                00002 ....................  #include <18F4620.h>
0000                00003 ....................  //////// Standard Header file for the PIC18F4620 device ////////////////
0000                00004 .................... #device PIC18F4620
0000                00413 .................... #list
0000                00414 ....................
0000                00415 .................... #device *=16
0000                00416 .................... #device adc=8
0000                00417 .................... #case
0000                00418 .................... #use delay(clock=20000000)
0000                00419 .................... #fuses  HS,NOWDT,NOLVP,PROTECT
0000                00420 .................... #opt 11
0000                00421 .................... //#zero_ram
0000                00422 ....................
0000                00423 .................... #use rs232( BAUD =  115200, PARITY = N, XMIT = PIN_C6, RCV = PIN_C7, BITS = 8, STREAM = SERIAL_2 ) //, FORCE_SW, ERRORS )
0000                00424 ....................
0000                00425 .................... void main()
0000                00426 .................... {
0004 6AF8           00427 CLRF   FF8
0006 9ED0           00428 BCF    FD0.7
0008 6AEA           00429 CLRF   FEA
000A 6AE9           00430 CLRF   FE9
000C 50C1           00431 MOVF   FC1,W
000E 0BC0           00432 ANDLW  C0
0010 090F           00433 IORLW  0F
0012 6EC1           00434 MOVWF  FC1
0014 0E07           00435 MOVLW  07
0016 6EB4           00436 MOVWF  FB4
0018 50B4           00437 MOVF   FB4,W
001A 9CA1           00438 BCF    FA1.6
001C 86B8           00439 BSF    FB8.3
001E 0E2A           00440 MOVLW  2A
0020 6EAF           00441 MOVWF  FAF
0022 0E26           00442 MOVLW  26
0024 6EAC           00443 MOVWF  FAC
0026 0E90           00444 MOVLW  90
0028 6EAB           00445 MOVWF  FAB
0000                00446 ....................     //
0000                00447 ....................     // Defino variables locales
0000                00448 ....................     //
0000                00449 ....................     char cCh;
0000                00450 ....................
0000                00451 ....................     fprintf( SERIAL_2, ">" );
002A 0E3E           00452 MOVLW  3E
002C A89E           00453 BTFSS  F9E.4
002E D7FE           00454 BRA    002C
0030 6EAD           00455 MOVWF  FAD
0000                00456 ....................     cCh = fgetc( SERIAL_2 );
0032 AA9E           00457 BTFSS  F9E.5
0034 D7FE           00458 BRA    0032
0036 CFAE F006      00459 MOVFF  FAE,06
0000                00460 ....................     fprintf( SERIAL_2, "%c\n\r", cCh );
003A 5006           00461 MOVF   06,W
003C A89E           00462 BTFSS  F9E.4
003E D7FE           00463 BRA    003C
0040 6EAD           00464 MOVWF  FAD
0042 0E0A           00465 MOVLW  0A
0044 A89E           00466 BTFSS  F9E.4
0046 D7FE           00467 BRA    0044
0048 6EAD           00468 MOVWF  FAD
004A 0E0D           00469 MOVLW  0D
004C A89E           00470 BTFSS  F9E.4
004E D7FE           00471 BRA    004C
0050 6EAD           00472 MOVWF  FAD
0000                00473 ....................
0000                00474 ....................     fprintf( SERIAL_2, "\n\r" );
0052 0E0A           00475 MOVLW  0A
0054 A89E           00476 BTFSS  F9E.4
0056 D7FE           00477 BRA    0054
0058 6EAD           00478 MOVWF  FAD
005A 0E0D           00479 MOVLW  0D
005C A89E           00480 BTFSS  F9E.4
005E D7FE           00481 BRA    005C
0060 6EAD           00482 MOVWF  FAD
0000                00483 ....................     while( TRUE );
0062 D7FF           00484 BRA    0062
0000                00485 .................... }
0000                00486 ....................
0064 0003           0487 SLEEP

Configuration Fuses:
   Word  1: C200   HS IESO FCMEN
   Word  2: 1E1F   BROWNOUT NOWDT BORV21 NOPUT WDT32768
   Word  3: 8700   CCP2C1 PBADEN LPT1OSC MCLR
   Word  4: 0081   STVREN NODEBUG NOLVP NOXINST
   Word  5: C000   PROTECT NOCPD NOCPB
   Word  6: E00F   NOWRT NOWRTD NOWRTC NOWRTB
   Word  7: 400F   NOEBTR NOEBTRB

SYMBOL TABLE
  LABEL                             VALUE

_RETURN_                          00000001
main.cCh                          00000006
PSP_DATA                          00000F83
C1OUT                             00000FB4
C2OUT                             00000FB4
CCP_2                             00000FBB
CCP_2_LOW                         00000FBB
CCP_2_HIGH                        00000FBC
CCP_1                             00000FBE
CCP_1_LOW                         00000FBE
CCP_1_HIGH                        00000FBF
main                              00000004

MEMORY USAGE
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 09, 2005 6:06 pm     Reply with quote

Some small background info on RS232:
The sample clock is only allowed to have an frequency error of about 3%. A data byte consists of 10 bits (8 data bits, a start bit and a stop bit), 10 times 3% error = 30% total error. With bad quality lines the error margin will drop to 2% or below. Maxim has a good application note on this, too bad I can't find the link now.

This 3% error margin is combined for both the sender and transmitter!

In your 2nd example code with the hardware UART the baudrate is set to 20MHz/4( 0x2A + 1) = 116.279 baud, a positive error of almost 1%. If your transmitter has an error of -2% or more you will receive garbage.
Many PCs are known to have large frequency offsets....

Do you have a scope? If yes, you can check the timing of the other device.
Or just quick, try the effect of reducing the baudrate in your 2nd example to 113k5.

A good thing with the hardware UART is to add the 'ERRORS' directive which will clear the error bits in the UART for you (otherwise the UART will stop receiving).

Edit: Removed an invalid remark about software UARTs.


Last edited by ckielstra on Wed Feb 09, 2005 6:39 pm; edited 1 time in total
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Wed Feb 09, 2005 6:12 pm     Reply with quote

Thank you very much!! for explain me this. But the problem not is the baud rate, is the ZERO_RAM.

I send this to CCS support and they tell me:

CCS Support wrote:
>
> This message is a reply to CCS e-mail id: 5B2624
>
> There is a problem with #ZERO_RAM on this part. Do not use it until the next release.

The next release is the Friday.

What you do think?

Best Regards,
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Feb 09, 2005 6:44 pm     Reply with quote

Comparing your two examples I don't see how the #zero_ram is affecting the hardware UART. Both generated assembly listings are equal, except for the RAM clearing part. The RAM clearing part only writes to RAM, not to any of the UART related file registers as far as I can see.
I still think you can fix your problem by configuring the next lower baudrate of 113k5. Especially the fact that the software UART started working when you enabled early sampling is a good hint in this direction.
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Wed Feb 09, 2005 10:20 pm     Reply with quote

I have too many problems with my 18F4620, I dont know if all problems are bugs or the microchip part have some problem. The point is that the problem exist!, if a case for the RIPLEY's

Other strange problem is that my board to 20Mhz can comunicate by the UART to 115kb excellent, but I change the crystal to 25Mhz and to 115Kb I see garbage!!. Now I am crazy!!, I want to found some people that develop on 18F4620 and CCS and ask if have some problem.

Sorry by my english.

Thank you very much!.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Feb 10, 2005 4:06 am     Reply with quote

Quote:
Other strange problem is that my board to 20Mhz can comunicate by the UART to 115kb excellent, but I change the crystal to 25Mhz and to 115Kb I see garbage!!. Now I am crazy!!, I want to found some people that develop on 18F4620 and CCS and ask if have some problem.

Your problem is that you can not use this PICs directly with a 25MHz crystal and fuses in HS-mode. The maximum speed of an external crystal can be 20MHz, see table 26-6 of the 18F4620 manual. If you want to run at higher frequencies you use either the 4x PLL multiplier or an external clock driver. For example, 40MHz can be achieved with a 10MHz crystal and setting the fuses to HS+PLL.

Funny how people come up with the same problems in a short time span, in the last two days you are the 3rd person having troubles with running at high clock speeds above 20MHz.
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Thu Feb 10, 2005 7:56 am     Reply with quote

Dear ckielstra,

Thank you very much!, for your information.

I have a question, Why in the table 2-2 Page 24 say 25Mhz????. and where you see that other people have the same problem?


Best Regards,
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Feb 10, 2005 8:54 am     Reply with quote

cfernandez wrote:
Dear ckielstra,

Thank you very much!, for your information.

I have a question, Why in the table 2-2 Page 24 say 25Mhz????. and where you see that other people have the same problem?


Best Regards,


I don't feel like grabbing a copy of the data sheet but does it say 25MHz "CRYSTAL" or 25MHz "OSCILLATOR". Two very different things.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Feb 10, 2005 9:07 am     Reply with quote

Quote:
I have a question, Why in the table 2-2 Page 24 say 25Mhz????
It must be a bug in the manual. Some other processors like the 18F458 are specified up to 25MHz for crystal oscillators. You might be lucky to find some samples to work at 25MHz but no garuantee. If you want to run faster than 20MHz. Your processor will run up to 40Mhz when using either an external clock driver or a slower crystal in combination with the internal 4x frequency multiplier.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Thu Feb 10, 2005 11:11 am     Reply with quote

ckielstra wrote:
Quote:
I have a question, Why in the table 2-2 Page 24 say 25Mhz????
It must be a bug in the manual. Some other processors like the 18F458 are specified up to 25MHz for crystal oscillators. You might be lucky to find some samples to work at 25MHz but no garuantee. If you want to run faster than 20MHz. Your processor will run up to 40Mhz when using either an external clock driver or a slower crystal in combination with the internal 4x frequency multiplier.


Definately a typo in table 2-2. Didn't see any correction made in the errata either.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Thu Feb 10, 2005 11:55 am     Reply with quote

I make a ticket in Microchip support and this is your answer:

** PLEASE DO NOT RESPOND TO THIS AUTOMATED MESSAGE VIA E-MAIL **
** TO RESPOND SUBMIT ADDITIONAL COMMENTS TO THIS TICKET ON SUPPORT.MICROCHIP.COM **

Below is a response from Microchip Engineering Support Team for your submitted ticket #: 1-13744
A description of the problem and our proposed resolution is contained below.

Area: PICmicro Products
Product Group: PIC18FXX20
Product: PIC18F4620

Problem Description:
I have a some question:

Question 1)
We buy 30 parts 18F4620 in DigiKey, and the idea are use this with 25Mhz and 115Kb, but we have problem with the UART for this speed, we change the crystal to 20Mhz and the UART in 115Kb work OK.

I see that in the table 2-2 of 18F4620 (39626b.pdf) say 25Mhz, but now I see that in the table 26-6 say that the max. speed in HS is 20Mhz.

Can you explain me this difference.

Question 2)
Exist some bug in the 18F4620 parts??

Question 3)
How to idenfy if my parts are OK or are lots with bugs?

Question 4)
I try with 10Mhz PLL and I have garbage in the comunication, This feature work fine?


I wait your answer for make a new order to DigiKey for 100 parts more.

Thank you very much!

Bert Regards,



Problem Resolution:
For a 25Mhz oscillator the error in baud rate will be just over 13%, which is greater than the tlerances in the rs-232 spec.
Dropping the oscilator frequency to 20 mhz will improve the baud rate error to under 9.6% which may be close enough.

There is an error in the datasheet where HS oscillator mode is rated to 25 Mhz. There is curently documentation rectifying this in the process of being published.

There are several errata items in teh PIC18F4620 these are covered in the errata document.
http://ww1.microchip.com/downloads/en/DeviceDoc/80224a.pdf
The errata applies to the currently available devices.

You should be able to clock the device at 40 mhz with an external 10 mhz cyrstal and the x4 PLL. You may have to check your baud rate and configuration of the USART.


If the resolution provided does not solve your problem, you may respond back to the support team through the web interface at support.microchip.com. Telephone support is also available Monday-Thursday between the hours of 7:30am and 4:00pm MST and on Friday between 10:00am and 4:00pm. You may contact the Support department by calling (480) 792-7627. You will be prompted to enter the Ticket ID shown in the subject line of this message for verification. Enter the Ticket ID which is 1-13744 substituting the '-' with the '*' key. Press # on your telephone when finished.

Please do not respond to this message via e-mail.


Microchip Engineering Support
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Thu Feb 10, 2005 11:58 am     Reply with quote

Where found the exactly documentation for know why 115kb in 25Mhz have more errors that 115kb in 20Mhz.

I remenber see this doc in microchip, but now I not found. Somebody know where is this?

Thanks,
Chas
Guest







PostPosted: Thu Feb 10, 2005 12:40 pm     Reply with quote

I find it most curious that when I go to Microchip's website and search for the PIC18F4620 that there are no errata sheets in the search results. There are for most other processors. If you check the document in the above post by cfernandez, it is 10 pages long!!! I wonder what other dirty little secrets, oops I mean errata sheets, are lurking in the weeds???
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Thu Feb 10, 2005 12:43 pm     Reply with quote

16F877A,.. oops that doesn't go to 25Mhz

Last edited by treitmey on Thu Feb 10, 2005 6:48 pm; edited 1 time in total
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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