multiply oscillators


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2009
    Posts
    6

    Default multiply oscillators

    Hi,

    I want to use 4 osscilators @ 1 pic..
    So I can choose between different oscillatos, (8,12,16,20 MhZ)..

    Code:
                    @ DEVICE PIC16F628A, MCLR_OFF				'MCLR PIN IS DIGITAL
    		@ DEVICE PIC16F628A, WDT_OFF				'WATCHDOG TIMER OFF
    		@ DEVICE PIC16F628A, INTOSC_OSC_NOCLKOUT	'Internal (INTOSC) oscillator with clock Output
    				
    		TRISA = %00000001				'0 = OUTPUT, 1 = INPUT
    		TRISB = %00000000				'0 = OUTPUT, 1 = INPUT
    		
    		CMCON = %00000111				'COMPARATORS OFF
    								
    		S0				VAR PORTB.0
    		LED				VAR PORTB.2
    		TESTJE			VAR PORTB.1
    		
    		PORTA=0
    		PORTB=0	
    		
    		Clear							'ALL BUFFERS 0
    		
    TEST:
    		@ DEVICE PIC16F628A, HS_OSC		'HIGH SPEED OSC
    		LED = 1
    		DEFINE OSC 16
    		TESTJE = 1
    		Pause 1000
    		TESTJE = 0
    		LED = 0
    		DEFINE OSC 20
    		TESTJE = 1
    		Pause 1000
    		TESTJE = 0		
    
    		GoTo TEST
    this is my code so far, but i dont work... any ideas of how to do this?

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Hi,

    Define is only used at compile time to tell the compiler which formula to use to get the right timings ...

    so, what you intend to do hasn't the least chance to work ... what you can do is add a freq variable :


    [code]

    SELECT CASE Freq

    Case 16

    TESTJE = 1
    Pause 4*1000
    TESTJE = 0
    LED = 0

    Case 20
    TESTJE = 1
    Pause 5*1000
    TESTJE = 0

    END SELECT

    But will only EASILY work for simple commands ... ( Not with One Wire, Serial or HPWM ..)

    Now ... surely Darrel has a library "hacking" for that ... at asm level !

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Apr 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi,

    Define is only used at compile time to tell the compiler which formula to use to get the right timings ...

    so, what you intend to do hasn't the least chance to work ... what you can do is add a freq variable :


    [code]

    SELECT CASE Freq

    Case 16

    TESTJE = 1
    Pause 4*1000
    TESTJE = 0
    LED = 0

    Case 20
    TESTJE = 1
    Pause 5*1000
    TESTJE = 0

    END SELECT

    But will only EASILY work for simple commands ... ( Not with One Wire, Serial or HPWM ..)

    Now ... surely Darrel has a library "hacking" for that ... at asm level !

    Alain
    I need it for hpwm..

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    So, Consider

    if You set HPWM @ 1000 Hz for a default 4Mhz Clock ...

    HPWM will run @ 4000 Hz for Xtal @ 16 Mhz

    .................. @ 5000 Hz for Xtal @ 20 Mhz


    Just correct your HPWM frequencies like that ...

    You also can have a look to Genuine examples that show how to use the PWM modules without using the HPWM command ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Default

    You can actually change the PLL and divider at run time. Probably the best way is to use Darrel Taylor's WriteConfig utility.
    Charles Linquist

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Problem is that it is only valid on 18F.

    Is there any specific reason why you want to use multiple OSC speed at runtime?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Default

    There are so many reasons not to use 16F parts. This is just one more.
    Charles Linquist

  8. #8
    Join Date
    Apr 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Problem is that it is only valid on 18F.

    Is there any specific reason why you want to use multiple OSC speed at runtime?
    i need it to take dutcycle steps by 0,1% and not 0,3%..

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ozzieB View Post
    i need it to take dutcycle steps by 0,1% and not 0,3%..
    Hi, Ozzie

    I saw on this forum one of Darrel's Goodies called " HPWM 10 " ...

    as it means ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. several oscillators
    By ozzieB in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th April 2009, 09:16
  2. Retrieving 32bit Multiply Result
    By Darrel Taylor in forum Code Examples
    Replies: 42
    Last Post: - 28th January 2008, 15:15
  3. 18F4620 hardware multiply
    By eric180db in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th November 2007, 12:54
  4. Can't multiply by 2!
    By jswayze in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th October 2004, 14:24
  5. Question about Oscillators
    By RossW in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 11th August 2004, 16:17

Members who have read this thread : 1

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