Shop OBEX P1 Docs P2 Docs Learn Events
How To Choose the Truly Correct OSCHS3, OSCHS2, OSCXT2, device setting? — Parallax Forums

How To Choose the Truly Correct OSCHS3, OSCHS2, OSCXT2, device setting?

ZootZoot Posts: 2,227
edited 2008-01-27 04:57 in General Discussion
Quick background: I installed my SX servo/led controller in my big 'bot. This is a 'bot that has run fine w/o code changes for 6 months or so. Used to have a PSC in it, which I replaced with the SX version.

Now, I spent all morning get SERIN failures (sporadically) on the host side when it would query the SX. At all baud rates. Board worked perfectly on the bench.

After much trial and error, I discovered that when the motors were OFF that everything would be fine. Motors ON = serial problems. I figured maybe it was noise, but it seemed weird because the PSC (at same baud rates, exact same wiring, power supply, etc) was fine for the nearly 18 months it was installed.

In any case, it seemed like noise would be the culprit, and a single battery supplies all power systems, but I couldn't find anything amiss on the serial line with a scope, no brownouts, etc.

I decided to try a 20MHZ resonator for the SX in lieu of the 50MHZ. SX wouldn't run properly. It ran, but not "right".

Then here is the *really* strange thing -- I put a DIFFERENT 50MHZ resonator in (a blue murata from the same Parallax-sold batch as the original 50MHZ resonator), just for sh*** and grins. Guess what? PERFECT. No serial dropouts, host gets every byte fine, and the servo behaviors are truly wonderful.

So this led me back to the SX manual. For both the 50MHZ and 20MHZ trials I used OSCHS2. My understanding had been that the lower the setting you can get away with, the less power?

Then I looked over some of JonnyMac's recent columns and he uses OSCHS3 for 50MHZ and OSCXT2 for 20MHZ?

How is one to know? Are the "brittle" resonators (like the blue muratas) "high-speed" and the "mylar-y" resonators (like the brown 20mhz) "normal" speed?

If there is a cogent explanation of the fine points in choosing the clock setting, do tell.

I may have other problems going on here, of course, but given that a swap in resonators of the same type gave such different results, I figured I'd nail that down first.

Code & circuit for my SX controller board are here: http://forums.parallax.com/showthread.php?p=703230

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php

Comments

  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2008-01-24 19:44
    Maybe you just got a couple of questionable resonators??? A while back I was working on some motor control code for the SX48 running at 20Mhz. At the time I was using one of my little 40-pin DIP SX48 modules on a breadboard. Before that all the modules I had built worked perfectly. This one was acting odd and when I swapped out the resonator the problems went away. So far it was the only one i've had issues with and have tried a couple different styles with excellent results.

    FYI: I've been using OSCXT2 with the 20Mhz resonators.

    Robert
  • ZootZoot Posts: 2,227
    edited 2008-01-25 00:11
    Thanks.

    1.
    I tested some more this afternoon, and I'm sure I'm getting noise on the serial line. I swapped resonators again, but this time left all serial cables disconnected, and I get noise. I realized during earlier test I still had Stamp serial cable and SX-Key connected (the SX was not running from the key; I just left it in so I could hit program again when I wanted).

    I think that whatever noise suppression is on-board the SX-Key brings the noise on my controller board down just enough that it doesn't error. With Key and Stamp serial disconnected it's sporadic.

    I've got a 4.7k pull-up on the SX serial pin (open true) -- before pulling the board to work on noise suppression, I decideed to try enabling the pullup on that pin (to give a little more noise immunity on top of the external pull-up). Y'know what, it *really* helped.

    On the firmware end I cut the time delay for the "host to get ready" before TXing of a byte to 1ms from 5ms and that helped a lot too (my BSP has yet to choke on the shorter turnaround time). I think the longer delay let a greater chance of noise creep in (mostly in the form of bogus stop bits).

    If anyone cares to check out my photo of the board against the schematic -- there's a cap on the SX, and the 5v power supply for the 'bot is heavily filtered and the power is clean. And the PSC worked fine, so it's most likely my board -- since that's the only thing that changed smile.gif.

    My best guess is that I cheated a bit and ran the Vss wire to the resonator center pin to right near the Vss host header pin. That pin however, remains disconnected; the board receives Vss from the servo power supply V- -- this was to avoid a ground loop on the single batter setup. I'm thinking I should have tied the center pin of the resonator right to the Vss pin of the SX, which puts it next to the .1uf bypass cap?

    2.
    OK, OSCXT2 for 20mhz. I still couldn't get the SX running right, but I'm going to check that out separately with simpler code (not sure my firmware can handle 20mhz -- it's borderline).

    That still doesn't answer the question of how do you know which to use, when????? Outside of JonnyMac's and other professionals' sample code and the rather broad frequency ranges specified in the SX Manual.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • ZootZoot Posts: 2,227
    edited 2008-01-25 04:09
    10uf cap on the power rails right by the Vss lead to the resonator -- noise gone. Works great. Will post video of the controller (run by the BS2p host) shortly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • BeanBean Posts: 8,129
    edited 2008-01-25 13:04
    Zoot,

    From my experience you need to experiment to find the right setting. But for a particular resonator the setting should be the same.

    I use the lowest setting that works. Higher settings use more current and can stress the resonator.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2008-01-25 17:47
    The various OSX?? settings from LP1 up to HS3 control the setting of the three FOSC2...FOSC0 bits in the Fuse word, where settings from 000b up to 110b select one of the seven available gains for the internal oscillator feedback driver that outputs to the OSC2 pin (111b selects an external RC network).

    There is no general rule which OSC setting to use because it depends on the type of the external resonator/xtal connected to OSC1/OSC2. Some components come with internal capacitors (like the "blue" Murata resonators available from Parallax), others require external capacitors, parallel resistors, etc.

    As a rule of thumb, you can say, the higher the clock frequency, the higher the gain setting should be. But as Bean mentioned, sometimes, it requires a bit of experimenting to find the right setting for a particular resonator/xtal. It is correct: Higher gains result in more supply current, and also cause some more EMI.

    Finding the lowest setting that works for a clock device is fine, but you should consider the possible ambient temperature range. When you minimize the gain, it can happen that the oscillator will not start at lower temperatures.

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

    G
  • ZootZoot Posts: 2,227
    edited 2008-01-25 18:04
    Thanks gents. One more question in that vein:

    IFBD -- do you disable the internal feedback resistor when, say, using an external 10k resistor across the OSC pins along with a 20-50MHZ resonator w/internal caps? Or is that just for the internal RC oscillator? or?

    I've not yet seen that directive show up in code I've sampled, so I never thought about until I checked out the OSC settings table in the SX manual more closely.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • ZootZoot Posts: 2,227
    edited 2008-01-25 19:58
    Video of the controller in situ here: www.youtube.com/watch?v=9PGgkRUSlDY. This is straight drop-in with just some minor changes in the Stamp host program to accomodate the serial format for this SX (the program always stored and handled servo positions in brads, so actually the changes were to cut *out* a lot of code that has been shifted to the SX. I did not yet retune the PID routines for this 'bot -- it's running through it's main loop *so* much faster now that the old PID constants make it way too responsive and jittery, but you get the idea.

    Since everything is brads, it's easy to do some nice algorithmic work on obstacle distances and angles -- esp. for things like pan angles -- looking front, side, etc.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • pjvpjv Posts: 1,903
    edited 2008-01-25 20:27
    Hi All;

    In fact my experience shows that too high a setting can cause some resonators even at 50 MHz to not work.

    Cheers,

    Peter (pjv)
  • william chanwilliam chan Posts: 1,326
    edited 2008-01-26 02:11
    Which setting has higher gain?
    OSCXT2 or OSCHS1 ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • pjvpjv Posts: 1,903
    edited 2008-01-26 02:45
    Hi William;

    OscHS3 is the highest;
    OscHS2
    OscHS1
    OscXT2
    OscXT1
    etc

    Cheers,

    Peter (pjv)
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-01-26 19:04
    When thinking about low temperature issues, I talked with John Barrowman at Parallax about how to evaluate the crystal or resonator choices. He suggested looking at the crystal output with an oscilloscope, using a low capacitance 10x probe. The output should be a strong sine wave, just less than rail to rail. If it clips with flat tops, then turn the oscillator setting down a notch. If it is less than full, then push it up a notch. A few pf of extra capacitance can make a difference too, but the value of the external feedback resistor is not seem to matter much, except to establish DC bias.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • william chanwilliam chan Posts: 1,326
    edited 2008-01-27 03:27
    Very few scopes can look at 50Mhz signals....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.fd.com.my
    www.mercedes.com.my
  • pjvpjv Posts: 1,903
    edited 2008-01-27 04:15
    Hi Tracy;

    When I was having my debug at 3 volt problems two days ago I spent a bunch of time on these issues, and, among other things, I did exactly what you are saying. I happen to have a scope that can go to 500MHz, and a special 1.5 pF low capacitance probe good to 1 GHz to go with that, so I'm pretty sure my measurements were real.

    The debugger defaults the oscillator setting to OSCHS1, regardless of the setting in your source code. In debug mode, you can only override that by changing the setting in the DEVICE panel, and then programming the chip via that avenue. The SXKey delivers an amplitude to the oscillator input pin -OSC1- pretty consistent, regardless of frequency, but the output observed on the oscillator output pin -OSC2- varied dramatically with the oscillator gain settings, from next to nothing to hitting the rails.

    Guenther advises that in debug that is of no consequence..... I suspect therefore that during debug the chip uses the input pin of the oscillator, whereas while not in debug it would of course use the output pin, or some buffer close to there. I still think my debug problems were related to the gain settings, but hey, I'm runnin' right now, and I'll dig deeper some other time.

    In one of my 3 volt scenarios (SX48) the oscillator will not run with a 50 MHz resonator and a gain setting of OSCHS3. I need to back it off to HS2.

    So my take on all this is along the lines as Terry stated; crank it up till it quits working, and then back it off one notch. That is if you can afford the extra current, and if you can't, then I would crank it down until it quits , and then up it by a notch. And if the span is wide, then park it near the middle. But do keep operating temperatures and different voltages in mind.

    Cheers,

    Peter (pjv)
  • ZootZoot Posts: 2,227
    edited 2008-01-27 04:57
    Most illuminating.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.