| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| rrb011270 
 
 
 Joined: 07 Sep 2003
 Posts: 51
 
 
 
			      
 
 | 
			
				| Buzzer Routine Help |  
				|  Posted: Mon Dec 22, 2003 7:28 pm |   |  
				| 
 |  
				| Mabuhay! 
 My buzzer routine below:
 output_high(BUZZER);
 delay_ms(200);
 output_low(BUZZER);
 delay_ms(450);
 
 Is there another way such that I can use interrupt driven o reduce the instruction cycle of this routine?
 
 My application is an RF reader which use an #int_ext2 to capture the ID from the badge.  When it is successfull a buzzer will sound for success.
 
 most of my code use the interrupt handler routine like the clock which use the #int_timer0 such it will capture the time and date and added to a complete packet of data which are compose of date, time, RFid, etc...
 
 Any help will do?
 
 Tenkyu
 |  | 
	
		|  | 
	
		| Mark 
 
 
 Joined: 07 Sep 2003
 Posts: 2838
 Location: Atlanta, GA
 
 
			      
 
 |  | 
	
		|  | 
	
		| rrb011270 
 
 
 Joined: 07 Sep 2003
 Posts: 51
 
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Tue Dec 23, 2003 12:24 am |   |  
				| 
 |  
				| 
 Yes would output for a duration only? Need Help?
 |  | 
	
		|  | 
	
		| Mark 
 
 
 Joined: 07 Sep 2003
 Posts: 2838
 Location: Atlanta, GA
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Tue Dec 23, 2003 8:01 am |   |  
				| 
 |  
				| I like to use timer2 as a 1ms tick.  Most of my software timers are based in milliseconds. 
 
  	  | Code: |  	  | #include <18F452.h>              // Target PIC Microcontroller IC
 #device  *=16                    // use a 16-bit pointer
 #device ICD=TRUE
 
 #fuses HS,NOPROTECT,NOLVP,NOWDT        // PIC MCU Configuration
 
 #use delay(clock=20000000)       // 20MHz Crystal clock speed
 
 // Configure PortA4 for buzzer output
 #bit BUZZER=0xF80.4
 
 int Buzzer_Timer = 0;
 
 #int_timer2
 void tick(void)
 {
 
 if (Buzzer_Timer)
 {
 Buzzer_Timer--;
 if (!Buzzer_Timer)
 {
 output_high(BUZZER);
 }
 }
 }
 
 void Beep(void)
 {
 Buzzer_Timer = 200;
 output_low(BUZZER);
 }
 
 main()
 {
 // Setup timer2 for 1ms intervals
 setup_timer_2(T2_DIV_BY_4,250,5);
 enable_interrupts(int_timer2);
 enable_interrupts(global);
 
 Beep();
 while (1) ;
 }
 
 | 
 |  | 
	
		|  | 
	
		| rrb011270 
 
 
 Joined: 07 Sep 2003
 Posts: 51
 
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Sun Dec 28, 2003 6:56 pm |   |  
				| 
 |  
				| This is what I did for timer2: 
 
  	  | Code: |  	  | 
 #include <18F452.h>              // Target PIC Microcontroller IC
 #device  *=16                    // use a 16-bit pointer
 
 #fuses HS,NOPROTECT,NOWDT        // PIC MCU Configuration
 
 #use delay(clock=20000000)       // 20MHz Crystal clock speed
 
 #define BUZZER PIN_A4            // buzzer to PortA4
 
 #int_timer2
 timer2_isr()
 {
 if (glBuzzerFlag)    // check if buzzer flag bit enable
 {
 if (buzzcnt >= 11)
 {
 output_high(BUZZER);       // buzzer turn-off
 glBuzzerFlag = 0;          // reset flag bit
 }
 buzzcnt++;
 }
 
 if (glBuzzerError)   // check if buzzer error flag bit enable
 {
 if ((buzzcnt >=11) && (buzzcnt < 21))
 output_high(BUZZER);       // turn-off buzzer for ~130msec.
 
 if ((buzzcnt >= 21) && (buzzcnt < 31))
 output_low(BUZZER);        // turn-on buzzer for ~130msec.
 
 if (buzzcnt >= 31)
 {
 output_high(BUZZER);       // buzzer turn-off
 glBuzzerError = 0;         // reset flag bit
 }
 buzzcnt++;
 }
 }
 
 void buzzSound()        // buzzer sounder routine
 {
 output_low(BUZZER);  // turn ON buzzer
 buzzcnt = 0;         // set buzzer time in 100mS per count
 }
 
 void init_chip() {   // Initialize the MCU Chip
 
 setup_adc_ports(NO_ANALOGS);
 setup_timer_2(T2_DIV_BY_16,0xFF,16);   // 6.56mS interupt interval
 enable_interrupts(int_timer2);   // Enable timer2 interrupt
 enable_interrupts(GLOBAL);     // Enable Global interrupt
 }
 
 
 
 | 
 
 Thank u for the help...
 |  | 
	
		|  | 
	
		|  |