Oscilators?

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Fritzables
Posts: 61
Joined: 07 Jun 2008 13:20
Location: Brisbane AUSTRALIA

Oscilators?

#1 Post by Fritzables » 12 Aug 2008 09:34

Firstly I would like to thank everyone over the past 2 months who have got me on my feet with regards to PIC programming. With out your help I really think I'd still be at the bottom of the heap.
I now feel a lot more confident and understand mostly on what goes on with PIC.

I am now in an area that I would like to understand a little better and hope that you can give some assistance here.

I am using a dsPIC30F4013 for my testing.

The developmental board I bought is a new EASYdsPIC4 which has a 10Mhz crystal mounted.

I have created the following code to give to help me with what's happening with Oscillators:

Code: Select all

program CLOCK
dim tClock as string[20]
dim tFOSC as string[20]

main:
  ADPCFG = $FFFF
  LCD_INIT_EASYDSPIC4()
  LCD_CMD(LCD_CURSOR_OFF)
  LCD_CMD(LCD_CLEAR)
  
  WordToStr(Clock_Mhz(),tClock)
  IntToStr(Get_Fosc_kHz(),tFOSC)
  
  LCD_CMD(LCD_FIRST_ROW)
  LCD_OUT(1,1,tFOSC)
  
  LCD_CMD(LCD_SECOND_ROW)
  LCD_OUT(2,1,tClock)
end.
In the IDE I see that I can change the Clock frequency and have chosen 40Mhz as the default.

When ever I change the Clock, say from 40 to 80Mhz, I understand what happens with relation to the 10Mhz crystal but I don't understand the relation to the FOSC.

For example, if I set clock to 40Mhz I see a FOSC value of: -25536 then if I set clock to 80 I see FOSC as 14464

Whats the relationship with FOSC to Clock?

Fritzables.

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

#2 Post by jpc » 12 Aug 2008 10:15

in help you find sub function Get_Fosc_kHz() as longint , you are considering it to be integer giving wrong outcome. Be aware that the frequency found is what you have programmed, NOT necessarily the real clock. By modifying from 40 to 80 mHz as such nothing changes , the value must correspond with the configuration and chosen osc source .

Fritzables
Posts: 61
Joined: 07 Jun 2008 13:20
Location: Brisbane AUSTRALIA

#3 Post by Fritzables » 14 Aug 2008 04:04

Thanks jpc,

All sorted out now.

Just one last question. Over the weekend I spent time in getting to know and understand how the clock works.

I have come up with the following assumption.

In the IDE one can change the clock speed, say from 40 to 80Mhz for example - this has no effect on how fast instructions are performed (if this is the case, I am unsure why have the ability to change it).

The EasydsPIC4 board has a 10Mhz crystal installed. When I change the FLAG from the default PLL 4x to any of the other PLLs, this when I notice the change in speed of the instructions.

So, basically I should be concentrating the the PLL if I wish to control the speed oh how a certain app runs in conjunctions with the various Timers (Timer1, Timer2, ...).

Have I got the bull by the right tail now?

Fritzables.

krikitu
Posts: 66
Joined: 03 Aug 2008 15:40

#4 Post by krikitu » 14 Aug 2008 08:51

Fritzables wrote:I am unsure why have the ability to change it).
Unit "Delays" (among others ?) is recompiled when you change frequency. This implies that some underlying code is changing with frequency, which seems obvious when we deal with delays or count and maybe adc.
See what I mean ?

Then you will have to deal with other registers and config flags, like PLL, to accomodate with the new frequency.

I'm not sure I'm very clear...

Fritzables
Posts: 61
Joined: 07 Jun 2008 13:20
Location: Brisbane AUSTRALIA

#5 Post by Fritzables » 14 Aug 2008 09:14

Hi krikitu,

Thanks for the detail - yea, it makes sense.

Fritzables.

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”