| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			akin54
 
 
  Joined: 11 Jan 2021 Posts: 7
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| GENERATING PWM USING THE TIMER | 
			 
			
				 Posted: Fri Mar 04, 2022 12:27 am     | 
				     | 
			 
			
				
  | 
			 
			
				Hello everyone.
 
I want to generate pwm from this processor (PIC12F683) without using the ccp1 leg. I want to use the GP5(A5) pin for this operation. The electronic card circuit I have drawn does not allow other conditions. When I try to generate pwm with interrupt using timer, the while loop of my program starts to crash. While I am creating a continuous pwm signal, I want to operate comfortably in my while loop. I would be glad if you help. Thanks in advance.
 
 
 
 
 	  | Code: | 	 		  #include <12F683.h>
 
#device ADC=10
 
#use delay(internal=8000000) | 	  
 
 
 	  | Code: | 	 		  #include <main.h>
 
#FUSES NOMCLR                                         //MCLR = A3 pin
 
void main()
 
{
 
   setup_adc_ports(sAN2, VSS_VDD);
 
   setup_adc(ADC_CLOCK_DIV_2);
 
   port_a_pullups(0x0A);
 
   set_tris_a(0x0E);
 
   output_a(0x00);                        
 
   while(TRUE)
 
   {
 
      if(input(pin_a3)==0)
 
      {
 
         output_high(pin_a1);
 
         delay_ms(1000);
 
         output_low(pin_a1);
 
      }
 
   }
 
} | 	 
  _________________ @electsoftware | 
			 
		  | 
	
	
		  | 
	
	
		
			PCM programmer
 
 
  Joined: 06 Sep 2003 Posts: 21708
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Mar 04, 2022 1:08 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Quote: | 	 		  
 
When I try to generate pwm with interrupt using timer, the while loop 
 
of my program starts to crash.
 
 | 	  
 
Post your code for the timer interrupt.  Post the code in main() that
 
enables it, and post the interrupt routine.  You left that code out of
 
your posted program.
 
 
 	  | Quote: | 	 		  |  port_a_pullups(0x0A);  | 	  
 
Here, you think a weak pullup is enabled on pins A1 and A3.
 
But pin A3 doesn't have that ability.  Look at this diagram on page 36:
 
REGISTER 4-4: WPU: WEAK PULL-UP REGISTER
 
It shows no pullup is available on pin A3 when using the NOMCLR fuse.
 
12F683 data sheet:
 
https://ww1.microchip.com/downloads/en/DeviceDoc/41211D_.pdf
 
 
 
This line sets all pins as outputs, unless you have a secret 
 
#use fast_io(a) statement that you didn't post. | 
			 
		  | 
	
	
		  | 
	
	
		
			akin54
 
 
  Joined: 11 Jan 2021 Posts: 7
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Mar 04, 2022 1:49 am     | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Code: | 	 		  #include <main.h>
 
#FUSES NOMCLR                                         //MCLR = A3 pin
 
#int_timer2
 
void timer2 () 
 
{
 
output_high(pin_a5); 
 
delay_us(12);
 
output_low(pin_a5); 
 
}
 
void main()
 
{
 
   setup_timer_2(T2_DIV_BY_1,1,1);
 
   setup_adc_ports(sAN2, VSS_VDD);
 
   setup_adc(ADC_CLOCK_DIV_2);
 
   port_a_pullups(0x02);
 
   set_tris_a(0x0E);
 
   output_a(0x0E);   
 
   enable_interrupts(INT_timer2) ;
 
   enable_interrupts(GLOBAL);
 
   while(TRUE)
 
   {
 
      if(input(pin_a3)==0)
 
      {
 
         output_high(pin_a0);
 
         delay_ms(1000);
 
         output_low(pin_a0);
 
      }
 
   }
 
} | 	 
  _________________ @electsoftware | 
			 
		  | 
	
	
		  | 
	
	
		
			akin54
 
 
  Joined: 11 Jan 2021 Posts: 7
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Fri Mar 04, 2022 1:50 am     | 
				     | 
			 
			
				
  | 
			 
			
				Yes, now I see. I made the MCLR pin a hardware button. _________________ @electsoftware | 
			 
		  | 
	
	
		  | 
	
	
		 |