View Full Version : multiply oscillators
  
ozzieB
- 6th April 2009, 08:57
Hi,
I want to use 4 osscilators @ 1 pic..
So I can choose between different oscillatos, (8,12,16,20 MhZ)..
                @ 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?
Acetronics2
- 6th April 2009, 09:37
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
ozzieB
- 6th April 2009, 09:43
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.. :(
Acetronics2
- 6th April 2009, 10:08
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
Charles Linquis
- 6th April 2009, 16:24
You can actually change the PLL and divider at run time.  Probably the best way is to use Darrel Taylor's WriteConfig utility.
mister_e
- 6th April 2009, 17:52
Problem is that it is only valid on 18F.
Is there any specific reason why you want to use multiple OSC speed at runtime?
Charles Linquis
- 6th April 2009, 22:03
There are so many reasons not to use 16F parts.  This is just one more.
ozzieB
- 7th April 2009, 07:47
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%..
Acetronics2
- 7th April 2009, 09:41
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
 
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.