PDA

View Full Version : Can the clock frequency change automatically?



huynh
05-17-2010, 02:30 PM
Dear all users,

It's my honor to have your opinion in an issue that involved with the clock frequency of Prostick USB.

I use an Prostick USB to receive data from some sensors, including the Digital magnetic compass and the rotational speed sensor. the clock setup is "
_CLKMODE = XTAL1 + PLL16X, 80 Mhz clock
_XINFREQ = 5_000_000;

As I use the function "byte[Stringptr][index++] := rx" the clock frequency looks quite different. By checking the following output:

out := (100_000_000/(clkfreq/1_000_000) + 1), (note: it just a function consisted of clkfreq/1_000_000)

i found that:
+ without the code of "byte[Stringptr][index++] := rx", the value of "out" is 12500001, so the clkfreq can be calculated as 80Mhz
+ as the code of "byte[Stringptr][index++] := rx" is included, the value of "out " is 724638, hence the corresponding clkfreq is 138Mhz

is it correct?

I do not have much experience about this issue. I am wondering whether there is a conflict as using the function of "byte[Stringptr][index++] := rx" or not.

Thank for any suggestion.

thien,

Timmoore
05-17-2010, 02:35 PM
no clock freq will not change without you explicitly changing it. Your symptoms are memory corruption. Check stringptr and index. If you post the rest of the code we can look and see if we can see the problem.

huynh
05-17-2010, 04:11 PM
I found some information in the manual in page 63,64. it is said that:

"CLKFREQ vs. _CLKFREQ
CLKFREQ is related to, but not the same as, _CLKFREQ. CLKFREQ is command that returns the current System Clock frequency whereas _CLKFREQ is an application-defined constant that contains the application’s System Clock frequency at startup. In other words, CLKFREQ is the current clock frequency and _CLKFREQ is the original clock frequency; they both may happen to be the same value but they certainly can be different."

It indicates that the CLKFREQ return the current clock frequency, which can differs from the origin value. But I still do not understand why it can be 138Mhz, while the maximum freq is 80Mhz.



Here is the code that I use to receive data from digital magnetic compass


pub DMCoutput | index

repeat while RxDMC <> "$"
RxDMC := DMC.rxcheck

index~

repeat while ( RxDMC <> "*" )
RxDMC := DMC.rx

byte[stringptr][index++] := RxDMC


byte[stringptr][--index]~
]


it is the subprogram in the main code

kuroneko
05-17-2010, 04:17 PM
So what's the value of stringptr? It really helps when you show as all the code. Otherwise we keep guessing ...

huynh
05-17-2010, 04:37 PM
Here the whole code. If you do not run the line of
byte[stringptr][index++] := RxDMC and byte[stringptr][--index]~ , you will get the clkfreq of 80Mhz, but as you run them, you we get 138Mhz for the clkfreq. Is it possible? I think there was something wrong


[

CON

_CLKMODE = XTAL1 + PLL16X ' 80 Mhz clock
'_XINFREQ = 5_000_000
_CLKFREQ = 80_000_000

'serial port to PC
PortRx = 26
PortTx = 27

' compass input pin

DMCTx = 22
DMCRx = 25



OBJ

PortCom : "FullDuplexSerialPlus"

DMC : "fullDuplexSerialPlusDMC"


VAR

'var DMC
byte bufferDMC[25]
long RxDMC
long stringptr
long ck




PUB Start


PortCom.start(PortRx, PortTx,0,115200)
DMC.start(DMCRx, DMCTx, 0, 115200)

repeat
Main


PUB Main |index


repeat while RxDMC <> "$"
RxDMC := DMC.rxcheck

index~

repeat while ( RxDMC <> "*")
RxDMC := DMC.rx
byte[stringptr][index++] := RxDMC

byte[stringptr][--index]~


ck := clkfreq

portcom.str(string(13))
portcom.str(stringptr)

portcom.str(string(","))
portcom.dec(ck)

PortCom.str(string(10))


]

MagIO2
05-17-2010, 05:57 PM
And now guess what the value of stringptr is when you run that code?

It's initialized to 0 and never set to an appropriate address. Guess what you want to do is:

stringptr := @bufferDMC

In your case you overwrite the first 16 bytes of RAM which have·a sepecial purpose including the variable CLKFREQ.


Post Edited (MagIO2) : 5/17/2010 11:12:01 AM GMT