View previous topic :: View next topic |
Author |
Message |
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
driver for ds12c887 |
Posted: Sat May 17, 2008 4:56 am |
|
|
Thank you
Last edited by HTAluvBeBeo on Tue May 20, 2008 8:08 am; edited 2 times in total |
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Sat May 17, 2008 5:55 pm |
|
|
Is my code too long to read
Please help me |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sat May 17, 2008 8:07 pm |
|
|
Code: | void init_rtc(void)
{
delay_ms(50); | Try increasing the delay. According to the datasheet it can take up to 200ms for the chip to accept data after power up.
As a test it is a good idea to read back the values from registers 0x0A and 0x0B and compare with the desired values. |
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Sun May 18, 2008 2:43 am |
|
|
the delay time in init_rtc() is increased to 500ms and
my main loop to read back rega and regb. But it seems that the value in rega is not match with what I wrote to. The value in regb is ok Code: | while(1)
{
if(read_rtc(rega)==0b00100000){output_low(pin_c2);delay_ms(500);output_high(pin_c2);delay_ms(500);}
//if(read_rtc(regb)==0b00000110){output_low(pin_c1);delay_ms(500);output_high(pin_c1);delay_ms(500);}
}
|
|
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Sun May 18, 2008 3:34 am |
|
|
I tried to rewrite init_rtc() to fix th problem. but the prblem is still.
The value in rega does not match
So, the problem is I can not write a right value to rega . However the write_rtc() and read_rtc()function woks quite well. Because I wrote a value to time register, read back and the values are displayed on led 7seg correctly.
Code: | void init_rtc(void)
{
delay_ms(500);
write_rtc(rega,0b11111111);
write_rtc(regb,0b11111111);
delay_ms(500);
write_rtc(rega,0b00100000);
write_rtc(regb,0b00000110);
delay_ms(500);
} |
|
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Sun May 18, 2008 4:47 am |
|
|
I tested bit 7 of regd. It seems that all 2 of my ds12c887 are dead.Right???
the led on C2 does not blink.
Code: |
//main loop
while(1)
{if(read_rtc(regd)&0b10000000){output_low(pin_c2);delay_ms(500);output_high(pin_c2);delay_ms(500);}
}
|
Or is there any other problem here??
Thx |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun May 18, 2008 6:30 am |
|
|
Quote: | I tested bit 7 of regd. It seems that all 2 of my ds12c887 are dead.Right??? | This is not a good sign. How old are your chips?
Where did you get them from?
It is still possible there is an error in your read / write routines. What is the value you read from register D? I mean, don't just test a single bit but get the whole byte. Maybe you changed one or more data lines.
The value you read from register D should be 0x00 or 0x80, any other value means you have data line D7 connected wrong.
For testing register A you should exclude bit 7. Code: | if( (read_rtc(rega) & 0x7F) ==0b00100000){output_low(pin_c2);delay_ms(500);output_high(pin_c2);delay_ms(500);}
|
|
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Sun May 18, 2008 7:10 am |
|
|
It would be very unlucky for me to buy 2 dead RTC from two different electronics shop. I am not sure about the reliablity of those electronics shop.
I've just done more tests
Code: | if(read_rtc(regd)==0x00){output_low(pin_c2);delay_ms(500);output_high(pin_c2);delay_ms(500);} |
and
Code: |
if(read_rtc(regd)==0x80){output_low(pin_c2);delay_ms(500);output_high(pin_c2);delay_ms(500);} |
the led does not blink, so is the problem on RTC or bugs of read write function?
Code: | if((read_rtc(rega)&0x7f)==0b00100000){output_low(pin_c2);delay_ms(500);output_high(pin_c2);delay_ms(500);} |
can not write to rega. the tests with control register of RTC were all failed
but I can write value to time register and read back then display on 7segment leds exactly.
I spend much time for this project but I am going to meet the deadline tomorrow.
This is not for assignment at school. This project is for an application I am in charge of . So I really need your help
Last edited by HTAluvBeBeo on Sun May 18, 2008 7:35 am; edited 1 time in total |
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Sun May 18, 2008 10:37 am |
|
|
Th problem here now is
Can not write to bit 5 (DV1) of regA(ie 0b0010xxxx)
the value of regD is 0x20 instead of 0x80 or 0x00
Help me plz:( |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 18, 2008 11:11 am |
|
|
Quote: | unsigned char read_rtc(unsigned char addr)
{
trisd=0xFF;
trise=0b00000111;
return (data);
}
void write_rtc(unsigned char addr,unsigned char data)
{
trise=0b00000111;
trisd = 0xFF;
} |
Why do you think that the PIC pins that drive the DS, AS, R/W signals
should be set as input pins (TRIS = 1) ? When you do this, you are
removing the signals from the ds12c887. The ds12887 pins are just
floating and could become any value. |
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Sun May 18, 2008 1:55 pm |
|
|
Thank you
I have pull up resistor on both port D and port E.
the code library with motorola bus do the same thing .
http://www.ccsinfo.com/forum/viewtopic.php?t=27799&highlight=ds12887
Code: | rtc_tris_r(); //set the tris of C and D to ALL INPUTS |
I tried to remove lines which make portE or both portE and portD to high Z. But the problem is still
I can not write '1' to DV1(bit5) of regA to enable the xtal and keep clock running. I means bit5 of regA is permanently zero. Others bit of regA can be written, read quite well
And
The value read back from regD is 0x20 |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun May 18, 2008 8:33 pm |
|
|
Quote: | It would be very unlucky for me to buy 2 dead RTC from two different electronics shop. I am not sure about the reliablity of those electronics shop. | If you bought the devices new than the chance of the batteries being empty is small.
I'm not happy with your use of pull-up resistors on the control and data lines to the clock chip. These resistors will affect the rise and fall times, effectively slowing down the communication speed. The resistors are not mentioned in the datasheet and a good design doesn't need them. Best is to remove them all.
From your code I suspect you have the CS pin of the clock chip hard wired to ground? If yes, than a pull-down resistor on the AS-line could provide a stable startup situation. Note: pull-down, not pull-up!
I checked the timing of your read and write routines and you have a problem at the end of these routines: Code: | void write_rtc(unsigned char addr,unsigned char data)
{
...
output_high(RW);output_high(AS); <-- delete this line.
trise=0b00000111; trisd = 0xFF;
} | Making AS high at the end of the write starts a new access cycle, don't do this. Remove this line in the read and write function.
Quote: | Can not write to bit 5 (DV1) of regA(ie 0b0010xxxx)
the value of regD is 0x20 instead of 0x80 or 0x00 | This is almost too much of a coincidence, both regA and regD have problems with bit5. Triple check your hardware for wiring problems, short circuits, loose solder pieces, etc., especially on the AD5 line.
Bit 5 in many of the other registers is don't care but just for fun you could try if setting / resetting of bit 5 in regB is possible. Or try setting bit5 of the Seconds or Minutes registers by writing a value higher than 32.
If all the above doesn't help than give a more detailed description of your circuit, could you post a schematic picture? If you can't do that, than describe the value of the pull-up resistors? What are the CS and MOT pins connected to? |
|
|
Guest
|
|
Posted: Sun May 18, 2008 10:01 pm |
|
|
I saw some thing strange with bit5 and AD5 so I tried to write '1' to bit 5 of regB, yesterday. It was ok.
the CS is connected to GND
I will try to fix code, hardware and post my sch and layout after coming back to home.
Thank you so much for your help.
This project is very important to me.
HTAluvBeBeo |
|
|
HTAluvBeBeo
Joined: 23 Feb 2008 Posts: 35
|
|
Posted: Sun May 18, 2008 11:57 pm |
|
|
IThank you
Last edited by HTAluvBeBeo on Tue May 20, 2008 8:06 am; edited 1 time in total |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon May 19, 2008 12:14 pm |
|
|
Quote: | Here is the sch and layout. Do you have any comment else besides removing all pullup R in port D, port E and adding pull down R to AS. | These are the most important changes I can recommend.
Also have a look at the output capacitors for the LM7805; 470uF/25V at the output is a capacitance much higher than required. These high capacitances have an ESL which is quiet high and might cause oscillation. Using a 25V version is waste of space and money. At the output I recommend a 10uF/10V electrolytic capacitor in parallel to a 1uF tantalum capacitor (for a low combined ESL). |
|
|
|