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

Max speed SPI Software 16f628
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
vtrx



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

Max speed SPI Software 16f628
PostPosted: Sat Jul 10, 2021 5:25 pm     Reply with quote

what is the maximum speed that is possible with 4MHZ using the 16f628a?
Code:
#use SPI(DO=PIN_A0,DI=PIN_A3,CLK=PIN_A2,MODE=0,BAUD =400000,BITS=16,msb_first,SAMPLE_RISE)


Can the speed setup above be more than 400khz?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jul 10, 2021 6:39 pm     Reply with quote

The 16F628 doesn't have a hardware MSSP module, so SPI must be
done in software. A 4 MHz crystal gives an instruction clock of 1 MHz.

Using the test program shown below in MPLAB vs. 8.92, and the
Stopwatch feature, I got 296 instruction cycles to send 16 bits.
That's 296 uSec. 296/16 gives 18.5 uSec per bit. That gives
about 54 KHz as the maximum effective bit frequency. The real
bit frequency will be faster than that, because there are some
cycles used in overhead.

Test program:
Code:
#include <16F628.h>
#fuses XT
#use delay(clock=4M)

#use SPI(DO=PIN_A0,DI=PIN_A3,CLK=PIN_A2,MODE=0, BAUD=400000,BITS=16,msb_first,SAMPLE_RISE)

//==========================
void main()
{
int16 data;

spi_xfer(data);

while(TRUE);
}
vtrx



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 6:08 am     Reply with quote

using 20mhz I can set the uart with 270khz, right?

Code:
#use SPI(DO=PIN_A0,DI=PIN_A3,CLK=PIN_A2,MODE=0,BAUD =270000,BITS=16,msb_first,SAMPLE_RISE)
temtronic



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

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 6:17 am     Reply with quote

yes, X5 clock = X5 SPI speed BUT...
be sure to use xtal/2caps for clock, to get accurate, consistant speed
also since this is a SOFTWARE SPI, nothing else can be done while SPI is being used...
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 7:51 am     Reply with quote

No 'uart' involved for SPI. You can get an SPI clock rate of 270KHz at 20Mhz.
The 'A' in the word UART, means 'asynchronous'. The whole point of SPI
is it is a synchronous interface.
temtronic



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

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 8:17 am     Reply with quote

an observation....
You may want to consider a 'pin compatible' PIC that has builtin hardware SSP peripheral. While the software SPI will work, depending on application, it does cost you code space. That PIC only has 2K, so it might be interesting to see how much space IS taken to do software SPI.
As the 628 is an 'older' PIC, odds are pretty good a newer one will have more memory, HW SPI and cost less.
Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 8:34 am     Reply with quote

16F1847 and it's cheaper too. It requires Pickit 3 to program it.

Last edited by PCM programmer on Sun Jul 11, 2021 8:35 am; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 8:35 am     Reply with quote

Absolutely.
The PIC16F18444, is the direct modern replacement for the 628A.
Has hardware SPI, up to 32MHz from the internal clock, and up to 28K of
ROM. It's also about half the price!....
It also supports PPS, so you can move the peripherals to where you want
them.
vtrx



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 11:28 am     Reply with quote

I'm actually going to use 16f648.
The value of this micro on aliexpress, where I buy it, is cheaper than the 16f1847.
The PIC will only receive serial data and write to an 8x8 matrix (15 Cis MAX).
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 12:16 pm     Reply with quote

Seriously still only gives a 4HHz internal oscillator. Adding a crystal to
give 20MHz, costs more than the 16F1847. This gives 32MHz on the internal
oscillator, and has hardware SPI.
temtronic



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

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 2:03 pm     Reply with quote

It sounds like he's using the PIC to send data to an SPI based 8x8 LED matrix display module. If so, he really doesn't need high speed SPI. Anything faster than say 50Hz will make the LEDs appear to be stable.
A lot would depend on the actual LED module being used, something we don't know.
vtrx



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 4:26 pm     Reply with quote

8x8 matrix (MAX7912),15 modules.
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Jul 11, 2021 11:56 pm     Reply with quote

Thing is that if you are daisy chaining 15 of these modules, you potentially
have 120 characters needing to be stored in the PIC. The actual data
stream needed to be sent to the display for an update is another 30 bytes.
Doesn't allow for much spare RAM in a PIC16F648. Then there will need
to be something like serial data being decoded to actually generate what
is to be sent to the display. Suddenly you are running out of space....
It is a waste of effort, trying to fit code into a smaller PIC. Seriously, using
the 1847, will give you smaller code that is easier to write, and runs a
lot faster, and enough room to actually work in.
The very start of this thread was hoe fast the SPI could be driven, implying
that the poster thinks speed is important. A 1847 at (say) 16MHz, can
generate a SPI stream running over seventy times faster than the 628/648,
and gives space to actually do the work to generate this.
temtronic



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

View user's profile Send private message

PostPosted: Mon Jul 12, 2021 4:55 am     Reply with quote

Points to ponder,while coffeee's being made..

1) given 15 modules, in series...(15 x 15= 240 bits of data.30 bytes of data..)
@the refresh rate of 800Hz(typ in the datasheet),the refresh rate for the chain would be 12,000Hz( 15x 800) ?

2) with 15 module, 330ms per module(spec sheet..) you'll need a solid 5 AMP power supply JUST for the LEDS ! 'Old skool' says to double that for long ter reliablility.

3) data input ,serial (UART) baudrate. will have to be faster than the 'update LED' rate,say a factor of x2, to allow for buffering,parsing,SPI straming.
vtrx



Joined: 11 Oct 2017
Posts: 142

View user's profile Send private message

PostPosted: Mon Jul 12, 2021 8:35 am     Reply with quote

I'm at work now, at night and post the full code, using the 16f628a, to show a fifteen letter word received by the UART(9.600), which is sent by a 18f2550 by USB HID.
It works very well.
The code contains the ASCII table, copied from Arduino, and the value received by the serial is calculated by the ASCII value to be found in the table.
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