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.

PIC timer in assembly

Status
Not open for further replies.

adrianvon

Member
Hi all,

I have a limiter switch which has to be pressed in approximately 20sec after a command is given.

Now i want to include a timer which will start when the command is given and if for some reason the limiter switch is not pressed, a buzzer will start beeping to inform the user.

Is it good to do it as below? or is there a better way to do it?

EDIT: And is there a way to calculate the timer? or maybe how much seconds each decrement takes?

Thanks

Code:
CLRF REG2
CLRF REG3
CLRF REG4
LINE1
BTFSC PORTB,1
GOTO STOP
DECFSZ REG2
BRA LINE1
DECFSZ REG3
BRA LINE1
DECFSZ REG4
BLA LINE1
GOTO BUZZER_ON
 
Last edited:
Hi,
Thanks for the calculator :) and is the coding structurally good? or is there a better way to do it ?

Thanks in advance
 
Not sure which PIC you're working with or what your oscillator speed is, but given a 4MHz Fosc, the instruction clock runs at 1MHz, which is 1 increment per microsecond. Prescale timer 1 with a 1:8 prescale, timer 1 will increment once every 8uS.

Timer 1 being a 16 bit timer, it will increment a total of 65,536 increments before rolling over -

65536 x 8uS = 524mS

So...1.048 seconds will pass every two overflows of timer 1. This means that timer 1 will overflow a total of 40 times in a 20 second period. So if we set up a counter with the value of 40 and we decrement this counter everytime timer 1 overflows, the counter will equal 0 by the time 20 seconds passes. Once the counter is decremented to 0, make the code check the button to see if it's pressed.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top