|
|
View previous topic :: View next topic |
Author |
Message |
Liam_85
Joined: 09 Nov 2014 Posts: 26 Location: Ireland
|
Oscillator timings |
Posted: Wed Dec 03, 2014 7:44 am |
|
|
Hi everyone, I am looking for a bit of help with internal/external oscillator timings. I done a few tests and I am a little confused with the speed my pic is running at. I am using a PIC25HJ128GP502 with PCD version 4.140 which according to the datasheet it can run at up to 80MHz/40MIPS. I am using the directive #use delay to set up the internal and external oscillators and didn't bother with setting any oscillator fuses. From the data sheet, it says that the instruction execution speed or device operating frequency, FCY = Fosc/2. I have setup a while(true) loop with output_toggle(pin_b5) inside to view the time on the oscilloscope so I can measure the frequency. So, a few test runs.
When i used;
#use delay(CLOCK=7370000) and #use delay(INTERNAL=4M) i got the same result, the high period on pin b5 was approx 0.5uS = 2MHz. This was nearly 4 times less than 7370000 and 2 times less than 4MHz.
When I used;
#use delay(internal=16M) and #use delay(CLOCK=16M, CRYSTAL=16M) i got the same result again with the high period on pin b5 approx 0.5uS = 2MHz for both. This now is a divide by 8 reduction for both.
With crystal set to 16MHz and clock set to 20M, 40M and 80M I got approx 2.5MHz, 5MHz and 10MHz respectively on pin b5 which is a divide by 8 reduction for each.
With internal set to 20M, 40M and 80M I got the same as above, approx 2.5MHz, 5MHz and 10MHz respectively on pin b5 which is a divide by 8 reduction.
What i thought would happen is for example when I used #use delay(CLOCK=80M, CRYSTAL=16M), there would be a divide by 2 reduction to 40MHz per instruction giving the 40MIPS. I tried reading Microchips data sheet regarding this PIC24 but I find it quite hard to read and understand at times. Can somebody please point me in the right direction because I am a little confused. Thanks in advance. _________________ Liam Hanmore |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Dec 03, 2014 8:22 am |
|
|
Seriously, to do timings, use longer times.
Problem is that turning a pin on, takes more than one instruction. The loop also takes time.
A loop like:
Code: |
while(TRUE)
output_toggle(PIN_B5);
|
Codes as three instructions, taking four instruction times (on a DsPIC a jump takes two instruction times).
However on a PIC18 it takes six instruction times. etc..
Makes it very hard to work out what is happening.
You actually have to take the code apart to work out what timings to expect for a given instruction rate.
However:
Code: |
while(TRUE)
{
delay_ms(1);
output_toggle(PIN_B5);
}
|
Should give nice 1mSec long high and lows, which are easy to look at on a scope. The error becomes tiny.
Without a scope, using 1second delays or even more makes it possible to use a stopwatch.
Now your crystal frequencies are spot on. 16MHz, = 8MIPS. 4 instructions per loop = 2MHz.
Similarly with the 80MHz, you are then at 40MIPS, and the loop will be at 10MHz.
Now the only place things are failing is when you try to go slow. With 'Internal=4MHz', this can't be done, so the clock fails to the default 7.37MHz rate. |
|
|
Liam_85
Joined: 09 Nov 2014 Posts: 26 Location: Ireland
|
|
Posted: Wed Dec 03, 2014 10:44 am |
|
|
Thanks Ttelmah, I was going on the advice of my lecturer with that method of delay. I think maybe i misinterpreted the meaning of MIPS. I assumed 1MIPS was a million instructions per second like output_low(pin_b5), output_high(pin_b5), output_toggle(pin_b5) etc.
Thank you for clarifying that up for me!! _________________ Liam Hanmore |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19538
|
|
Posted: Wed Dec 03, 2014 12:05 pm |
|
|
Very much no. Some things like say a sin, or a log, will involve thousands of processor instructions. A C 'instruction', is a massive construct in processor terms.... |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|