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

Write file of data to PIC

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



Joined: 30 Dec 2010
Posts: 2

View user's profile Send private message

Write file of data to PIC
PostPosted: Thu Dec 30, 2010 4:56 pm     Reply with quote

First I am new to this so please be gentle. I am using a PIC 16F876 with a 20MHz oscillator. I am attempting to write a large chunk of data to my PIC. I have approximately 12k samples saved in a .txt file but I can convert it to a .bin. My plan is to save the 12k bytes into program memory and use it from there, but I am unsure how to write the data to my PIC. I know I need to use the RS232 interface and the getc function but I am unsure what program to use to communicate between my PC and the PIC. Any help would be greatly appreciated thanks Smile
temtronic



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

View user's profile Send private message

PostPosted: Thu Dec 30, 2010 8:29 pm     Reply with quote

Obviously you need some kind of 'terminal' software to download your file to the PIC. Two choices, canned software or do-it-yourself.
The easy way to most is #1
#1: While Hyperterminal is not the best, it will do the job (I used it for 4 years downloading Dominos), you might want to check out RealTerm or others.
#2: Perhaps a challenge at first, but a great learning experience, is to cut the terminal code yourself. C#, VB, or Delphi will all work. I still use Quickbasic 4.5 today as it interfaces to real interrupts under Dos based platforms using real comports. This feature is critical in my aps and NOT available under Windows (unless you access ring0).

Start easy, make a loopback connector, install a terminal program and experiment, get comfortable with the commands and structures.
Then write a simple PIC program to echo data received back to the PC.

After that you can build up from there to 'stuff' the PIC with your 12KB txt file.
wireless



Joined: 02 Nov 2003
Posts: 16
Location: London England

View user's profile Send private message

Writing to PIC
PostPosted: Fri Dec 31, 2010 3:54 am     Reply with quote

You need to study the PIC family data sheets, the 16F876 does not sound suitable for your application. You suggest writing your "data" to the program memory but this is not possible to write to program memory from within a program with this part. Also, it only has 8k of 14 bit words of program space which even with your data converted to bin which would be a very much simpler solutionary is unlikely to be enough space for the data and the program.

Suggest you look at the PIC18F family as these can write to program memory or you might even find one with enough internal RAM to store your data.

Regards

Terry
_________________
"An engineer is someone, who can do for 5 bob, what any dam fool can do for 10. " - Hon C S Royce Joint Founder of Rolls Royce.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Fri Dec 31, 2010 4:53 am     Reply with quote

A lot more basic thinking and some data is needed:
1) What do you want to do with the data, once it is in the PIC?.
2) How often is this going to be updated?.
3) What is the format of the 'text'?.
4) How big are the 'samples'.

Now, starting with the '4'. If the data is just numbers say, separated by perhaps commas, or line feeds, then it is actually _easier_ to send this (though taking more time), rather than binary data!. Reason is that in text form, the commas, or line feeds, provide some basic 'knowledge' for the PIC of where each number starts/stops, and simple off the shelf functions can turn the numbers into values.

This then links to '4'. If the samples are 'bytes', then obviously you are talking about 12KB of storage needed in the end. The 16F876, even if you used all it's program memory, could only just hold this much, and in a _very_ inconvenient format. It has 8192 'words' of program memory, with each word holding 14bits. So if the data is bytes, you would have to split them into odd sized lumps to store them into this memory space. Means the program gets larger, and less space is left to hold the data. I _doubt_ if it is really possible to hold this data and the program in the internal memory of the PIC. If the data is larger than 'bytes', then this is definately true....

Two suggestions then arise:
1) Switch to a PIC with larger memory space - PIC 18 family, not only have more locations, but the locations themselves are bigger.
2) Add an external memory. A I2C FRAM for example could hold this data easily, with fast writing and reading, and avoids the potential problem in '2'.
Now '2'. The PIC has a limited _life_ for the write cycles on it's program memory. Not a problem for something changed at a few month intervals, like program code, and even when developing, the total cycles hopefully will be fairly low. But, anything that is written at all frequently, should _not_ be written to the program memory. It is also worth realising that writing to program memory, is quite slow, and the processor has to completely 'stop', while the write takes place. On the 876, the warranted 'life' is just 1000 cycles, and a write can take up to 8mSec to complete. When you realise that you could write a byte to the FRAM suggestion, even using slow communications in under 80uSec. Use the SPI version instead, and raise the speed, and the advantage gets even larger. Also the life is basically infinite, which may help to make this the much better route.

Then we come to '1'. It is just about as easy to read from an external memory, as from the program memory. If the data needed to be stored in the 14bit chunks to fit it into program memory, then it becomes several orders of magnitude _easier_ to read from the external memory...

You need to specify your design, before worrying about the code.

Best Wishes
Walped



Joined: 30 Dec 2010
Posts: 2

View user's profile Send private message

PostPosted: Fri Dec 31, 2010 2:25 pm     Reply with quote

Thank you for your replies this is very helpful.
@Ttelmah
Once I have the data on the pick I want to use it to do an audio play back using PWM. I have taken the .wav file of the sound sample I want to play and have removed the header. The sample plays at 8000Hz and has 8bits per sample and is about 1.5 seconds long so about 12k samples. Once I have the sample data on the PIC and I am able to play back I do not plan on updating it often if ever. Currently I have the data in a text file each sample separated by line feeds. Finally the samples are, as mentioned before, 8 bits each. I was hoping to save it onto the PIC first and play it back then later add some external memory and play with that but after looking at the data sheet again as mentioned there is not enough space to put it all in program memory, it does seem to make more sense to start with some external memory. I guess my final question then is what program do I use to write my data to the external memory? Thanks again for the help!
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