changing osc on the fly


Closed Thread
Results 1 to 23 of 23

Hybrid View

  1. #1
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    I was thinking of a routine that could detect the clock speed the pic is running at
    so that then the pic program could adjust serial speed, etc accordingly.

    Make a delay loop in picbasic and count the number of ticks a hardware timer
    makes during the delay loop.. and then the hardware timer value will be
    different for different clock speeds.

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Wouldn't a delay need to know clock speed to work correctly?

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Art, What would you use as a reference in that situation?

    Dave Purola,
    N8NTA

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    If you have a PIC that supports Internal/External Oscillator Switchover then you shouldn't need a firmware solution to determine osc speed. You already know what it should be after you write to OSCCON & flip the System Clock Select bit.

    If you have one running on the internal oscillator, and you need to calibrate it, then Microchip has a few app notes for this using TMR1 with an external 32.768kHz watch type crystal. Or you could just output the internal clock on OSC2/CLKO and test it with an O-scope.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rmteo View Post
    Wouldn't a delay need to know clock speed to work correctly?
    No, because you use a timer based on RC clock, which is always the same,
    but the delay is dependent on osc speed.

    So, start timer, execute delay, read timer.

    The fact that the delay varies is what I'm counting on.

  6. #6
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Lets say you have a 4MHz clock and you set a delay of 1mS (1000us). A timer (without pre/post scaler) will count to 1000 for the duration of the delay.

    Now drop the clock the 1MHz. The timer will now count to 250 (1000/4) each mS. However, the delay will increase to 4mS due to the slower clock, so the timer will again count to 1000.

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    On the 16F877/876 for example, Timer0 can increment on the rising or falling edge of pin RA4/TOCKI
    That way you can use an RC osc to control TIMER0 so varying the OSC for the microcontroller will
    change the speed of the pause delay, but not the speed of TIMER0.
    Art.
    Last edited by Art; - 6th February 2010 at 02:52.

  8. #8
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Art View Post
    On the 16F877/876 for example, Timer0 can increment on the rising or falling edge of pin RA4/TOCKI
    That way you can use an RC osc to control TIMER0 so varying the OSC for the microcontroller will
    change the speed of the pause delay, but not the speed of TIMER0.
    Art.
    That is a little different from this.
    Quote Originally Posted by Art View Post
    Make a delay loop in picbasic and count the number of ticks a hardware timer
    makes during the delay loop.. and then the hardware timer value will be
    different for different clock speeds.

  9. #9
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    In some cases, you can read the configuration bits to determine if you are running on the INT OSC, and whether or not any dividers or PLLs are in use. If you have any kind of external oscillator or RS-232 input, you can figure things out pretty easily.
    Charles Linquist

  10. #10
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rmteo View Post
    That is a little different from this.
    and then the hardware timer value will be
    different for different clock speeds.
    The hardware timer value you read back after the pause routine will be different for different clock speeds (of the microcontroller osc).

Similar Threads

  1. Define osc 1
    By ronsimpson in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st October 2009, 07:35
  2. Changing bits in a byte for multiple output
    By tazntex in forum Serial
    Replies: 3
    Last Post: - 11th August 2008, 20:10
  3. Replies: 4
    Last Post: - 16th May 2008, 15:35
  4. Changing declared variables names on the fly
    By jessey in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 16th December 2006, 07:34
  5. Mode changing on the fly
    By Angus Anderson in forum GSM
    Replies: 1
    Last Post: - 28th November 2006, 09:58

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts