Shop OBEX P1 Docs P2 Docs Learn Events
Frequency for square wave — Parallax Forums

Frequency for square wave

CenlasoftCenlasoft Posts: 265
edited 2008-12-28 02:52 in General Discussion
Hello,
Bean gave me some code:
DEVICE SX28,OSCHS2,TURBO,OPTIONX,STACKX
FREQ 50_000_000, 34_000_000

OutPin PIN RA.0 OUTPUT

INTERRUPT NOCODE 2_000_000
OutPin = ~OutPin
RETURNINT

PROGRAM Start

Start:
END

It worked well, I want to know if I can go as low as 53 khz?
Will it work for a 4MHz resonator as well?
I apologize for the simple questions.
Thank you,
Curtis

Comments

  • JonnyMacJonnyMac Posts: 9,214
    edited 2008-12-27 02:46
    Remember that Period = 1 / Frequency -- and you need to split the period to get a square wave. Change your code to this:

    INTERRUPT NOCODE 26_500
      OutPin = ~OutPin
      RETURNINT
    



    It probably won't be perfect, but should get you close.
  • CenlasoftCenlasoft Posts: 265
    edited 2008-12-28 00:36
    Thanks for the info, I tried the code below and it gave me a 54.6 khz square wave signal on my scope. I will tweak it to get my 53 khz square wave.

    INTERRUPT NOCODE 106_000
    OutPin = ~OutPin
    RETURNINT

    My questions are:
    1. I will be sending the square wave to a tank circuit (coil and capacitor). LC tank circuits can produces high voltages and current. Should I put a resistor or diode to protect my sx28 pin?
    2. Is there is any code I can use to keep the frequency stable? I am a beginner in the sxb.
    3. I will be reading the voltage on the coil using a voltage divider and ADC0831 later. Any thoughts are appreciated.
    Thanks,
    Curtis
  • BeanBean Posts: 8,129
    edited 2008-12-28 02:21
    The output frequency is dependent on the frequency that is clocking the SX, and the ratio of SX clock to output frequency.

    For example assume you are using a 4MHz resonator. The resonator could be off by +/- 100ppM or so.

    Then you have the ratio. 4_000_000 / 106_000 = 37.7, so this should get rounded to 38. So 4_000_000 / 38 = 105_263 / 2 = 52631 Hz.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ·The next time you need a hero don't look up in the sky...Look in the mirror.


    ·
  • CenlasoftCenlasoft Posts: 265
    edited 2008-12-28 02:52
    Thanks Bean,
    I understand the concept now. I can now experiment with my tank circuit and my experiments.
    Curtis
Sign In or Register to comment.