Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Using a PIC microcontroller to interface with a DS1302 real time clock

Status
Not open for further replies.
Pommie:

Should the crystal's signal be a PWM or sine waveform? B/c when I measured the clock, I don't see anything.
 
I'm getting a sine wave signal between pin 3 and ground at 32.7 kHz with a peak to peak voltage of 247 mV. I don't see anything between pin 2 and ground, only a constant voltage of 200 mV. Is this an indicator of anything?
 
Monitoring the crystal may stop it working. The data sheet suggests monitoring the second register in order to establish if the crystal is running. Have a read of the section "Checking For Oscillation" in the data sheet linked to earlier by Picasm.

Mike.
 
Nothing thing aout breadboards and crystals.....of course they add all sort of parasitic stuff to it, but also, quite simply...watch crystals do not have very thick legs.....and breadboards need good pins to make contact :D I have had watch crystals working on a breadboard..not ideal I know but you have to solder it to a bit of stripboard then use pin headers.

My two cents.

Blueteeth
 
Pommie said:
Aren't scope probes still around 10pF even on 10X?

It's a 1/10th of what it says on the front of your scope :p

I regularly check oscillators on micro-controllers, at x1 it stops pretty well all of them, at x10 it usually works perfectly fine on either end of the crystal. Now I would have expected (probably like most people here?) that the lower the crystal the less effect it would have - however, like I said before, I had occasion to scope a 32KHz crystal last week, and even on x10 it killed the oscillation on one end of it.

I presume this is probably because it's a very low power circuit, so it can run off tiny batteries?.
 
Nigel,

I was questioning your statement with regard to a x10 probe, you stated,
and that's considerably less capacitance than a breadbopard adds!.

As I calculated the breadboard capacitance as 1pF and scopes are typically 15pF+ with a x10 probe, your statement appears erroneous.

Mike.
 
Pommie said:
Nigel,

I was questioning your statement with regard to a x10 probe, you stated,

As I calculated the breadboard capacitance as 1pF and scopes are typically 15pF+ with a x10 probe, your statement appears erroneous.

Mike.

I was (and still am) under the impression that breadboard capacitance is considerably higher than that?.

From a Wikipedia article:

Due to large stray capacitance (from 2-25pF per contact point),

Your scope probe capacitance estimate is also much too high, from a x10 probe spec:

The probe is suited to equipment with an input impedance of 1MΩ shunted by 25pF. However, it is possible to compensate for equipment with an input capacitance in the range 10-35pF.

This would give a loading capacitance of between 1pF and 3.5pF, with 2.5pF being what the probe is designed for.
 
Last edited:
Nigel Goodwin said:
I was (and still am) under the impression that breadboard capacitance is considerably higher than that?.

Maybe you can suggest where my calculation is erroneous.

You scope probe capacitance estimate is also much too high, from a x10 probe spec:
A quick google finds **broken link removed** which suggests that a x10 probe is 11-15pF.

Mike.
 
One would think that by looking a the title of a thread you could guess at about how many posts it would take to put it to rest.

There are a few things that put this out of wack.
Change of topic or hijack.
Clueless OP
The use of the word breadboard....​
:D
 
Last edited:
Nigel Goodwin said:
I wouldn't bother calculating something like that, measure it, or refer to the manufacturers measurements - for the ones which might mention it?.

I suppose your meter can measure 1pF. Mere mortals have to calculate. :rolleyes:

What about the x10 probe, it still appears to be higher than the breadboard. That is assuming that Wikipedia's 2pf if the small row and the 25pf is the power rails.

Mike.
 
Pommie said:
I suppose your meter can measure 1pF. Mere mortals have to calculate. :rolleyes:

You have to be inventive! :D

What about the x10 probe, it still appears to be higher than the breadboard. That is assuming that Wikipedia's 2pf if the small row and the 25pf is the power rails.

It only said 'between' 2pF and 25pF, not that both values were present on a breadboard.

From the look of things we may be looking at similar capacitances though?.

Not that it really matters, get the crystal off the breadboard where it has a chance!.
 
Try to write and read on DS1302 RAM first, if you don't get the right result clear WP bit, if still can't read and write your functions might not be working, if it does read the seconds register, if seconds value is not changing clear CH bit.
 
Does anyone know whether I can make a particular pin (namely RA2) as both an input and an output on a PIC? I am having trouble managing the TRIS register properly in my code. Thanks.
 
ssylee said:
Does anyone know whether I can make a particular pin (namely RA2) as both an input and an output on a PIC? I am having trouble managing the TRIS register properly in my code. Thanks.

Yes you can have it as both input and output. If you are experiencing difficulty I suspect that you have the pin setup as an analogue input. When setup as analogue, the pin works fine as an output but will always read zero when used as a digital input. Try setting ADCON1 = 0x0f.

Mike.
 
ssylee said:
Does anyone know whether I can make a particular pin (namely RA2) as both an input and an output on a PIC? I am having trouble managing the TRIS register properly in my code. Thanks.

It's common practice, and is the way I2C is generally done.

As suggested, you need to say what PIC you're using so we can tell you if there are specific requirements for that pin.
 
Some good news: I've managed to configure and read out the time properly (hour, minute, second) without starting the clock. However, I am having trouble with when I'm setting up other registers of the chip. My logic is to stop the clock, clear the write protect bit, change whatever register to carry the value I want, and then start the clock again, as shown in the function below:
Code:
// This function sets the time of the Real time Clocks
// Note to self: change it such that it's user controllable
void set_time(void)
{
     // Stop the Clock
     start_stop_RTC(1);

     // Clear the Write protect bit before setting time
     write_protect(0);

     // Set time
 //   set_seconds(0);
 //   set_minutes(9);
 //   set_hour(9, 1, TWELVEHOUR);
 //   set_hour(22, 0, TWENTYFOUR);
/*    set_date(2);
    set_month(1);
    set_day(4);*/
    set_year(2008);

    // Start the clock
    start_stop_RTC(0);

    // Set the Write protect bit before setting time
    //write_protect(1);
}

However, I'm running into a problem that my seconds register is reset to zero whenever the start_stop_RTC() function is called, leading to a lag time. My start_stop_RTC() function looks like below:
Code:
// This function starts or stops the Real-time Clock Upon Request
// halt == 1 -> stop the RTC
// halt == 0 -> start the RTC
void start_stop_RTC(short halt)
{
     unsigned char current_time;

    // retrieve current time
    current_time = readbyte(READSEC);

     if (halt==1){                // if desired to halt
        // set the Clock Halt bit to bit 7 only
        writebyte(WRITESEC, current_time | (halt << 7));
     }
     else if (halt == 0)         // if desired to start
     {
         // clear the Clock Halt bit to bit 7 only
         writebyte(WRITESEC, current_time & (0xfe << 7));
     }
}

I have modified some sample code written by Maxim/Dallas Semiconductor for a 8051 type microcontroller to work for the PIC I'm using, so readbyte() and writebyte() functions were tested to work. Is it by design that the seconds register act this way? Thanks.
 
I don't read C but it looks like you're clearing the whole register not just the bit. Looks like your supposed to put the seconds in with the start clock bit.
Why would you want to stop the clock once it's running? Not sure if you can even read or write a single bit with SPI.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top