| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| tien168bn 
 
 
 Joined: 04 Apr 2014
 Posts: 7
 Location: Viet Nam
 
 
			    
 
 | 
			
				| PWM with 18F4431 |  
				|  Posted: Mon Jun 09, 2014 9:29 pm |   |  
				| 
 |  
				| I have 2 motor. I use PWM with PIC18F4431. but I use Proteus for simulation. It not run. Help me with problem.  	  | Code: |  	  | #include "D:\Do line\main.h" #fuses hs, nowdt, noprotect, nowrt, nolvp, hpol_low
 #use delay(clock=20000000)
 
 #byte porta=0xf80
 #byte portb=0xf81
 #byte portc=0xf82
 #byte portd=0xf83
 #byte porte=0xf84
 /////////////
 #use fast_io(a)
 #use fast_io(b)
 #use fast_io(c)
 #use fast_io(d)
 #use fast_io(e)
 
 #bit dk0 = portb.5
 #bit dk2 = portb.2
 #bit start = portd.0
 #bit stop = portd.1
 #bit cb0 = porta.0
 #bit cb1 = porta.1
 #bit cb2 = porta.2
 #bit cb3 = porta.3
 #bit cb4 = porta.4
 #bit cb5 = porta.5
 
 
 int1 flag = 0;
 void button(void)
 {
 if(start == 0 && stop == 1)/// && flag == 0)
 {flag = 1;}
 if(start == 1 && stop == 0)// && flag == 1)
 {flag = 0;}
 }
 void main()
 {
 SET_TRIS_A (0xFF);
 SET_TRIS_B (0X00);
 SET_TRIS_C (0X00);
 SET_TRIS_D (0X0F);
 SET_TRIS_E (0B111);
 SETUP_POWER_PWM_PINS(PWM_ODD_ON,PWM_ODD_ON,PWM_ODD_ON,PWM_ODD_ON);
 SETUP_POWER_PWM(PWM_CLOCK_DIV_64|PWM_FREE_RUN,1,0,250,0,1,0); //15kHz--333
 SETUP_TIMER_2(T2_DIV_BY_1,255,1);
 dk0 = 0;
 dk2 = 0;
 set_power_pwm0_duty(0);
 set_power_pwm2_duty(0);
 while(true)
 {
 button();
 if(flag == 1)
 {
 dk0 = dk2 = 1;
 delay_ms(70);
 set_power_pwm0_duty(700);
 set_power_pwm2_duty(700);
 }
 if(flag == 0)
 {
 dk0 = dk2 = 0;
 delay_ms(70);
 set_power_pwm0_duty(0);
 set_power_pwm2_duty(0);
 }
 }
 }
 | 
 |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 |  | 
	
		|  | 
	
		| tien168bn 
 
 
 Joined: 04 Apr 2014
 Posts: 7
 Location: Viet Nam
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Jun 09, 2014 9:44 pm |   |  
				| 
 |  
				| I use module PWM of 18F4431. but It not run. Have something wrong? This code, in last year, it run with my robot. and now, it not run :(. both simulation and in the circuit
 |  | 
	
		|  | 
	
		| tien168bn 
 
 
 Joined: 04 Apr 2014
 Posts: 7
 Location: Viet Nam
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon Jun 09, 2014 9:49 pm |   |  
				| 
 |  
				| The signal in RB5(PWM5) not change.@@ |  | 
	
		|  | 
	
		| PCM programmer 
 
 
 Joined: 06 Sep 2003
 Posts: 21708
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Jun 10, 2014 12:36 am |   |  
				| 
 |  
				|  	  | Quote: |  	  | The signal in RB5(PWM5) not change | 
 The PWM5 signal does not come out on pin RB5.  It comes out on pin RB4.
 
 I ran the program in my link (in hardware) and I can see PWM pulses on:
 PWM1 - pin 34 - RB1
 PWM3 - pin 36 - RB3
 PWM5 - pin 37 - RB4
 PWM7 - pin 30 - RD7
 
 This is with the 40-pin DIP package of the 18F4431.
 |  | 
	
		|  | 
	
		|  |