| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| sonicdeejay 
 
 
 Joined: 20 Dec 2005
 Posts: 112
 
 
 
			    
 
 | 
			
				| Trying to generat 2 PWM in port C using PIC18F2431 |  
				|  Posted: Thu Jan 12, 2006 6:28 am |   |  
				| 
 |  
				| My code is as followed.... 
 and I can't measure any square wave in my oscilloscope,,,
 
 
 
 #include <18F2331.h>
 #device adc=8 //Where x is the number of bits read_adc() should return
 #use delay(clock = 4000000)
 //#use delay(clock=20000000)
 #fuses XT,NOWDT,WDT128,HS, NOPROTECT, IESO, BROWNOUT, BORV27, NOPUT, NOCPD, STVREN, NODEBUG, LVP, NOWRT, NOWRTD, FCMEN, NOWINEN, T1LOWPOWER, HPOL_HIGH, NOWRTC, NOWRTB, NOEBTR, NOEBTRB, NOCPB, LPOL_HIGH, PWMPIN, NOMCLR, FLTAC1, SSP_RC
 
 
 void main()
 {
 
 //setup_adc_ports(NO_ANALOGS|VSS_VDD);
 
 setup_adc(ADC_OFF|ADC_TAD_MUL_0);
 
 setup_spi(FALSE);
 
 setup_wdt(WDT_ON);
 
 setup_timer_0(RTCC_INTERNAL);
 
 setup_timer_1(T1_DISABLED);
 
 setup_timer_2(T2_DISABLED,0,1);
 
 SET_TRIS_A( 0x0F ); //Declare as Output
 
 //setup_adc_ports( RA0_ANALOG );
 //setup_adc( ADC_CLOCK_INTERNAL );
 //set_adc_channel( 0 );
 
 //int i, value, min, max;
 while(1)
 {
 
 output_high(PIN_A0);
 delay_ms(1000);
 output_low(PIN_A0);
 delay_ms(1000);
 output_high(PIN_A0);
 delay_ms(500);
 output_low(PIN_A0);
 delay_ms(500);
 
 
 //PWM test Drive
 output_low(PIN_C1); // Set CCP2 output low
 output_low(PIN_C2); // Set CCP1 output low
 
 setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
 setup_ccp2(CCP_PWM); // Configure CCP2 as a PWM
 
 setup_timer_2(T2_DIV_BY_16, 124, 1); // 500 Hz
 set_pwm1_duty(31); // 25% duty cycle on pin C2
 set_pwm2_duty(62); // 50% duty cycle on pin C1
 
 
 
 }
 |  |  
		|  |  
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Jan 12, 2006 1:37 pm |   |  
				| 
 |  
				| Make the changes shown in bold below: 
 
  	  | Quote: |  	  | #fuses XT,NOWDT,WDT128,HS, NOPROTECT, IESO, BROWNOUT, BORV27, NOPUT, NOCPD, STVREN, NODEBUG, NOLVP, NOWRT, NOWRTD, FCMEN, NOWINEN, T1LOWPOWER, HPOL_HIGH, NOWRTC, NOWRTB, NOEBTR, NOEBTRB, NOCPB, LPOL_HIGH, PWMPIN, NOMCLR, FLTAC1, SSP_RC | 
 
 
  	  | Quote: |  	  | void main() {
 
 //setup_adc_ports(NO_ANALOGS|VSS_VDD);
 setup_adc(ADC_OFF|ADC_TAD_MUL_0);
 setup_spi(FALSE);
 setup_wdt(WDT_ON);
 setup_timer_0(RTCC_INTERNAL);
 setup_timer_1(T1_DISABLED);
 setup_timer_2(T2_DISABLED,0,1);
 SET_TRIS_A( 0x0F ); //Declare as Output
 
 //setup_adc_ports( RA0_ANALOG );
 //setup_adc( ADC_CLOCK_INTERNAL );
 //set_adc_channel( 0 );
 //int i, value, min, max;
 
 // while(1)    // Comment out these two lines.
 //{
 
 output_high(PIN_A0);
 delay_ms(1000);
 output_low(PIN_A0);
 delay_ms(1000);
 output_high(PIN_A0);
 delay_ms(500);
 output_low(PIN_A0);
 delay_ms(500);
 
 //PWM test Drive
 output_low(PIN_C1); // Set CCP2 output low
 output_low(PIN_C2); // Set CCP1 output low
 
 setup_ccp1(CCP_PWM); // Configure CCP1 as a PWM
 setup_ccp2(CCP_PWM); // Configure CCP2 as a PWM
 
 setup_timer_2(T2_DIV_BY_16, 124, 1); // 500 Hz
 set_pwm1_duty(31); // 25% duty cycle on pin C2
 set_pwm2_duty(62); // 50% duty cycle on pin C1
 
 
 while(1);       // Add this line
 }
 | 
 |  |  
		|  |  
		|  |  
  
	| 
 
 | You cannot post new topics in this forum You cannot reply to topics in this forum
 You cannot edit your posts in this forum
 You cannot delete your posts in this forum
 You cannot vote in polls in this forum
 
 |  
 Powered by phpBB © 2001, 2005 phpBB Group
 
 |