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

problem with 18F4550 clock speed
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
probeoil



Joined: 02 Apr 2013
Posts: 20
Location: greece

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 8:15 am     Reply with quote

Quote:
Don't confuse MIPS and MHz. The PIC processor needs 4 clock cycles to execute 1 instruction. So, as Ttelmah already pointed out, when running at 48MHz the processor can execute 12 instructions every us.

You are right about the MIPS, I will use hardware SPI, with a parallel ADC to get top speed.
I don't want video speed from the CCD, just enough speed to read it.
Most CCD have minimum output frequency 1MHz.

Thank you everyone for the help.
ckielstra



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

View user's profile Send private message

PostPosted: Sat Apr 20, 2013 4:12 am     Reply with quote

Reading my post again I think I wasn't very clear on the point I was trying to make:
Be sure to choose the right tools for the job at hand!

The PIC is (barely) capable of reading the CCD at your desired speed, but what is to happen next with the read data could be a problem. The PIC18F4550 only has 2048 bytes of SRAM and that is most likely way too small for your application.
I assume you you want to forward the CCD data over USB? Forget it! This is not going to happen while reading data at the same time over SPI at 2MByte/s. The PIC at 48MHz is just way too slow for that.

Without knowing more details over your project I can't give advice, but my gut feeling is that you would be much better helped by another hardware platform. I do like the PIC but it has its limitations.
Just as an example, the Raspberry Pi board at $25 contains an ARM processor at 700MHz that will run circles around any PIC18.
probeoil



Joined: 02 Apr 2013
Posts: 20
Location: greece

View user's profile Send private message

PostPosted: Sun Apr 21, 2013 7:57 am     Reply with quote

Thank you everyone,

After a three hour reading i understand why it can't go faster.
I will change my design
Ttelmah



Joined: 11 Mar 2010
Posts: 19569

View user's profile Send private message

PostPosted: Sun Apr 21, 2013 9:32 am     Reply with quote

You can go a little faster by using fast_io.

Currently 'output_high', and 'output_low', will execute two machine operations. First set the tris to output on the bit, then output the value. Then the loop itself always takes two instruction times.
With fast_io, you set the directions you want yourself _once_, and then they are not changed when you access a pin. About 33% increase in the maximum speed for the loop. Smile

Best Wishes
probeoil



Joined: 02 Apr 2013
Posts: 20
Location: greece

View user's profile Send private message

PostPosted: Sun Apr 21, 2013 10:04 am     Reply with quote

Nice Ttelmah , i'll try it tomorrow
probeoil



Joined: 02 Apr 2013
Posts: 20
Location: greece

View user's profile Send private message

PostPosted: Mon Apr 22, 2013 2:43 am     Reply with quote

FAST_IO doubled the speed of the commands, thanks guys
probeoil



Joined: 02 Apr 2013
Posts: 20
Location: greece

View user's profile Send private message

PostPosted: Mon Apr 22, 2013 2:57 am     Reply with quote

I need some more of your precious help..
I want to program a hardware SPI for 16 bits frame, I'm using a 12-bit ADC
which has 4-bit leading zeros and 12-bit data.

Any example or tutorial you can point out will be useful

Thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19569

View user's profile Send private message

PostPosted: Mon Apr 22, 2013 4:10 am     Reply with quote

#1 Just send as two bytes.
Code:

int16 rval send_16(int16 val_to_send)
{
   int8 reply[2];
   reply[1]=spi_write(make8(val_to_send,1)); //MSB first
   reply[0]=spi_write(make8(val_to_send,0));
   return(make16(reply[1],reply[0]));
}

#2 use the #use SPI method
Code:

#USE SPI(MASTER,SPI1,STREAM=HWSPI)
   
   int16 reply;

   reply=spi_xfer(HWSPI,val_to_send,16);


Both are just about equally quick.
The hardware itself can't do 16bit transfers (except on some of the DsPIC's). Understand that it doesn't actually matter if there is a pause between the bytes (since SPI includes it's own clock).
On current compilers, #2 works well, and gives compact easy to understand code.

Best Wishes
probeoil



Joined: 02 Apr 2013
Posts: 20
Location: greece

View user's profile Send private message

PostPosted: Mon Apr 22, 2013 5:12 am     Reply with quote

Quote:
#1 Just send as two bytes.

Code:

int16 rval send_16(int16 val_to_send)
{
int8 reply[2];
reply[1]=spi_write(make8(val_to_send,1)); //MSB first
reply[0]=spi_write(make8(val_to_send,0));
return(make16(reply[1],reply[0]));
}


#2 use the #use SPI method

Code:

#USE SPI(MASTER,SPI1,STREAM=HWSPI)

int16 reply;

reply=spi_xfer(HWSPI,val_to_send,16);



Both are just about equally quick.
The hardware itself can't do 16bit transfers (except on some of the DsPIC's). Understand that it doesn't actually matter if there is a pause between the bytes (since SPI includes it's own clock).
On current compilers, #2 works well, and gives compact easy to understand code.



thank you Ttelmah,
I'm trying out the first program, although I get an error at spi_write(), the
error says a numeric expression must appear here.
The #2 is software spi and it's too slow..

to use the hardware SPI I have to use the spi pins of PIC?

Code:
int16 rval send_16(int16 val_to_send)
{
   int8 reply[2];
   reply[1]=spi_write(make8(val_to_send,1)); //MSB first
   reply[0]=spi_write(make8(val_to_send,0));
   return(make16(reply[1],reply[0]));
}
[quote]

many thanks[/quote]
temtronic



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

View user's profile Send private message

PostPosted: Mon Apr 22, 2013 5:57 am     Reply with quote

Yes, to use any internal 'hardware' device(SPI, UART,etc) to access fastest speeds, interrupts, etc. you need to use the designated I/O pins.
hth
jay
probeoil



Joined: 02 Apr 2013
Posts: 20
Location: greece

View user's profile Send private message

PostPosted: Mon Apr 22, 2013 6:33 am     Reply with quote

I'm screwed, I'm stuck with software spi.

With a parallel ADC i'll get 700KHz

it's enough for a CMOS but it won't do it for CCD

Thank you lads you have been very helpful
Best wishes
Ttelmah



Joined: 11 Mar 2010
Posts: 19569

View user's profile Send private message

PostPosted: Mon Apr 22, 2013 7:23 am     Reply with quote

Can I suggest you look at the 18F46J50, instead of the 4550?.

Downside - it is 3.3v, and you have to supply Vusb.
Plus-side - on this there is a second hardware SPI (and quite a few other peripherals as well), which can be re-mapped to different pins.
Other than these peripherals it is pin compatible for the 4550.
It also has twice as much ROM, and nearly twice as much RAM.

Best Wishes
probeoil



Joined: 02 Apr 2013
Posts: 20
Location: greece

View user's profile Send private message

PostPosted: Thu Apr 25, 2013 2:07 pm     Reply with quote

Hi guys,

I will need your wisdom on something.
I decided to change the mcu to something faster,
I'm looking for a microcontroller with 24 MIPS, at least 30 i/o
for general use, usb compatible.All that on a board with usb connector,
a crystal for clock and a steady power supply circuit.

At a price 40-70$

Any ideas are will be useful

Thanks
temtronic



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

View user's profile Send private message

PostPosted: Thu Apr 25, 2013 2:27 pm     Reply with quote

one tip I can offer.

After using the 4550 for about a year, I gave up and bought a silly $3 ttl-usb module.
With all the USB driver/connection/etc. 'offloaded' to the module, it greatly simplified both hardware and software design.It freed up about 1/3 of the 4550 memory(no usb drivers !) and since it has connector onboard, saved a few pennies as well as an 'off the shelf' solution.

Ok, $3 for the module might be costly BUT I've saved a LOT of R&D time($$$$) and it's a 'universal' solution..so projects are not PIC type dependent.

fwiw

jay
probeoil



Joined: 02 Apr 2013
Posts: 20
Location: greece

View user's profile Send private message

PostPosted: Fri Apr 26, 2013 4:49 am     Reply with quote

Hi !!
what is your appinion about the PIC32MX795F512 processor
I found a board that has what i need

http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,892,894&Prod=CHIPKIT-MAX32

my conserne is that the have a 8MHz crystal on it, will it reduce the maximum speed?
I can't find the CPU speed in respect to the crystal source.
Although i don't think it would reduce speed, it's like puting wooden wheels on a sports car..
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