Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 6th January 2008, 02:31 PM   (permalink)
Default

Quote:
Originally Posted by Nigel Goodwin
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.

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 is offline   Reply With Quote
Old 6th January 2008, 02:45 PM   (permalink)
Default

Quote:
Originally Posted by Pommie
I suppose your meter can measure 1pF. Mere mortals have to calculate.
You have to be inventive!

Quote:

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!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now   Reply With Quote
Old 6th January 2008, 11:30 PM   (permalink)
Default

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.
penoy_balut is offline   Reply With Quote
Old 7th January 2008, 04:53 AM   (permalink)
Default

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 is offline   Reply With Quote
Old 7th January 2008, 05:42 AM   (permalink)
Default

Quote:
Originally Posted by ssylee
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.
Pommie is offline   Reply With Quote
Old 7th January 2008, 09:09 AM   (permalink)
Default

Quote:
Originally Posted by ssylee
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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now   Reply With Quote
Old 7th January 2008, 11:25 PM   (permalink)
Default

I'm using a PIC18F2620 (not sure if I mentioned it in the first thread of the topic).
ssylee is offline   Reply With Quote
Old 7th January 2008, 11:56 PM   (permalink)
Default

Did you check that you have ADCON1 = 0x0f as I suggested.

Mike.
Pommie is offline   Reply With Quote
Old 9th January 2008, 06:43 AM   (permalink)
Default

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.
ssylee is offline   Reply With Quote
Old 9th January 2008, 06:51 AM   (permalink)
Default

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.
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 9th January 2008, 06:55 AM   (permalink)
Default

Where does the code look like I'm clearing the whole register.
On the other note, I'm not aware of the ability to change the register content without stopping the clock. I probably never want to stop the clock. I don't recall reading anything about the datasheet whether I have to stop the clock before modifying the contents before they change again.
ssylee is offline   Reply With Quote
Old 9th January 2008, 06:56 AM   (permalink)
Default

Shouldn't

writebyte(WRITESEC, current_time & (0xfe << 7));

be

writebyte(WRITESEC, current_time & 0x7f);

Mike.
Pommie is offline   Reply With Quote
Old 9th January 2008, 07:03 AM   (permalink)
Default

I think they are the same. However, your function call is more efficient since there is one less operation. My function call included an extra operation of shifting the 0 in bit 0 to the left seven times.
ssylee is offline   Reply With Quote
Old 9th January 2008, 07:05 AM   (permalink)
Default

0xfe shifted left 7 times is 0x7f00, I assume WRITESEC requires a byte and therefore it will get passed zero.

Mike.
Pommie is offline   Reply With Quote
Old 9th January 2008, 07:21 AM   (permalink)
Default

You're still writing over the seconds register no matter how you figure it. You should write the seconds last and let it run. It does all the MDY calcs on its own till year 2100. Are you trying to make it a stopwatch?
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
Real Time FLIR Video Feed digital0ne Robotics Chat 3 11th April 2004 06:21 PM
digital clock setting the time mode Jay Duluguin Electronic Projects Design/Ideas/Reviews 0 19th February 2004 10:09 PM
real time clock finst Micro Controllers 4 17th January 2004 12:11 AM
list of Real Time Clock thendo Micro Controllers 2 8th November 2003 05:41 PM
time clock gogo01 Electronic Projects Design/Ideas/Reviews 2 22nd August 2003 05:05 AM



All times are GMT. The time now is 10:36 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.