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.

[SOLVED] DS1307 square wave output problem

Status
Not open for further replies.

anboli

Full Member level 2
Joined
Mar 9, 2012
Messages
144
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Activity points
2,512
Hi to all,

I had interfaced the DS1307ic with my PIC controller. I getting all the values from the RTC IC, but while accessing the square wave, its not giving the proper 1Hz pulse, instead of it gives too much of pulses during the ON time of the signal but not in thr OFF time.

i given 4.7K Pull up with 3.3v,

VCC of the IC is 5V.

Please give any solution to get the proper square wave out from the DS1307 IC.
 

Go through the data sheet of DS1307, address 07.
Do ensure that you have send bit 0,1 as low

Something like below, depending upon your function:

Code:
Write_To_DS1307(0x07, 0b10010000);
 

Go through the data sheet of DS1307, address 07.
Do ensure that you have send bit 0,1 as low

Something like below, depending upon your function:

Code:
Write_To_DS1307(0x07, 0b10010000);

Yeah i given like this

write_Device(RTC,0x00,0);
write_Device(RTC,0x01,4);
write_Device(RTC,0x02,0x16);
write_Device(RTC,0x03,4);
write_Device(RTC,0x04,0x25);
write_Device(RTC,0x05,0x02);
write_Device(RTC,0x06,0x16);
write_Device(RTC,0x07,0x10);

i getting the waveform, but not exactly the perfect square wave..
 

0x10 hex is 0b00010000;

which means you have addressed bit 4 only, and not addressed bit 7.

Bit 7: Output Control (OUT). This bit controls the output level of the SQW/OUT pin when the square-wave output
is disabled. If SQWE = 0, the logic level on the SQW/OUT pin is 1 if OUT = 1 and is 0 if OUT = 0. On initial
application of power to the device, this bit is typically set to a 0.
 
Last edited:

You have to write 0x10 to the 0x07 regsiter to enable Square Wave at 1 Hz.
 

yeah i wrote both 0x90 and 0x10 in the address of 0x07..
but not getting..
 

0x10 is the correct value. 0x90 is wrong.

Bit 7: Output Control (OUT). This bit controls the output level of the SQW/OUT pin when the square-wave output
is disabled. If SQWE = 0, the logic level on the SQW/OUT pin is 1 if OUT = 1 and is 0 if OUT = 0. On initial
application of power to the device, this bit is typically set to a 0.
 

i attaching the image of the waveform.. P_20160225_171851.jpgP_20160225_171857.jpgP_20160225_171919.jpgP_20160225_171927.jpg

- - - Updated - - -

i getting the waveform like this.. during the ON time, its giving so many pulse up to the next OFF state.
 

write_Device(RTC,0x07,0x10);
Yeah i given 0x10 only in the address of 0x07..

- - - Updated - - -

yeah here it is the code..

Code:
unsigned int8 read_device(unsigned int1 Device_Select, unsigned int16 Location_Address )
{
	unsigned int8 read_data = 0;
	
	if( Device_Select == RTC )
	{
		I2C_Ack_Polling(RTC_DEVICE_WRITE);
		I2CStart();
		I2C_Write_Data(RTC_DEVICE_WRITE);
		I2C_Write_Data(Location_Address); //Device Location
		I2CStart();
		I2C_Write_Data(RTC_DEVICE_READ);	
	}
	else
	{
		I2CStart();
		I2C_Write_Data(EEPROM_DEVICE_WRITE);
		I2C_Write_Data(Location_Address >> 8 );
		I2C_Write_Data( Location_Address );
		I2CStart();
		I2C_Write_Data(EEPROM_DEVICE_READ);
	}
	read_data = I2C_Read_Data();
	I2CStop();
	
	return(read_data);
}

void write_device(unsigned int1 Device_Select, unsigned int16 Location_Address, unsigned int8 Data_To_Store)
{
	if( Device_Select == RTC )
	{
		I2C_Ack_Polling(RTC_DEVICE_WRITE);	
		I2CStart();
		I2C_Write_Data(RTC_DEVICE_WRITE);
		I2C_Write_Data(Location_Address);
		I2C_Write_Data(Data_To_Store);
		I2CStop();
	}
	else
	{
		I2CStart();
		I2C_Write_Data(EEPROM_DEVICE_WRITE);
		I2C_Write_Data( Location_Address >> 8 );
		I2C_Write_Data( Location_Address );
		I2C_Write_Data(Data_To_Store);
		I2CStop();
		I2CStart();	
		I2C_Ack_Polling(EEPROM_DEVICE_WRITE);
		I2CStop();
	}	
	return;
}


void I2C_Ack_Polling(unsigned int8 device_address)
{
	int1 ACK_STATUS = 0;
		
	while(TRUE)
	{
		I2CStart();
	
		if(I2C_Write_Data(device_address) == ACK ) 
		{
			break;
		}	
	}
		
	I2CStop();
	
	return;
}

void I2CStart()
{
	TRISH = TRISH & 0xFFBF;
	
	output_high(SDA);
	delay_us(I2C_Delay);
	output_high(SCL);
	delay_us(I2C_Delay);
	output_low(SDA);
	delay_us(I2C_Delay);
	
	return;
}

void I2CStop()
{
	output_low(SCL);
	delay_us(I2C_Delay);
	
	TRISH = TRISH & 0xFFBF;
	output_low(SDA);
	delay_us(I2C_Delay);
	output_high(SCL);
	delay_us(I2C_Delay);
	output_high(SDA);
	delay_us(I2C_Delay);
	
	return;
}

unsigned int8 I2C_Read_Data(void)
{
	unsigned int8 i, Eeprom_Read_Data = 0;
	
	unsigned int1 a=0;
	
	output_low(SCL);
	TRISH = TRISH | 0x0040;
	
	for( i=0; i<8; i++)
	{
		output_low(SCL);
		delay_us(I2C_Delay);
		output_high(SCL);
		delay_us(I2C_Delay);
		
		Eeprom_Read_Data <<= 1;
		
		a = input(SDA);
		Eeprom_Read_Data = Eeprom_Read_Data | a;
	}
		
	output_low(SCL);
	delay_us(I2C_Delay);
	output_high(SCL);
	delay_us(I2C_Delay);
	
	return(Eeprom_Read_Data);
}

unsigned int1 I2C_Write_Data(unsigned int8 Write_data)
{
	unsigned int8 i=0,j=0,temp_data;
	
	TRISH = TRISH & 0xFFBF;
	
	for(i=0b10000000,j=0;j<8;j++)
	{
		output_low(SCL);
		delay_us(I2C_Delay);
		if( Write_data & i )
		output_high(SDA);
		else
		output_low(SDA);
		i >>= 1;
		
		delay_us(I2C_Delay);
		output_high(SCL);
		delay_us(I2C_Delay);
	}
	output_low(SCL);
	delay_us(I2C_Delay);
	TRISH = TRISH | 0x0040;
	
	output_high(SCL);
	delay_us(I2C_Delay);
	
	for(i=0;i<255;i++)
	{
		if( !(input(SDA)))
		{
			break;
		}
	}
	output_low(SCL);
	delay_us(I2C_Delay);
	
	if( i == 255 )
	return(NO_ACK);
	return(ACK);
	
}
 
Last edited by a moderator:

Correct programming or not, DS1307 has no feature to produce a similar waveform. Pull-up resistor connected to pulsating 100 Hz voltage?
 

I getting the RTC Value perfectly. On every second its increment and values are updating. Dont know why its happening like this..

- - - Updated - - -

I connected the SQW/OUT pin to 4.7K Pull up resistor to 3.3V. all the details are given, yeah i know the ds1307 will not produce like this waveform at all. Its new problem for me. I cant understand why its happening like this.

- - - Updated - - -

i attach the timer output value..

Untitled.png
 

hello,


I connected the SQW/OUT pin to 4.7K Pull up resistor to 3.3V.

try to pull up resistorr to 5V instead of Vbat 3,3V..
to avoid High frequency feed back..
or try to filter 3,3V by C =2,2µF // 100nF
 
  • Like
Reactions: anboli

    anboli

    Points: 2
    Helpful Answer Positive Rating
Hi,

it seems your pullup accidentally is not connected to VCC but to an oscillating signal. Check pullup connection.

If this is not the case, then there may be a short circuit to another signal.

Klaus
 
  • Like
Reactions: anboli

    anboli

    Points: 2
    Helpful Answer Positive Rating
Thanks KlausST,
The problem with an external pull up Vcc. I given to VBAT 3.3v, its getting perfect square wave output. And i have another doubt, if i connect to the pull up to VABT, is there any chance to get down the battery life?
 

Hi,

if i connect to the pull up to VABT, is there any chance to get down the battery life?
For sure, as soon as you draw current from the battery you shorten battery life.

***
One side of the pullup is the DS1307_OUT. Did you check the signal at the other pullup connection? Is it continously VCC?

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top