Shop OBEX P1 Docs P2 Docs Learn Events
Problems Converting Between 5 MHz Crystal and Built in Timer — Parallax Forums

Problems Converting Between 5 MHz Crystal and Built in Timer

Chip MagnetChip Magnet Posts: 2
edited 2011-09-30 08:17 in Propeller 1
I am building a little gizmo that uses the Prop chip to do little animations with 8 LEDs in P0 through P7.

First I built up the circuit on a breadboard and I used a 5 MHz crystal. This worked fine. Then I had a professional PCB made up, and I wanted to use the Prop's built-in RC timing circuit, because it was cheaper, and precise timing isn't an issue here. Well, I thought it was just going to be a matter of changing the following:


_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq

To:
CLK_FREQ = 12_000_000

Just to make sure some systems were OK, I did run a simple LED on/off program. That worked, but then my main program doesn't I'm also using JM_Bam8 as a background routine. (This is basically a way to get multiple PWM's from one cog). Are there things I should change in that as well?

It has a few lines like this:


TIX_001 := (clkfreq >> 8) >> 8 ' 256Hz, 256 steps


So, when I mess with the CLK_FREQ in the main program, now I messed up things that depend on it in the sub-routines.

Any advice? Switching between the crystal and the internal RC timer isn't as easy as changing a line or two. What are some of the pitfalls to look out for?

Thanks in advance.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-30 07:36
    I'm not sure what you're trying to do with CLK_FREQ that isn't already done with CLKFREQ. The compiler computes a clock frequency based on _CLKMODE and _XINFREQ and stores that in long location 0 of your program for use by CLKFREQ. If you explicitly provide _CLKFREQ, that's used instead. To use the internal fast RC clock all you have to do is compile your program with _CLKMODE = RCFAST and (optionally) _CLKFREQ = 12_000_000. All parts of the program that use CLKFREQ will use the new value for timing. The compiler also saves the _CLKMODE value in byte location 5 and the bootloader uses that to set the clock mode register before starting your program.
  • jazzedjazzed Posts: 11,803
    edited 2011-09-30 07:37
    Try this: _clkmode = RCFAST
    RCFAST gives approximately 12MHz operation.
    Don't use _xinfreq or _clkfreq with RCFAST.
  • photomankcphotomankc Posts: 943
    edited 2011-09-30 07:50
    ... Already explained better by others.
  • Chip MagnetChip Magnet Posts: 2
    edited 2011-09-30 08:17
    Thanks everyone
Sign In or Register to comment.