Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Will this Delay effects to the accuracy? - PIC16F84A

Status
Not open for further replies.

Gayan Soyza

Active Member
Hi guys after a long time.this time i'm building a single digit clock,the original is from nixie.the original code works well.but i had to make some changes in the codings for my satisfaction.

To increment the digits TMR0's prescaler is assigned to 1:32.TOIF polling method has used in this.some TICKS have used in "Real-time clock algorithm" to get a correct count.

My problem is i need to make a sound for every hour (RB6 is a spare pin in the cct so i connected a piezo to it).

I have added a small coding in the "Real-time clock algorithm" section to get a BEEP in every hour.the BEEP's duraion is one second.like this below & the edited file is in the attachment.

Code:
;*********MAKE A SMALL BEEP IN EVERY HOUR*********************

	CALL	BEEP
	CALL	DEL1SEC		;DURATION OF THE BEEP 1SECOND

;*************************************************************
will this BEEP delay can effect to the time????
I mean for every hour will it reduce by one second???

If so how can I add a Beep without disturbing the time.where is the best place to put that BEEP?
 

Attachments

  • source code.txt
    9.3 KB · Views: 164
Yes it's going to effect the timing. You're using too many delay loops, it's incredibly inefficient way to program and causes huge problems with timing sensitive programs like this. You need to run the main clock timer as an interrupt routine instead of a polled routine. I don't think interrupts on the PIC can be stacked so you just have to make sure that none of the rest of your code can prevent the processor from interrupting. Interrupts can get a little tricky if you use a lot of them but as long as you're only using a single timer overflow interrupt (especially one that occurs only once a second) it's really pretty easy.
 
Last edited:
If for whatever reason you simply don't want to use an interupt and are just looking for a quick and dirty fix for your code all you have to do is change the delay on the beep to a half second, that way you can be sure you won't miss any timer overflows. Besides, most hour notification beeps on clocks I've heard are only 1/4 second long 1/2 at most unless you want it to be really annoying.
 
Another alternative is to turn the buzzer on when the hours increment and turn it off when the seconds increment. That way it will sound for 1 second every hour without a delay anywhere.

Mike.
 
The codes not particular user friendly when the timer is poled though. Wastes huge amounts of processor time. Even if it's just a one off project for kicks it's 'bad form' to program like that. If it's a school project about all it's gonna get you is a basic 'project complete acording to guidelines' and not actually teach you anything of use.
 
Sceadwian said:
The codes not particular user friendly when the timer is poled though. Wastes huge amounts of processor time. Even if it's just a one off project for kicks it's 'bad form' to program like that. If it's a school project about all it's gonna get you is a basic 'project complete acording to guidelines' and not actually teach you anything of use.

You need to consider where the code has probably come from - low-end PIC's don't have interrupts - the code was probably ported from a low-end OTP device.

In this case (as in many cases) it makes no difference whatsoever anyway, the only difference is where it's wasting the time!.
 
Thanks for the advices.In this case I would prefer pommie's method without using any delay loops and taking the advantage of the runing time.its enough me to turn a pin to HIGH for a simple BEEP.B'cuz I'm not going to to put a string in that time period to get a tune.I just needed a BEEP.so inside the call BEEP it will have only BSF PortB,6.

I applied the method in the "Real-time clock algorithm" section & checked.Like this.

Code:
CLOCK   MOVLW   TCK0            ; increment digits as appropriate
	MOVWF   TICKS           ; and define number of ticks per second 
				; for next second
	[B]BCF	06H,6		; TURN OFF BEEP[/B]
	INCF    SEC,1          
	MOVF    SEC,0
	SUBLW   0X09
	BTFSC   STATUS,0
	RETURN

	MOVLW   TCK1
	MOVWF   TICKS
	CLRF    SEC
	INCF    SEC10,1
	MOVF    SEC10,0
	SUBLW   0X05
	BTFSC   STATUS,0
	RETURN

	MOVLW   TCK2
	MOVWF   TICKS
	CLRF    SEC10
	INCF    MIN,1
	MOVF    MIN,0
	SUBLW   0X09
	BTFSC   STATUS,0
	RETURN

	MOVLW   TCK3
	MOVWF   TICKS
	CLRF    MIN
	INCF    MIN10,1
	MOVF    MIN10,0
	SUBLW   0X05
	BTFSC   STATUS,0
	RETURN

	MOVLW   TCK4
	MOVWF   TICKS
	CLRF    MIN10
	MOVF    HOUR10,0
	SUBLW   0X00		
	BTFSC   STATUS,0
	GOTO    INCHR
	[B]BSF	06H,6		;BEEP ON[/B]
	INCF    HOUR,1
	MOVF    HOUR,0
	SUBLW   0X02
	BTFSC   STATUS,0
	RETURN

	MOVLW   TCK6
	MOVWF   TICKS
	CLRF    HOUR
	[B]BSF	06H,6		;BEEP ON[/B]
	INCF	HOUR,1
	CLRF    HOUR10
	RETURN

INCHR   [B]BSF	06H,6		;BEEP ON[/B]
	INCF    HOUR,1
	MOVF    HOUR,0
	SUBLW   0X09
	BTFSC   STATUS,0
	RETURN

	MOVLW   TCK5
	MOVWF   TICKS
	CLRF    HOUR
	[B]BSF	06H,6		;BEEP ON[/B]
	INCF    HOUR10,1
	RETURN
But still I cannot get a output from RB6 for every hour.any suggesions??
 

Attachments

  • clock(Beep).txt
    8.1 KB · Views: 175
I found the solution for my BEEP problem while making some experiments in the coding.the code has to correct like this.
Code:
MAIN    CALL    CLOCK           
	CALL    SHOW            
	[B]BCF	06H,6		;TURN OFF BEEP[/B]
WAIT    BTFSS   INTCON,2        
	GOTO    WAIT
	CLRF    INTCON
	CALL    CHKSW           
	DECFSZ  TICKS,1
	GOTO    WAIT
	GOTO    MAIN            


CLOCK   MOVLW   TCK0            
	MOVWF   TICKS           
	INCF    SEC,1          
	MOVF    SEC,0
	SUBLW   0X09
	BTFSC   STATUS,0
	RETURN

	MOVLW   TCK1
	MOVWF   TICKS
	CLRF    SEC
	INCF    SEC10,1
	MOVF    SEC10,0
	SUBLW   0X05
	BTFSC   STATUS,0
	RETURN

	MOVLW   TCK2
	MOVWF   TICKS
	CLRF    SEC10
	INCF    MIN,1
	MOVF    MIN,0
	SUBLW   0X09
	BTFSC   STATUS,0
	RETURN

	MOVLW   TCK3
	MOVWF   TICKS
	CLRF    MIN
	INCF    MIN10,1
	MOVF    MIN10,0
	SUBLW   0X05
	BTFSC   STATUS,0
	RETURN

	MOVLW   TCK4
	MOVWF   TICKS
	CLRF    MIN10
	MOVF    HOUR10,0
	SUBLW   0X00		
	BTFSC   STATUS,0
	GOTO    INCHR
	INCF    HOUR,1
	MOVF    HOUR,0
	SUBLW   0X02
	BTFSC   STATUS,0
	[B]GOTO	BEEP		;GOTO BEEP[/B]

	MOVLW   TCK6
	MOVWF   TICKS
	CLRF    HOUR
	INCF	HOUR,1
	CLRF    HOUR10
	[B]GOTO	BEEP		;GOTO BEEP[/B]

INCHR   INCF    HOUR,1
	MOVF    HOUR,0
	SUBLW   0X09
	BTFSC   STATUS,0
	[B]GOTO	BEEP		;GOTO BEEP[/B]

	MOVLW   TCK5
	MOVWF   TICKS
	CLRF    HOUR
	INCF    HOUR10,1
	[B]GOTO	BEEP		;GOTO BEEP[/B]

;---------LENGTH OF THE BEEP----------------

[B]BEEP	BSF	PORTB,6
BDEL1	DECFSZ 	1AH,1		;255 LOOPS
	GOTO	BDEL1
	BCF	PORTB,6
BDEL2	DECFSZ 	1AH,1		;255 LOOPS
	GOTO	BDEL2
	DECFSZ	LENGTH		;LENGTH=40H (MAKES 40 TIMES ON OFF)
	GOTO	BEEP
	RETURN[/B]

;-------------------------------------------
The output is not an audio frequency, it is a simple logic pulse, so one would need a tone or chime generator for the audio.

Which is best way to turn on a buzzer through a delay loop like I did (below 1second) or through a chime generator?

Do you satisfy with my BEEP codings?

Please reply me
 
What PIC are you using?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top