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.

help with real time clock

Status
Not open for further replies.

shaneelal

Member level 1
Joined
Nov 16, 2004
Messages
38
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
553
pic 18 sspadd with 40 mhz

I don't know much about real time clocks.I'm using it in a project along with a PIC18f452. The device will continuously sense a measurement and have it stored, the real time clock should send an interrupt to the PIC every 2 seconds. When the interrupt occurs,the PIC should transmit the measurement using rs232.
What is the simplist way to have this interrupt occur. I"m using mc18 compilier. I'm also not sure how to transmit when the interrupt occurs. Any help will be appreciated.
 

i2c c18 rtc 400 mhz

For this application PIC can generate 2 second interval by itself using internal timer but if you would like to use external RTC you can use DS1307/1377 from Maxim.
( **broken link removed** )
This device can generate interrupts every second so you will need to count to 2 for 2 second interrupt.
On interrupt you will need to take data from PICs memeory and send it out through RS-232 driver ..
 

16f87 timer0 interrupt

Hi,

RTC DS1302 from MAXIM/Dallas is good too and Philips I2C PCF8583.
 

c18 readi2c

philips PCF8593 is better.
another way use microcontroller with crystal 32768
you can use PIC16F84A or 89C2051.
for more information goto:
**broken link removed**
 

rtc ds1307 adjust time

Could you tell me in detail how the PIC can interrupt itself every 2 seconds. Other things have to be continiously be going on till the interrupt occurs. When the interrupt occurs, the pic will transmit the last stored value,which is desired to be transmitted. I'm using timer0 and timer1 to perform operations in my code.
 

delay function using rtc

Use the timer/counter register of PIC and there will be an interrupt every overflow.
 
  • Like
Reactions: MEPLA_F

    MEPLA_F

    Points: 2
    Helpful Answer Positive Rating
pcf8583 18f

hi,
to get a 1 sec interrupt.. for ur 18F452 ( the operating freq is 40Mhz rite ? )
if that the case.. using timer1 which is 16 bits, an overflow will take 6.5ms with a prescalar of 1. this u can use a register to keep on looping for ard 153 time.. Each overflow will cuz an interrupt.. so when it counts up to 153 time.. then will do the stuff u want. if u want a 2 sec interrupt, loop for 2*153 time.

1/ (2^16 * 100n ) =153

hpe it helps

Added after 2 minutes:

oh yes, remember to keep ur interrupt service routine as short as possible..
preferrably, in the ISR only clear ur interrupt flag n decrement the count..
 

i2c ssp ds1307 slave

hi,

U can use Dallas DS3107 RTC. It can be configured for outputing 1hz square wave on one of its pins. It works on I2C protocol. U can give this saure wave 2 either timer or any interrupt pin on PIC. In ISR u can check for 2 sec by using simple variable. If two seconds r ovr then u can initiate the serial transfer.

If u r using RTC just to get 1Sec interrupt and it has no other function, and if Timer1 OSC pins of ur PIC18F452 r free.then u can connect 32.678Khz crystal at Timer1 OSC pins (same way we use crystal for master osc., but with 20PF cap).
and loading timer1 with 0x8000 will give u interrupt on every 1sec. This u may elliminate ur RTC also.

Configure tIMER 1 FOR external OSC source.
Best Regards.
 

ds1302 using 16mhz

Hi.. I have some trouble with DS1307.. I built a clock and I write software to read from DS1307 about every second... I found that time is not correct when operate about one day.. time will slower about 1 minute.. I think because I read from DS1307 every second.. IF I read it every hour it works better.. But I need to display clock every second.. Any sugest for algorithym or any way to make it more precise
 

generating 1 second timer interupt on 40mhz pic

hope u made design not with many resistor or high values,for power saving.second point is for timing.
if its so necessary may be a trick would work? :wink:
 

how to say real time clock in arabic

Hi.. I have some trouble with DS1307.. I built a clock and I write software to read from DS1307 about every second... I found that time is not correct when operate about one day.. time will slower about 1 minute.. I think because I read from DS1307 every second.. IF I read it every hour it works better.. But I need to display clock every second.. Any sugest for algorithym or any way to make it more precise

That is due to the accuracy of the RTC IC, I have a similar problem with a PCF 8583 RTC, you could put a trimmer in the circuit (between one of the OCS pins and +ve) and manually adjust it, I am looking into better solutions at the moment, one of which is to use a Dallas DS32KHz TCXO to replace the crystal timer reference.

Back to the original problem, unless the interval has to be EXACTLY 2 seconds, i.e. not 1.99 or 2.05 etc then I wouldnt use an external clock source, but use one of the timers on the PIC.
During the 2 second "wait" between sending the info, does your program need to be doing anything else? or just waiting? if just waiting, then you dont need to use an interrupt, just a 2 second time delay.


I dont know the 18F series, but heres some 16F code to provide a 2 second delay (assuming 40Mhz for you PIC)

Code:
; Delay = 2 seconds
; Clock frequency = 40 MHz

; Actual delay = 2 seconds = 20000000 cycles
; Error = 0 %

	cblock
	d1
	d2
	d3
	endc

			;19999999 cycles
	movlw	0xB6
	movwf	d1
	movlw	0x99
	movwf	d2
	movlw	0x2C
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

			;1 cycle
	nop

I got that from HERE

If the PIC wont be idle during the 2 seconds, you will need to use an interrupt and increase a counter/counters on every interrupt until the counters have clocked the 2 seconds, I have to hand some INT code for 16F which will clock an LED (or whatever) at approx 500 ms if thats any use I can post it.

Regards
 

timer1 1sec int external 32.768 real-time clock

I'm building a device which measures wirespeed.I'm using the output of a shaft encoder as input of pulses for PIC.I'm using timer0 to time 100 pulses. Timer1 will be counting the pulses.The speed will then be calculated.I am to transmit this speed every 2 seconds.The wirespeed measurement should be ongoing only stopping to transmit the wirespeed. I don't know how I can use another timer to create an interrupt every 2 seconds and still keep timming 100 pulses and calculating speed.

I"m using the M41ST85Y real time clock. I just want to recieve an interrupt from this clock every 2 seconds. I"m having alot of trouble understanding the c code to do that task.I'm using mplab c18 compiler.
All I have so far is this

Code:
//configure I2C
OpenI2C(MASTER, SLEW_OFF);
	SSPADD = 9; //400kHz Baud clock(9) @16MHz
	                    //100kHz Baud clock(39) @16MHz

I got that from the c-18 libraries,I changed SLEW_ON to SLEW_OFF cause of what I saw on pg151 of 18f452 manual
Code:
"Note 1: The I2C interface does not conform to the 400 kHz I2C specification (which applies to rates greater than100 kHz) in all details, but may be used with care where higher rates are required by the application."
Also from the manual on page 134,has info on SSPADD.I'm not sure how to configure it.
Code:
"SSPADD register holds the slave device address
when the SSP is configured in I2C Slave mode. When
the SSP is configured in Master mode, the lower
seven bits of SSPADD act as the baud rate generator
reload value."
I"m using a 4Mhz clock for my 18f452.

Do I have to give the real time clock an address? If so how do I do it?
I was thinking about using the Function EEByteWrite in c-18 to write to the rtc to interrupt every two seconds.
If someone could help me out with this code I would be very grateful.
I've attached some pages from the real time clock spec sheet.
If there is anything anyone is confused about,please say.
 

timer1 interrupt 16f87

Hi,

ok, I'll try and ofer some help, but I dont know 18f and I dont know C !

The RTC chip you are using seems a bit OTT for your use. But basically, once you power on the RTC, it should start counting, and often RTC chips will pulse on one of their ppins every second but I cant see any reference to such behaviour on this particular one - not that it doesnt exist. What you need to do is read the RTC memory - just like you were reading from any of its memory. The lower 4 bits of address 0x01 are the seconds. I have never used this chip, I found a datasheet but it doesnt go up to page 134! so I assume its a different one than you have, the one I found is **broken link removed** . In order to read it you will need to know how to read I2C, I can post some generic sample code in assembly for 16F series but I dont know if that will help you. You mention an "EEByteWrite function", does this Write to I2C or to PIC EEPROM ? if it is I2C, then I assume you also have a read function?
If I were you, I'd probably bin the RTC and just use a delay in your program. Here is some code that will give a 2 second delay for a PIC running at 4Mhz



Code:
	cblock
	d1
	d2
	d3
	endc

			;1999996 cycles
	movlw	0x11
	movwf	d1
	movlw	0x5D
	movwf	d2
	movlw	0x05
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

			;4 cycles
	goto	$+1
	goto	$+1


----------------------
 

    shaneelal

    Points: 2
    Helpful Answer Positive Rating
pcf8583 c18

hai

this is working program for ds1337 rtc with seven segment display for pic
16f877
it will be helpful to u
then press helped me button
 
  • Like
Reactions: NNDD

    shaneelal

    Points: 2
    Helpful Answer Positive Rating

    NNDD

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top