|
|
View previous topic :: View next topic |
Author |
Message |
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
dsPIC33 timing |
Posted: Thu Dec 17, 2009 12:45 am |
|
|
I have a curious question.
on a dsPIC33, I am using a 10mhz xtal, and set the pll to on, then did the following code, and used my scope to test the timing, interesting enough, my scope tells me the +PW is 6.4ms not 10ms, when I set XTAL to 64000000 I end up getting 10.020ms now I understand it won't be perfect because of the output instruction time, and the entry/exit of the delay code, etc...
My understanding is the XTAL setting is so CCS knows the 'speed' and can adjust its delay functions correctly, however, they were really low. Did I miss something in the data sheet?
Relevant snippet of main.h
Code: |
#include <33FJ32MC202.h>
#device *=16
#FUSES PR_PLL //Primary Oscillator with PLL
#FUSES HS
#use delay(clock=XTAL)
|
My main.c file
Code: |
#define XTAL 40000000
#include "main.h"
void main()
{
setup_wdt(WDT_OFF);
setup_timer1(TMR_DISABLED);
while(1)
{
output_high(pin_b6);
delay_us(10);
output_low(pin_b6);
delay_us(10);
}
}
|
Then, I decided to do a test, no delays, so the xtal value is not being used.
dissasembly shown
Code: |
.................... while(1)
.................... {
.................... output_high(pin_b6);
0212: BCLR.B 2C8.6
0214: BSET.B 2CC.6
.................... output_low(pin_b6);
0216: BCLR.B 2C8.6
0218: BCLR.B 2CC.6
....................
.................... }
021A: BRA 212
|
I am now showing an 80ns +PW, so 80ns for 4 instructions, or 10ns each, my confusion, is that not 100mips? or did I totally miss something?
Or is my scope seeing +PW at the end of instruction 0214, and end of pulse at 0218 execution? so I am measuring 2 instructions, thus giving 50 MIPS? instead of the 40 I thought I would have? _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Dec 17, 2009 1:33 am |
|
|
Two comments:
A PIC33FJ32MC202 has a programmable PLL. It's at least ignorant to expect a certain clock frequency without
telling the compiler the crystal and intended core clock frequency. With some devices, the CCS compiler is
able to infer the PLL settings, if you tell this two values using #use delay(clock=xxx, oscillator=yyy) syntax.
In other cases, you have to setup the PLL explicitely.
A #use delay (clock = xxx) refers to the core clock frequency, not the crystal frequency. It directs the CCS compiler
to use the default PLL settings and expects, that you supply an input clock, that can achieve the said value. |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Thu Dec 17, 2009 1:36 am |
|
|
Ok, forgive my ignorance here, but what would be the correct way to set this up for 10mhz xtal and 40mhz operation (40 mips)?
Edit: in my first test, I did use the #use delay (clock = 40000000) , but the delays were way too short, so I said it was 64000000 and the delays were more accurate.
I thought I set the pll with thee lines
#FUSES PR_PLL //Primary Oscillator with PLL
#FUSES HS
again forgive me, this is my first experience with dsPic, I mostly use the 18 and under. _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Thu Dec 17, 2009 1:58 am |
|
|
FvM: I thank you, I added this line to the original test:
#use delay(clock=40M, oscillator=10M)
instead of:
#use delay(clock=40M)
timmings apear locked on now. _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Thu Dec 24, 2009 1:32 pm |
|
|
Quote: | 40mhz operation (40 mips)? |
In fact no.
The PIC architecture is capable of 1 instruction per 4 clock cycles thus 40 mhz = 10 mips.
If you want maximum mips for your dspic you need to go to 120mhz (30 mips).
Only with the internal oscillator you can reach 117.92mhz but at some disadvantage that it's no so precise (IIRC it will variate with temperature) but O.K. for most application (i use them often (internal osc.) for cost cutting).
If you want to try... this is the following header i use:
Code: |
#include <33FJ32MC202.h>
#FUSES FRC_PLL16
#FUSES PR_PLL
#FUSES NOWDT
#FUSES NOPUT
#FUSES NOMCLR
#use delay(clock=117920000)
|
7.37 mhz x PLL of 16 = 117.92mhz
or with your external 10 mhz osc :
Code: |
#include <33FJ32MC202.h>
#FUSES XT_PLL8
#FUSES PR_PLL
#FUSES NOWDT
#FUSES NOPUT
#FUSES NOMCLR
#use delay(clock=80000000)
|
for a maximum of 80mhz (20 mips) (pll16 will give 160mhz which exceed the maximum specs of 120mhz)
Regards,
Laurent |
|
|
Sergeant82d
Joined: 01 Nov 2009 Posts: 55 Location: Central Oklahoma
|
|
Posted: Thu Dec 24, 2009 11:29 pm |
|
|
The DSPICs only have 2 clock cycles per execution cycle. Or at least, the ones I have read the datasheets for do. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Dec 25, 2009 7:01 am |
|
|
To clarify the confusion:
All dsPIC33 have maximum of 80 MHz PLL output clock respectively 40 MIPS. dsPIC30 has 120 MHz PLL/30 MIPS. |
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Fri Dec 25, 2009 2:32 pm |
|
|
Quote: | All dsPIC33 have maximum of 80 MHz PLL output clock respectively 40 MIPS. dsPIC30 has 120 MHz PLL/30 MIPS. |
Oops my bad, I only work with dspic30 series, I thought that the same rules applied for the 33 series.
I know that dspic30 is older than is brother the dspic33, I didn't know that they managed to get less cycle per instruction from their architecture
Regards,
Laurent |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Dec 25, 2009 4:06 pm |
|
|
Data Sheet -- Data Sheet...
Chant... Remember... Read up. (even when NOT in doubt)
The features on Microchip products have become so numerous (especially when I'm working with different families) that study of the datasheets has become critical.
Also, for the sake of code clarity, when using a crystal, I use
#use delay (clock=40M, crystal=10M) (not oscillator)
Check the config through MPLAB or equiv to make sure the commands result the same.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Fri Dec 25, 2009 4:22 pm |
|
|
Thank everyone, this has been a big help.
I have just been working with pic18,16,12 and recently the 33 and 10.
I have never had an issue setting the clock speed, untill now with the 33.
It is me not reading the datasheet, I just assumed same logic, 4 clocks per instruction....
as mentioned previously, I am now using this when using a 33
#use delay (clock=40M, crystal=10M) _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
|
|
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
|