|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Real time clocks, out of the question?
Quote:
'volatile' tells the compiler that the variable may change on its own and to generate code as appropriate. For optimization purposes, a compiler may read a variable from memory into a temporary register, and subsequent read/write operations to that variable _may_ only occur to the register without updating the memory location. Telling the compiler that the variable is volatile causes the compiler to re-read the variable's memory location each time it is used, and to write it back to memory each time it is updated. 'volatile' would be used for things like hardware periphial registers, as well as things like variables that might change inside of an interrupt routine. Since the compiler can't know why you are telling it that the variable is volatile, it wouldn't generate additional instructions to disable interrupts during critical regions to ensure that a multi-byte variable read/write operation is performed without the potential for another interrupt routine corrupting the operation. Pre-emptive multi-tasking operating systems generally pose the same potential for corruption that an interrupt routine does. The 'static' qualifier allows variables to be declared within a local, rather than global, scope and simply tells the compiler to declare the variable in a memory location that is static, rather than allocating it on the stack frame (or emulated equivilent thereof) of the local function. Any variable declared outside of a function is normally considered a global variable, but unless other source files provide an 'extern' reference, the variable's use will remain limited to that source file, and is sometimes referred to as a 'local global'. The caveat here is that if you were to declare another 'local global' in another source file, the linker will (usually) have a problem with the duplicate declarations, and generate an error. Recognizing that Microchips documentation already presumes a certain familiarity with the "C" language and doesn't really get into all of the specifics, for those that already have a general grasp on the "C" language, two books that I would recommend are: The C Programming Language by Brian Kernighan and Dennis Ritchie, who are the origional authors of "C". A book on C by Al Kelly and Ira Pohl. K&R's book is very terse with minimal examples, but is the bible. The 2nd one is also a bit terse, and goes into depth more than K&R's book. I've included links to Amazon's website as a convienent reference, but retailers such as Barnes & Noble also generally carry these and other good reference books where you can browse before you buy. |
|
#2
|
||||
|
||||
|
Strangely enough, K&R is sitting right here on my bookshelf. Somehow I hadn't remembered "volatile". I'll go reread through the data types/variables stuff again.
Not to seem pestery... but I've once again confused myself in this code. I read through the PIC's datasheet (timer section) and studied up on the registers. On the good side, I now completely understand all the scalers, clocks, and flags, but I could not seem to understand how the high and low byte registers worked/were needed. I don't see how an integer could go past 65,535, so why does the high byte happen to be able to have a value over that? I also could not find an equivalent for the PR2 register for Timer1. Is that simply not present and do I have to use conventional math to downscale further? Thanks again for the help. |
|
#3
|
||||
|
||||
|
Re: Real time clocks, out of the question?
Quote:
Timer's 2 & 4 are 8 bit wide timers and have the "PR" registers, the other timers are 16 bit. Timer 1 is a bit special and can be used for a low power, real time clock function. Without a specific reference, I'm not sure what you mean about the high byte having a value greater than 65535. My only guess would be that by setting a value to zero, you'll get an effective divide rate of 65536, but I don't immediately see that in the documentation. The reason that the 16 bit counter is split into two 8 bit registers is that the CPU only operates on data 8 bits at a time. So a 16 bit read/write operation requires two data bus operations to manipulate the 16 bit value. Does that help or did I miss one or more of the questions? |
|
#4
|
||||
|
||||
|
Ahhh, that explains things a bit. I should have thought about that. RD16 two bytes wide, duh.
Thanks for that tidbit. And the high and low bytes. In the wallclock code (http://www.chiefdelphi.com/forums/sh...t=wallclock.c), the high byte value is.... NEVER MIND Someone can't count their zeros. I still don't exactly understand what the purpose of the high and low bytes are. Is it like an loop condition? Above the max value for a 16bit number counts as an overflow and it resets, setting the flag with it? THANK YOU |
|
#5
|
||||
|
||||
|
Re: Real time clocks, out of the question?
I wrote some real-time clock code for the EDU-RC a few years ago. Here's a link: http://kevin.org/frc/2005/edu_clock2.zip.
-Kevin |
|
#6
|
||||
|
||||
|
Re: Real time clocks, out of the question?
Okay. Thanks very much Kevin and Mark. The last thing I need to make sure of is the value for the system clock. In the edu_clock code, it's specified as 10MHz. Does anyone know if there would be a difference in the PIC18F8722? I seem to remember reading something about 32.blablabla MHz somewhere. Or maybe it's changeable...
After this, I deserve to be put back into grade school if I can't do the math. THANKS |
|
#7
|
|||||
|
|||||
|
Re: Real time clocks, out of the question?
It's the same 10MHz for the PIC18F8722 we use.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Networkable real-time game simulation for 'Aim High'! test it out now | Bongle | General Forum | 11 | 19-03-2006 23:10 |
| Real time photos from the buckeye regional | Greg Needel | Regional Competitions | 4 | 25-03-2004 12:46 |
| Robot motion after the time has run out. | Randy Ai | Rules/Strategy | 1 | 06-01-2003 17:17 |
| Real Time Scoring | archiver | 2000 | 2 | 24-06-2002 00:09 |
| real time chat | SharkBite | CD Forum Support | 4 | 07-02-2002 21:22 |