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

Date and Time stamping!!!!

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







Date and Time stamping!!!!
PostPosted: Thu Oct 06, 2005 6:31 pm     Reply with quote

Hi everyone,

i am interested in date and time stamping (i.e including the current time and date) my data string before storing it into external memory. i am using 16f877a mcu. is this sort of a thing possible. if so, how ?

Take care

Best regards
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Thu Oct 06, 2005 6:53 pm     Reply with quote

Try searching the forum:
http://www.ccsinfo.com/forum/viewtopic.php?t=23945&highlight=date
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Thu Oct 06, 2005 7:02 pm     Reply with quote

In a general case, you'll need a surce of date and time for this such as real time clock (RTC, e.g. DS1307) or a GPS receiver.
ambivalent
Guest







information about RTC
PostPosted: Thu Oct 06, 2005 7:30 pm     Reply with quote

Hi everyone!

i have searched the following forum for my date and time stamping problem:


http://www.ccsinfo.com/forum/viewtopic.php?t=23945&highlight=date

however the command printf(__DATE__) gives the date at the compile time, which in my case is no good as i need the date and time update constantly with out having to burn the code again and again.

I guess i would need to use real time clock (RTC, e.g. DS1307) as kender suggested. does ne one have any idea about interfacing this RTC to the 16f877a, how much would it cost me to purchase this RTC hardware

Take care

Best Regards
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Thu Oct 06, 2005 8:21 pm     Reply with quote

You can use either a RTC (that will need a lithium back-up battery) or implement a firmware clock.

RTC:
$3.75 for the IC
$4.50 for the battery

Holds time after power down.
Driver available on this forum.

Firmware Clock:
Free
Must set after each power-up.
Must write your own code.


I've done both. I will always use a RTC from now on. You have to decide what's important to you.

Good luck,

John
ambivalent
Guest







RTC IC!!
PostPosted: Thu Oct 06, 2005 10:23 pm     Reply with quote

Hi everyone

john thankyou for your reply. i believe that the RTC IC option will be the most feasible in my case as i do need the and date to be updated constantly without reprogramming the controller.

can you plz tell me the IC no for which the drivers are available, and also from where these drivers can be found.

and also is the 'date' feature also included in the RTC IC or not?

thankyou very much

Best Regards
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Fri Oct 07, 2005 1:00 am     Reply with quote

First:

Do you have any other peripherals that you need to incorporate? Do they require I2C or SPI? If so, that will help decide which RTC you want to use.

The DS1307 is I2C and I believe the DS1302 is SPI.

Go to the following web page:

http://para.maxim-ic.com/ss.asp?Fam=RTC&Tree=Timers&HP=Timers.cfm&ln=

Check the appropriate boxes (the BUS type is the most relevant).

When trying to find drivers look in your c:/program files/PICC/drivers for an appropriate driver. If that doesn't work, come to this forum and search. I used "ds1307 driver" and received this as one possibility:

http://www.ccsinfo.com/forum/viewtopic.php?t=23255&highlight=ds1307+driver

As always, when using a new component, read the datasheet and make sure you understand what's involved. The 1302 and 1307 are similar but different. One can recharge a b/u battery the other can't.

Yes, most any RTC will support dates. And a variety of other nifty features.... alarms, etc.....

Good luck,

John
ambivalent
Guest







RTC ic!!
PostPosted: Fri Oct 07, 2005 2:15 am     Reply with quote

hi
thankyou john for your reply.

can you plz clarify some things as i am new to this field of microcontrollers. what is the significance of I2C or SPI. Another thing is that if i chose ds1307 than what about its power source. Does it need a rechargable battery or does it require +5v from the same source as the microcontroller.

Hope you can help!
Best regards
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Fri Oct 07, 2005 8:53 am     Reply with quote

I2C and SPI are serial communication schemes that are popular in embedded systems. They are relevant in your choice of a specific RTC because you would normally want to stick with one scheme throughout your design for simplicity's sake.

So, if you have any other hardware peripheral requirements, EEPROM, digital pots, etc. you may want to look into what is available. Sticking with a single type will simplify things and reduce the pin count of your MCU. But, if all else fails both SPI and I2C can be implemented simultaneously (if I'm not mistaken.)

If you are going to be logging data you will need some sort of external memory for the data. How much, how fast will, for what cost will help you decide that. Provide details and many expert members of this forum will provide all sorts of ideas.

The power to the RTC must be "un-interruptable" to allow it continue to run when power is removed from the MCU. So, there is typically a coin cell that provides the few uA required for the RTC to continue to run. Depending on the RTC, that may be a rechargeable cell or not. But, that comes later in the decision process.
Quote:

Does it need a rechargable battery or does it require +5v from the same source as the microcontroller.

If you removed power from the MCU what would happen to the RTC?

The DS1307 can use eiher a rechargeable b/u or a primary b/u, but that's where reading the datasheet comes in.

The most important thing you can do now is share some details with the forum so they can help you make the decisions you need to make. The experience here is astounding and the willingness to help is even more. Just open up and let them help.

Good luck,

John
ckielstra



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

View user's profile Send private message

PostPosted: Fri Oct 07, 2005 9:40 am     Reply with quote

Quote:
But, if all else fails both SPI and I2C can be implemented simultaneously (if I'm not mistaken.)
Yes, you can have both but with serious limitations. One uses the inbuilt hardware support while the other is a software implementation. Please note that SPI is much easier to implement in software than I2C, so when choosing to use both make sure that I2C is the one supported by hardware. Also the software implementation won't be able to generate interrupts and polling the data lines will require a lot of available clock cycles. Better to choose wise and stick to either SPI or I2C.

- SPI requires more I/O pins than I2C.
SPI uses 3 data wires plus an additional wire for each chip select, for example with 3 devices on the bus you'll need 3 + 3*1 = 6 I/O pins. I2C only uses 2 data wires, no matter how many chips you connect to the bus.

+ SPI is faster than I2C.
In SPI the maximum data transfer rate is only limited by the speed of the connected devices. Practical limit is the clock speed of the PIC, generating clock pulses at Fosc/4, or with a 4MHz clock you achieve a 1MHz maximum SPI rate. For I2C there are 2 defined speeds, 100kHz or 400kHz. Also the protocol for I2C introduces a lot of overhead reducing the data rate further.

+ SPI is easier to implement
The SPI protocol is easier than the I2C protocol (just a chip select line i.s.o. addresses and no potential data collisions). This is however a minor advantage as most problems are handled by the hardware support for I2C in the PIC processors and many driver examples can be dowloaded.

As John already wrote, base your decision on the availability of the devices you need for both bus types.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Fri Oct 07, 2005 2:45 pm     Reply with quote

I personally always make an oposite choice:
ckielstra wrote:
Yes, you can have both but with serious limitations. One uses the inbuilt hardware support while the other is a software implementation. Please note that SPI is much easier to implement in software than I2C, so when choosing to use both make sure that I2C is the one supported by hardware.

I agree that it's better to have only one bus in the system, but I usualyl make an oposite choice of software vs. hardware support. Software I2C is supported by the CCS compiler, so I don't need to write the bit-banging code for the I2C. I can simply use #use i2c(...) directive. Conversely SPI is typically ised as a migh-speed bus, and therefore it needs hardware support.
Ttelmah
Guest







PostPosted: Fri Oct 07, 2005 2:50 pm     Reply with quote

I agree.
However it does of course depend on which way you want to transfer data. A software I2C 'slave', can be done, but is _very_ hard indeed, and is not a standard implementation. The 'master' conversely, is very easy to code, and even easier if the library is available. On SPI, the same is true. The master is relatively easy to code either with software or hardware, but the slave is actually hard with either (the SPI slave implementation in the PIC, is to my mind very poor).

Best Wishes
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