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

    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 01:52.

  2. #2
    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.

  3. #3
    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

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    With VDD = 5.0V, supply current of PIC18F4550 at 4MHz is typically 2.5mA (5.0mA MAX). In sleep mode it is 0.1uA (2.0us MAX). See table 28-2 of the datasheet.

    So in sleep mode, current consumption is 1/25000 of that of run mode at 4MHz. To reduce power consumption - the intent of the OP - it makes more sense to use the Power Managed Modes of the device, which is what they were designed to do.

    Any of the available interrupt sources can cause the device to exit from the Sleep mode to Run mode. To enable this functionality, an interrupt source must be enabled by setting its enable bit in one of the INTCON or PIE registers. The exit sequence is initiated when the corresponding interrupt flag bit is set. You can also exit Sleep mode by WDT time out.

  5. #5
    Join Date
    Jun 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Thumbs up thanks all

    thank you all for your help,, here is what i did,

    i ran the cpu on lower speed than the 48mhz needed for the USB, which did the trick without the need to switch the clock on the fly.

    thanks again

  6. #6
    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).

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


    Did you find this post helpful? Yes | No

    Default

    For all you that are contemplating a common body of code running on many different PICs , I have a project where I have to deal with this on a constant basis. For a long time, we built hardware with a 20Mhz 8720. Later, the hardware changed to a 40Mhz 8723. The speed increase was necessary for some new functionality (the 12 bit A/D was handy too), but we really didn't want to support two code bases. Some customers had both models, which meant the same code had to run seamlessly on both. The boards (obviously) have nearly the same functionality, but upgrades dictated that some pin changes (at least on the PIC - not the board I/O) had to change as well.

    We even had a few intermediate boards that were running with an 8723 at 20Mhz. These were built when the '8720 was becoming obsolete and before we had code that was modified to run at 40Mhz.

    Our code can tell some of the things about the board it is on by reading the state of a couple of pins on startup (no we didn't plan it that way, it just works out).

    The 20 Mhz units are running with a 20Mhz XTAL, and the 40Mhz units are running on a 10Mhz XTAL with the 4X PLL running.

    We read the config bits to see if the PLL is enabled and set a "40Mhz" flag.
    The config bits also tell us we are running on an 8723 or 8720.

    Since the code is the same in all boards, the DEFINES are the same. In our code, the OSC is DEFINEd to 20.

    Using information from the config bits, we made a table that set up things properly as far as timer reload values (to keep the timer interrupts at a constant rate), Baud rate values, PR2 (PWM registers, etc), A/D clock (/32 or /64). The A/D conversion routines also had to be changed to deal with the two extra bits on the '23.

    Finally, we made a large number of GOSUB DELAYX , which replaced all the PAUSE STATEMENTS. For example: The PAUSE 100 would be replaced with
    GOSUB DELAY100. DELAY100 called another routine that contained PAUSE X,
    where 'X' was either 100 (for 20Mhz) or 200 (for 40Mhz).

    It can be done.
    Charles Linquist

Similar Threads

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