Shop OBEX P1 Docs P2 Docs Learn Events
50 MHz Resonator\SX/B — Parallax Forums

50 MHz Resonator\SX/B

RsadeikaRsadeika Posts: 3,837
edited 2005-02-11 22:24 in General Discussion
DEVICE········· SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000

LED1 var RC.7

PROGRAM Start

Start:
·low LED1
·pause 4000
·high LED1
end

When the above listing is run with the sx key installed, I get a pause of 4 seconds. When I remove the sx key and run it with the 50MHz resonator, the pause is just a flash, less than a second.

Do I have to be resonator specific, meaning if I use 'freq 4_000_000' in the program, then I have to use a 4 MHz resonator to have the correct time lapse?

Soon, the questions will stop.

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-02-10 20:01
    The FREQ directive only tells the SXKey what speed to run at, when you are using the resonator it will run at that speed. If you want your SXKey to behave like your resonator you should specify the speed of your resonator in the FREQ directive. The SX has an on-board clock that runs at 4MHz, you can specify its use instead of the resonator.
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-02-10 20:44
    Actually the FREQ directive tells the Basic keywords what oscillator you intend to use. Thus, the PAUSE 4000 will use the FREQ 4_000_000 directive to accurately set the delay.

    If you then put in a 50 Mhz oscillator, then PAUSE has set the delay WAY too short -- as you saw.

    The SX doesn't really care what size oscillator you put in. However, the Basic keywords do, if you are going to get accurate timing. I believe you also have to tell the SX-Key what frequency you want IT to give the SX you are programming.

    Conclusion: If you want accurate timing, make sure all three settings agree -- your resonator, the FREQ line, and the SX-Key setting. And the above poster is correct -- the SX has an 'internal' 4 Mhz oscillator that doesn't require external components.
  • Jim G.Jim G. Posts: 27
    edited 2005-02-10 20:47
    ... I'm not using SX/B, but I suspect that the FREQ directive also tells compiler the clock speed so it can calculate the correct·delay for the 'pause' command to be accurate...

    If this is true, then changing to FREQ 50_000_000 should make everything work; SX Key or resonator.

    Another $0.02.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-02-10 20:54
    Like Jim I have not used the SX/B, after I posted I realized that SX/B has frequency depedent instructions which would rely on the frequency specified in the directive, therefore I should not have used the word "only" in my previous post.
  • BeanBean Posts: 8,129
    edited 2005-02-11 01:44
    Of course the timing will be wrong if you tell the compiler that the frequency is 4 MHz and you are clocking the chip at 50 MHz ???
    Bean.
  • RsadeikaRsadeika Posts: 3,837
    edited 2005-02-11 13:19
    Thanks everybody. The gist of the information, if I am going to use a 50MHz resonator then I should make sure that the 'freq' matches the resonator. I thought that the resonator would act like the sx key, make the correct 'freq' adjustment.
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-02-11 18:59
    Rsadeika,

    a resonator is always factory-calibrated to the frequency it is specified for, i.e. what is printed on the resonator's body.

    When you connect a resonator to the OSC1/OSC2 pins of an SX, the SX-internal oscillator driver supplys the SX functional sections with the clock frequency impacted by the resonator currently hooked up erxternally.

    The SK-Key, on the other hand, has a variable clock generator integrated, capable of driving the SX with many different clock frequencies through the OSC1 pin.

    In SX Assembly language, the FREQ directive defines the frequency, SX-Key shall generate and feed into the SX under test. By no means, can this directive "tell" the SX which clock frequency it shall use when running stand-alone. IOW, always make sure that the FREQ directive specifies the same frequency (i.e. the resonator's frequency) you will be using in a stand-alone system.

    In SX/B-generated programs, this becomes even more important as SX/B takes the information specified by the FREQ directive (in the SX/B program) to calculate the loop counts required for various time-sensitive incstructions, where PAUSE is just one of them. In an Assembly program, you would have to make all these time calculations manually which SX/B nicely does for you. As you will notice, the Assembly output generated by SX/B also conatains the same FREQU directive it has found in the SX/B program in order to set the SX-Key clock generator to the desired frequency.

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

    G
  • RsadeikaRsadeika Posts: 3,837
    edited 2005-02-11 22:24
    Thank you Gunther. Now I know what the function of a resonator is, and more importantly how it fits in to the scheme of things. You can probably tell that my background is not electronics.
Sign In or Register to comment.