Shop OBEX P1 Docs P2 Docs Learn Events
SX asm IRC_CAL Snippet — Parallax Forums

SX asm IRC_CAL Snippet

RsadeikaRsadeika Posts: 3,837
edited 2005-12-17 23:28 in General Discussion
I am still using the Guenther code, the listing that I have is functional, I have some remarks through out the code, so if somebody notices a glaring mistake, please make me aware of it.

Now, I have a question about the proper usage of IRC_CAL.

The DEVICE OSC4MHZ selects the SX internal RC, and you get three choices of IRC_CAL IRC_SLOW, IRC_4MHZ, and IRC_FAST. In the data sheet it states something about a +-8%, I assume that IRC_SLOW would be a calibration at -8%, and IRC_FAST would be a calibration·of +8%. What kind of calibration does IRC_4MHS get? So, I guess you get a warning here, do not use this setting if you will be using this to send a rocket to Mars.

The DEVICE OSCHSx selects one of the High speed crystal/res. choices, and as turns out you get to use an IRC_CAL setting, also. So, when you select IRC_SLOW or IRC_FAST, what exactly do you get? When you leave out the IRC_CAL setting, the compiler gives a warning that it is using the default IRQ_SLOW setting. When I am using a freq 50_000_000, in the run window it just shows that the freq of the program is 50_000_000. Does the same warning apply here, do not use for rocket science.

I guess my question is for the more experienced programmers, down the road, will this come in handy, the usage of IRQ_CAL. At this point I am sort of missing the utility of the IRC_CAL setting. A couple of examples could be in order, if possible.

Ray
Thanks in advance

****CODE
;;;
;; Tut003.src
;;;
device sx52
device oschs3······ ;High speed crystal, 1MHz - 75MHz
;IRC_CAL IRC_FAST·· ;Real life utility still undecided
freq 50_000_000
;****
;device osc4mhz····· ;This uses the SX internal RC
;IRC_CAL IRC_FAST··· ;Specific for 4MHz selection
···················· ;Selections are IRC_CAL IRC_FAST,
···················· ;IRC_4MHZ, IRC_SLOW
;freq 4_000_000····· ;Can use different freq's up to 4MHz
;****
reset Main················ ;Label where the program starts
;Data area········ ;I lean towards structure, this notation
·················· ;is for me to make things a little easier

·org $0A··········· ;This is the starting point for Data
·························· ;and Code, the compiler sorts it out
·························· ;SX52 -> $0A, SX28 -> $08
·························· ;························
Counter1 ds 1············· ;Remember code can be placed here
Counter2 ds 1············· ;also, the compiler distinguishes
Counter3 ds 1············· ;between variables and code
;End of data
;Code area
·org $0············ ;Code start position on reset
Main
·mov w,#$1f········ ;This is SX52 specific -> TRIS_
·mov m,w
·mov !rd,#%11111110 ;Set rd.0 to output
Loop

·decsz Counter1····· ;Counter1 is a byte, descsz starts at 255
··························· ;and decrements until it hits 0
·· jmp Loop
·decsz Counter2
·· jmp Loop
·decsz Counter3
·· jmp Loop
·clrb rd.0·········· ;Turn on the LED
Loop1
···· ·decsz Counter1
·· jmp Loop1
·decsz Counter2
·· jmp Loop1
·decsz Counter3
·· jmp Loop1
·setb rd.0·········· ;Turn off the LED
·jmp Loop

jmp $····· ;I like to use this to end my code,
·········· ;at this point it is in an endless loop.
end······· ;End of source code, remmarks can be placed
·········· ;here after 'end'. The compiler treats
·········· ;it as text and is ignored.

Comments

  • BeanBean Posts: 8,129
    edited 2005-12-17 21:35
    No it's not rocket science, your making it way harder than it is...

    IRC_CAL is used to adjust the INTERAL oscillator ONLY. It has no effect if an external anything is used.

    IRC_FAST will just set the internal oscillator as fast as it can be adjusted, but not nessaccarly +8%, same with IRC_SLOW.

    IRC_CAL uses the SX-Key to measure the internal oscillator and sets it as close as possible to 4Mhz (this could still be several percent off).

    The +/- 8% figure means that the interal oscillator can vary upto +/- 8% with supply voltage and temperature.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012

    "SX-Video OSD module" Now available from Parallax for only·$49.95
    http://www.parallax.com/detail.asp?product_id=30015

    Product web site: www.sxvm.com

    Forget about the past, plan for the future, and live for today.
    ·
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-12-17 23:28
    A rule of thumb:

    When using any other clock source but the internal RC clock, add an IDC_CAL IRC_FAST or IDC_CAL IRC_SLOW directive to your code, just to keep the SX-Key IDE from performing an IRC calibration process when you select the "Program", "Run", or "Debug" options from the menu, just to avoid the extra time required for the calibration process. The IDE will perform the calibration whenever it "sees" an IRC_CAL IRC_4MHZ directive in the code, no matter if you have specified the internal RC clock (DEVICE OSC4MHZ) or not.

    When you want to use the internal RC clock, use the DEVICE OSC4MHZ directive (or any other one also activating the clock prescaler). You may still leave the IRC_CAL IRC_FAST or IRC_CAL IRC_SLOW directive in your code if precision of the internal RC clock is not an issue. In case you want to have the internal RC clock adjusted to 4 MHz as close as possible, use an IRC_CAL IRC_4MHZ directive instead. When the SX is programmed, some extra time is required to allow the SX-Key IDE to perform this calibration. Please keep in mind that the internal RC clock (even if calibrated) may be not stable/precise enough for certain purposes, like executing a UART VP, etc.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
Sign In or Register to comment.