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

PIC18F2550 REPLACED FOR PIC18F26K22
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gaugeguy



Joined: 05 Apr 2011
Posts: 288

View user's profile Send private message

PostPosted: Wed Dec 08, 2021 8:37 am     Reply with quote

You need to use LAT and not PORT when setting an output. PORT is for input and LAT is for output.
rudy



Joined: 27 Apr 2008
Posts: 167

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

PostPosted: Thu Dec 09, 2021 5:59 am     Reply with quote

It worked at the end!

But I am not sure what is the SPI frequency I am working with. I finally got the SPI running, I presume I am running at 64MHz, but the refresh rate of the LCD is exactly the same as 18F2550 running at 48Mhz.

Quite confusing...

Code:
#include <18F26K22.h>
#fuses NOWDT, NOFCMEN, NOIESO, NOCPD, NOPROTECT, NOLVP, NODEBUG, PUT, BROWNOUT, NOMCLR
#use delay(internal=64MHz)
#use SPI(MASTER, SPI1, MODE=0, BITS=8)
#use I2C(MASTER, SDA=PIN_B1, SCL=PIN_B2)

#byte PORTA=0xF80
#byte PORTB=0xF81
#byte PORTC=0xF82
#byte PORTE=0xF84
#byte SSP1CON1=0xFC6
#byte SSP1STAT=0xFC7

#define TFT_CS    PIN_B5   //LCD CHIP SELECT PIN
#define TFT_RST   PIN_B4   //LCD RESET PIN
#define TFT_DC    PIN_B3   //LCD DATA/COMMAND PIN

//#bit SET=PORTA.0
#bit RGT=PORTA.1
#bit LFT=PORTA.2
#bit U_P=PORTA.3
#bit D_W=PORTA.4
#bit F_M=PORTA.5
void main()
   {
      SETUP_ADC_PORTS(NO_ANALOGS);
    SETUP_COMPARATOR(NC_NC_NC_NC);
      SETUP_COUNTERS(RTCC_INTERNAL,RTCC_DIV_1);
    SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_8);
    SETUP_TIMER_2(T2_DISABLED,0XFF,16);
      SETUP_TIMER_3(T3_DISABLED);
      SETUP_CCP1(CCP_CAPTURE_FE);
      SET_TRIS_A(0b11111110); 
      SET_TRIS_B(0b11000001);
      SET_TRIS_C(0b11010111);
      SET_TRIS_E(0b11111111);
   SSP1CON1=0X30;
   SSP1STAT=0X40;
loop:
   while(1)
      {
      }
goto loop;
   }
temtronic



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

View user's profile Send private message

PostPosted: Thu Dec 09, 2021 7:34 am     Reply with quote

LCD refresh is determined by the LCD module not the SPI speed.
SPI speed is the 'data transfer' rate.
Historically LCDs are slow devices, so you' need to read the datasheet for your to see how 'fast' it is.
To measure the SPI speed, simply put scope or frequency counter on the SPI clock pin, send a character forever, read the scope or counter.
rudy



Joined: 27 Apr 2008
Posts: 167

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

PostPosted: Thu Dec 09, 2021 7:44 am     Reply with quote

With Oscilloscope, the maximum I could reach is 1,60mhz at clock pin. The IIL9341 can easily reach 10Mhz.
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Thu Dec 09, 2021 10:38 am     Reply with quote

Try explicitly setting the SPI clock rate:

#use SPI(MASTER, SPI1, MODE=0, BITS=8, BAUD=8MHz)

The slew rate limitation of the SPI port, together with the setup and hold
times of the devices, means that though it can potentially clock to 16MHz,
this is usually out of spec. However 4Mhz, and 8MHz, should
work. I've used the SPI at 8Mhz on the same chip you are using and
it merrily worked fine.
If it doesn't go to 8MHz, you need to do a basic 'flash an LED' test and
check your chip genuinely is running at 64MHz.

What compiler version are you actually using with this?.
rudy



Joined: 27 Apr 2008
Posts: 167

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

PostPosted: Thu Dec 09, 2021 10:43 am     Reply with quote

Hi Ttelmah

When I insert this:

Quote:

#use SPI(MASTER, SPI1, MODE=0, BITS=8, BAUD=8MHz)


There is an error:

Quote:

*** Error 100 "TRAKER.c" Line 5(5,50): USE parameter value is out of range Not a number: 8MHZ
1 Errors, 0 Warnings.


My compiler is 5.007, but I am moving to 5.049 soon

Regards.
rudy



Joined: 27 Apr 2008
Posts: 167

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

PostPosted: Thu Dec 09, 2021 10:47 am     Reply with quote

There is another issue. The clock waveform is weird. The SDO is sharp square wave, but the clock signal is strange. I don't know if there is nome other configuration I need to do on PIN_C3. Have to check.
rudy



Joined: 27 Apr 2008
Posts: 167

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

PostPosted: Thu Dec 09, 2021 11:42 am     Reply with quote

All wrigth!

Chip is not running at 64Mhz.

I did this: (as mentioned by Ttelmah:

Code:
#include <18F26K22.h>
#fuses NOWDT, NOFCMEN, NOIESO, NOCPD, NOPROTECT, NOLVP, NODEBUG, PUT, BROWNOUT, NOMCLR
#use delay(internal=64MHz)

void main()
   {
      SETUP_ADC_PORTS(NO_ANALOGS);
    SETUP_COMPARATOR(NC_NC_NC_NC);
      SETUP_COUNTERS(RTCC_INTERNAL,RTCC_DIV_1);
    SETUP_TIMER_1(T1_INTERNAL|T1_DIV_BY_8);
    SETUP_TIMER_2(T2_DISABLED,0XFF,16);
      SETUP_TIMER_3(T3_DISABLED);
      SETUP_CCP1(CCP_CAPTURE_FE);
      SET_TRIS_A(0b11111110); 
      SET_TRIS_B(0b11000001);
      SET_TRIS_C(0b11010111);
      SET_TRIS_E(0b11111111);
loop:
     while(1) //PG NORMAL DE TRABALHO
      {
      output_high(pin_a0);
      output_low(pin_a0);
      }
goto loop;
   }


and I found a nice 2MHz on pin A0, and it should be 16Mhz.

I will check what is wrong with the clock prior to proceed.

Regards.
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Thu Dec 09, 2021 12:46 pm     Reply with quote

No, it shouldn't be 16MHz. Each output instruction is 3 machine cycles, and
the loop is another two. This is why to test the speed you need to do it
with delays in the loop. Something like:
Code:

     while(TRUE)
      {
        output_toggle(pin_a0);
        delay_ms(1);
      }

This should give about 500Hz.

The current loop should give about 2Mhz. Your chip is running at 64 MHz
(16MIPS, 8 instruction times per loop) = 2MHz.
rudy



Joined: 27 Apr 2008
Posts: 167

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

PostPosted: Thu Dec 09, 2021 12:53 pm     Reply with quote

Rsrsrsrsrs.

Exactly 500Hz. A nice square wave.
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Fri Dec 10, 2021 1:17 am     Reply with quote

In which case you should be able to get the SPI to 4 or 8MHz. Same
question as before, what compiler version is this being tried on?. Also
what happens if you specify 8MHz?.
rudy



Joined: 27 Apr 2008
Posts: 167

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

PostPosted: Fri Dec 10, 2021 6:47 am     Reply with quote

Well, Ttelmah;

The compiler version now is 5.049. I Expect that the 18F26k22 could be at least 30% faster them 18F2550 (64/48). I have here an old particular development, that uses an 320x240 ILI9341 LCD color display, and I am trying to do the SPI communication a little bit faster, to get better LCD screen image changing. But I also have the 18F2550 running in the old development, along with this new development, and I can see any difference within both processors SPI speed.

All I can do now, with my poor knowledge, is to check if the sending image routine is the problem perhaps, may be it is not as good as it could be.

Regarding with your question, if I understand it, The #use_spi statement you send me, didn't make any change to SPI speed, in fact, it got slower than the original statement.

This is your suggestion:
Code:
#use SPI(MASTER, SPI1, MODE=0, BITS=8, BAUD=8000000)

This is what I am using:
Code:
#use SPI(MASTER, SPI1, MODE=0, BITS=8)

And later, on main part, I write these lines:
Code:
SSP1CON1=0X30;
SSP1STAT=0X40;

It is the fastest speed I could get till now.
If this is the maximum speed, I will proceed anyway, because the 18F26K22 has much more memory space, and I will be able to finish some screens I had left behind, due to memory size of the F2550.

Regards.
Ttelmah



Joined: 11 Mar 2010
Posts: 19221

View user's profile Send private message

PostPosted: Fri Dec 10, 2021 7:14 am     Reply with quote

Get rid of your code writing to the SSP registers.
The setting you are trying to use takes the SPI port outside it's limitations.
Generally in CCS, you should pretty much never write directly to registers.
Doing so is an easy way to make mistakes.

One key thing I have not seen you doing, is setting the slew rate, On this
later chip, you need to disable the slew rate limitation or it won't be able
to clock at the fast rates.

set_slow_slew_c(FALSE);

Slew rate limiting defaults to 'on', and limits the maximum clock rate
on the SCK pin to under 2MHz.
rudy



Joined: 27 Apr 2008
Posts: 167

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

PostPosted: Fri Dec 10, 2021 7:52 am     Reply with quote

No change!

The only things that makes SPI goes at reasonably speed are:

Code:
SSP1CON1=0X30;
SP1STAT=0X40;


Without these lines, it goes slower!

I will rewrite all my code anyway, so I have plenty on time to try to make it goes faster!

Regards;
temtronic



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

View user's profile Send private message

PostPosted: Fri Dec 10, 2021 9:40 am     Reply with quote

As Mr. T says, use the CCS functions not directly writing to registers.
I suspect the old compiler version 'might' be putting the wrong data into the registers. Dumping the listing would confirm/deny this. filename.lst is the listing, the actual code generated by your program.
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 Previous  1, 2, 3  Next
Page 2 of 3

 
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