| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| safwat 
 
 
 Joined: 08 Feb 2015
 Posts: 20
 
 
 
			    
 
 | 
			
				| Configuring external oscillator |  
				|  Posted: Thu Feb 12, 2015 12:14 am |   |  
				| 
 |  
				| How can i configure an external oscillator (crystal) in pic 16F877A? what is the highest frequency that can be achieved with a crystal oscillator? |  | 
	
		|  | 
	
		| safwat 
 
 
 Joined: 08 Feb 2015
 Posts: 20
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Feb 12, 2015 12:23 am |   |  
				| 
 |  
				| sorry for being trivial but do i have to add anything in the code to initialize the oscillator ? |  | 
	
		|  | 
	
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19967
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Feb 12, 2015 3:02 am |   |  
				| 
 |  
				| Just select the HS fuse as the oscillator (make sure you remove all other oscillator fuses - the number of people posting settings with two or more oscillators selected is 'major'). Maximum speed, read the data sheet - typically 20MHz, on these older chips, increasing to 25MHz on newer models. |  | 
	
		|  | 
	
		| safwat 
 
 
 Joined: 08 Feb 2015
 Posts: 20
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Feb 12, 2015 7:31 am |   |  
				| 
 |  
				| so i can get a maximum PWM frequency of maximum 5000 Hz right? what if i want to increase the PWM frequency much higher than that? |  | 
	
		|  | 
	
		| temtronic 
 
 
 Joined: 01 Jul 2010
 Posts: 9589
 Location: Greensville,Ontario
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Feb 12, 2015 8:00 am |   |  
				| 
 |  
				| You really should read the datasheet section about the CCP module. There lies specific information that you need to know as well as charts and figures. The obsolete 877 has a max of 20MHz for the xtal.
 
 jay
 |  | 
	
		|  | 
	
		| Ttelmah 
 
 
 Joined: 11 Mar 2010
 Posts: 19967
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Feb 12, 2015 8:54 am |   |  
				| 
 |  
				| As Temtronic says, 'read the data sheet'. You can run the PWM, over 20KHz, on a 4MHz oscillator. What you lose is resolution. 
 On 20MHz, at full resolution, the PWM can go to just under 20KHz. You have a factor of 4 involved somewhere that doesn't exist. Look at table 8-3 in the data sheet.
 
 Remember also, that this is a very old chip. Most newer ones allow faster oscillators, and often PLL's as well. There are PIC16's that go to 48MHz. These offer full PWM resolution up to 46.875KHz.
 |  | 
	
		|  | 
	
		| safwat 
 
 
 Joined: 08 Feb 2015
 Posts: 20
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Feb 12, 2015 10:26 am |   |  
				| 
 |  
				| yeah thanks both of you. table 8.3 solved the problem |  | 
	
		|  | 
	
		|  |