|
|
View previous topic :: View next topic |
Author |
Message |
mahmudur.rahman
Joined: 08 Nov 2010 Posts: 3
|
need help for calculating time!!!! |
Posted: Tue Nov 30, 2010 2:24 am |
|
|
hi...
I am trying to understand something which is related with the CPU clock and ADC clock.
I don't know how to describe. I am just writing what I know.
My controller is PIC18F2550 and my crystal is 16MHz.
Now... I used the following line in my code:
Code: |
#use delay(clock=48M, crystal=16M) // processor directive that specifies the clock speed.
setup_adc(ADC_CLOCK_DIV_64); // A/D Prescaler = 64; if Fosc = 16MHz, Tosc = (Fosc/4)/64 = 62.5 KHz |
Here I multiplied my clock speed my 4 times.
Can someone please tell me how can I calculate the time to execute one instruction?
And the calculation for the time related to adc.
I don't know, that have I given enough information or not, or did I manage to make myself clear. I just need to know about all the time related factors with ADC.
thnx... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Nov 30, 2010 3:48 am |
|
|
First of all, distinguish 'times' from 'frequencies'. Things beginning with 'T', are normally 'times', while things using 'F' are normally 'frequencies'. Using 'Tosc' for a frequency is confusing.....
One instruction of what?.
The processor will execute one instruction every 1/16000000th second. However one C instruction can be millions of CPU instructions in some cases. A search here will find a lot about this.
Your 'master clock' (Fosc), is the crystal*4, not the crystal frequency itself.
Look at figure 2.1 in the data sheet, and the two lines exiting centre right, for the CPU, and peripherals. Your clock with the current settings, will be taking the oscillator, dividing it by 4, through the 'PLL prescaler', feeding this into the PLL to generate 96MHz, then through the PLL postscaler, dividing it by 2, to give 48MHz, and this is then fed into the MUX, and on to your CPU.
The ADC clock, is fed from the CPU clock, _not_ directly from the external crystal.
Now, you run into a problem here. Technically, at 48MHz, there is _no_ available divider, that gives a legal clock rate for the ADC. Look at table 21-1 in the data sheet.
The ADC takes 11 cycles of it's clock to perform a conversion.
Overclocking the ADC, reduces accuracy. This may be acceptable - depends on the ADC accuracy you need.
There are two ways to run the ADC 'legally' on these chips with a 48MHz master clock:
1) Change clock speed just for the conversion.
2) Put the processor to sleep for the conversion.
Best Wishes |
|
|
|
|
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
|