| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| petu65 
 
 
 Joined: 05 Jan 2011
 Posts: 8
 
 
 
			    
 
 | 
			
				| How to setup timers to get 3 PWM-channels with 18F452? |  
				|  Posted: Fri May 24, 2013 3:32 am |   |  
				| 
 |  
				| I have used 2 PWM-channels earlier but cant figure how to use three PWM:s simultaneously? 
 This is what I have used:
 
 setup_timer_0(T0_EXT_H_TO_L|T0_DIV_1);
 setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
 setup_timer_2(T2_DIV_BY_4,199,1); //1kHz 100=50%
 setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
 setup_ccp1(CCP_PWM);
 setup_ccp2(CCP_PWM);
 
 Now I need 3 PWM-channels with 1kHz duty and 10 i/o-channels. Any other chip?
 |  | 
	
		|  | 
	
		| Mike Walne 
 
 
 Joined: 19 Feb 2004
 Posts: 1785
 Location: Boston Spa UK
 
 
			    
 
 | 
			
				| Re: How to setup timers to get 3 PWM-channels with 18F452? |  
				|  Posted: Fri May 24, 2013 4:02 am |   |  
				| 
 |  
				|  	  | petu65 wrote: |  	  | Now I need 3 PWM-channels with 1kHz duty and 10 i/o-channels. Any other chip?
 | 
 
 Can we assume you mean 1kHz frequency?
 
 Mike
 
 PS Try microchip website for chips with more than 2 PWMs.
 |  | 
	
		|  | 
	
		| petu65 
 
 
 Joined: 05 Jan 2011
 Posts: 8
 
 
 
			    
 
 | 
			
				| Re: How to setup timers to get 3 PWM-channels with 18F452? |  
				|  Posted: Fri May 24, 2013 4:11 am |   |  
				| 
 |  
				|  	  | Mike Walne wrote: |  	  |  	  | petu65 wrote: |  	  | Now I need 3 PWM-channels with 1kHz duty and 10 i/o-channels. Any other chip?
 | 
 
 Can we assume you mean 1kHz frequency?
 
 Mike
 
 PS Try microchip website for chips with more than 2 PWMs.
 | 
 
 Sorry I write wrong, PWM output frequency should be about 1kHz.
 Dutycycle to be adjusted 0-100%. 8-bit is enough.
 
 Petu
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 |  | 
	
		|  | 
	
		| John P 
 
 
 Joined: 17 Sep 2003
 Posts: 331
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sat May 25, 2013 9:24 pm |   |  
				| 
 |  
				| You should be able to do this with a chip that has 2 hardware PWMs. Then you write software to create the third one, using timer interrupts. But I can see a fine challenge coming up, where you need to have some PWM duty cycles which are so short that you must use just a single interrupt and a delay to create the pulse, and others which are longer and need an interrupt to start the pulse, and another interrupt to end it. But I don't see any reason why this absolutely wouldn't work. 
 And as always with something that needs to have precise timing, if there are other elements which conflict with your interrupts, the scheme may not be workable.
 |  | 
	
		|  | 
	
		| petu65 
 
 
 Joined: 05 Jan 2011
 Posts: 8
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue May 28, 2013 2:02 am |   |  
				| 
 |  
				| I ordered few 16F737 chips. They have three hardware PWM outputs, I think it's easiest way to do it   
 Petu
 |  | 
	
		|  | 
	
		|  |