Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

method for getting current time and setting a time in uc

Status
Not open for further replies.

varunme

Advanced Member level 3
Joined
Aug 10, 2011
Messages
741
Helped
17
Reputation
36
Reaction score
17
Trophy points
1,318
Activity points
5,764
what are the methods for determining current time and setting a time period in a microcontroller ?
 

Hi,

Its called a RTC - Real Time Clock.

They can be external devices, software based or many of the newer micros have a RTC built in.

Cannot give anything more specific as you do not give any detail.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
If you want to use a micro with in built RTC you can look here
http://www.atmel.com/dyn/resources/prod_documents/doc1259.pdf
This application note describes how to implement a Real Time Clock (RTC) on
AVR® microcontrollers that features the RTC module. The implementation requires
only one discrete component – a 32.768 kHz watch crystal.

If you want to use external RTC, then you may use DS1307(without battery backup) or DS12887+(with inbuilt Li battery but costly!)
 
Last edited:
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
This example shows how to get time values from real time register on STM32:
Code:
void CalculateTime2(void)
{
  u32 TimeVar;
  
  TimeVar=RTC_GetCounter();
  TimeVar=TimeVar % 86400;
  a_TimeStructVar.Hour=(u8)(TimeVar/3600);
  a_TimeStructVar.Min=(u8)((TimeVar%3600)/60);
  a_TimeStructVar.Sec=(u8)((TimeVar%3600)%60);
}
As you can see, STM32 using one 32-bit length register to store the time and one the same for calender. This routine calculate the real values from bcd-coded 32-bit register value. Hope it helps a little.
On 8-bit micro controllers i'm using few independent byte variables, organized in structure. Like this:
Code:
struct DateAndTime
{
  char Sec;
  char Min;
  char Hour;
  char Day;
  char Month;
  char year;
};
This six 8-bit unsigned variables stores date and time for the real time clock module, based on PIC18F Timer1 timer with external 32768 oscillator.
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
I am using PIC microcontroller
to build an interrupt which control an LED in traffic light using pwm
which adjust its brightness according to time ( peak time and offtime )

is it fairly simple to interface RTC with picmicro ?
 

DS1307 has I2C interface, and if you are using PIC with I2C support then interfacing is simple.
 
Last edited:

Mr. Easyrider83 is right!

It will be better to use light sensor (LDR or photo trinsistor, CDS etc) for traffic light. Apart from evening time the ambient light may get reduced due to cloud, heavy rain or Solar eclipse etc. They are small, inexpensive, low-power, easy to use and don't wear out. You are requested to please check : How to use photocells, LDRs, CdS cells, photoresistors!
 

11am to 2.30pm is offtime , that can create problems
 

11am to 2.30pm is offtime , that can create problems

Hi,

From your previous posts it seems you are using a 4550 and C.

The two choices you have are an external RTC like the 1307 and associate parts, which also adds day, date and alarms etc. or go for a simpler software RTC based on a 32khz xtal connected to Timer1 input.

The advantage of the 1307 chips is that they have a battery backup so power outages are not a problem.

Plenty of examples of both around
 

You didn't clearly tell, if your problems are mainly to have a clock (e.g. a RTC chip) or how to deal with time quantities in C library functions? Without using existing C libraries, it's often a resonable way to keep time of day as an integer number (e.g. minutes or seconds since midnight). You don't necessarily need a RTC chip as long as time keeping during power loss isn't an issue. Obviously, daytime related comparisons are much simpler by using an integer time representation instead of hour/minute/seconds. Date and time library functions are usually providing both formats and conversions betwen them.
 

yes FVM ,
problem is to deal with the time quantities, how to store this into a variable and how to save them .
 

Time quantities with separate hour/minute/seconds representation are usually stored in structures. If you are using existing library time and date function, you need to refer to the defined data types, otherwise you'r free to define your own. As said, I prefer integer quantities for time, e.g. timeofday as a 16 bit unsigned integer with the LSB representing 2 seconds.
 

and i have to save the time to external eeprom incase if it has to be used daily ?
Anybody having experience on the below board ?

**broken link removed** ?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top