View previous topic :: View next topic |
Author |
Message |
ThomasC
Joined: 09 Oct 2007 Posts: 62
|
How 2 Display Switching frequency? |
Posted: Fri Nov 02, 2007 9:16 am |
|
|
I've done multiple searches. I'm using a PIC16F690.
I believe my frequency current is:
#use delay(clock=4000000)
but can I display that in real time over RS232? Thank you all. |
|
|
Ttelmah Guest
|
|
Posted: Fri Nov 02, 2007 10:52 am |
|
|
The only way for the chip to actually be able to detect it's own frequency, is if it has another clock source. If (for instance), you have an external 1/sec sgnal on a pin, then you can (crudely), count the number of instructions between the pin changing, or (more accurately), use a CCP module to count the clock pulses between edges.
You can't work out the frequency, without a second reference (just as, you cannot tell how 'high' you are, without some baseline to compare 'height' to). If using an external serial port, then you could generate a good estimate (if you know the baud rate of the port), by using the bit width as your reference. However at the end of the day, if you are able to send serial data, your internal oscillator frequency must be close to 'right'.
Best Wishes |
|
|
amcfall
Joined: 20 Oct 2005 Posts: 44
|
|
Posted: Fri Nov 02, 2007 12:45 pm |
|
|
I am a bit confused as to what you are trying to accomplish. As said above, you pretty much have to know what frequency you are running at to do any serial communications. If you don't know what frequency you are running at, how are you going to send any data out the serial port?
Avery |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sat Nov 03, 2007 9:18 am |
|
|
Perhaps what you are looking for is a preprocessor statement like __DATE__
only for the clock instead of the DATE or a getenv(string) that would return the clock value in #use delay(clock=40000000). Your code would then have the compile time value of your clock frequency. getenv () makes a lot of values available but it doesn't make the clock value available. Even if available it wouldn't actually measure the frequency just report what you specified at compile time. |
|
|
Ken Johnson
Joined: 23 Mar 2006 Posts: 197 Location: Lewisburg, WV
|
|
Posted: Sat Nov 03, 2007 9:27 am |
|
|
From the V4.060 help file, getenv("CLOCK") returns the MPU FOSC
Ken |
|
|
ThomasC
Joined: 09 Oct 2007 Posts: 62
|
|
Posted: Mon Nov 05, 2007 8:45 am |
|
|
amcfall wrote: | I am a bit confused as to what you are trying to accomplish. As said above, you pretty much have to know what frequency you are running at to do any serial communications. If you don't know what frequency you are running at, how are you going to send any data out the serial port?
Avery |
It's a program designed for one of our customers. They will only be using only hyper terminal to interact and control the pic. |
|
|
amcfall
Joined: 20 Oct 2005 Posts: 44
|
|
Posted: Mon Nov 05, 2007 9:00 am |
|
|
ThomasC wrote: | amcfall wrote: | I am a bit confused as to what you are trying to accomplish. As said above, you pretty much have to know what frequency you are running at to do any serial communications. If you don't know what frequency you are running at, how are you going to send any data out the serial port?
Avery |
It's a program designed for one of our customers. They will only be using only hyper terminal to interact and control the pic. |
Not quite what I meant, let me rephrase:
Why do you need to do this? Even if you switch frequency I would think that you will always know what frequency you are running at or you would not be able to setup your USART to talk to the outside world. So, when you switch frequencies and setup your oscillator you would just change the value of a variable that holds your current speed. I'm just wondering out loud here, I feel that I'm missing a part of the 'why'.
Avery |
|
|
ThomasC
Joined: 09 Oct 2007 Posts: 62
|
|
Posted: Mon Nov 05, 2007 1:33 pm |
|
|
Sorry, I confused the clock speed with the external/internal oscillator/RC oscillator connection (RA5/CLKIN).
I would like to display input from pin RA5 on the pic16F690. Thanks. |
|
|
|