flotulopex
- 19th June 2007, 06:00
Hi there,
I'm stuck in trying to make a multiple alarms-timer based on Melanie's "Olympic Timer".
Doing it the way it is here, the timer will mess-up and the sound stop only after a little time (20 to 40 seconds).
This is probably due to the SOUND command witch takes to much time to execute and blocks the interrupt count or so.
I have the feeling it is not possible to get this working this way.
Can anybody confirm?
I think, I'll better go for a RTC (yes/no)?
' Fuses
@ DEVICE PIC12F675, XT_OSC ;Xtal 4MHz
@ DEVICE PIC12F675, WDT_OFF
@ DEVICE PIC12F675, PWRT_OFF
@ DEVICE PIC12F675, MCLR_ON
@ DEVICE PIC12F675, BOD_OFF
@ DEVICE PIC12F675, PROTECT_OFF
@ DEVICE PIC12F675, CPD_OFF
'-------------------------------------------------------------------------------
' Registers 76543210
CMCON = %00000111 'Comparator OFF
ANSEL = %00000000 'Analog/Digital ports
OPTION_REG = %00000101 'Pull-Ups ENabled, TMR0 prescaler 1:64=16.384 ms
INTCON = %10100000 'GPIO.2 External Interrupt enabled
GPIO = %00000000 'Ports High/Low
TRISIO = %00000000 'Set Input/Output
'-------------------------------------------------------------------------------
' Variables
Ticks var byte
Second var byte
Minute var byte
Hour var byte
Buzzer var GPIO.2
DOutPin var GPIO.1
Update var byte
second = 0
Minute = 0
hour = 0
Update = 0
'-------------------------------------------------------------------------------
' Program
On Interrupt Goto tick_int
MAIN:
if Update = 1 then
update = 0
if second = 0 and minute = 9 and hour = 0 then goto beep1
if second = 0 and minute = 27 and hour = 0 then goto beep1
endif
BEEP1:
sound buzzer,[100,10,50,10]
goto main
end
'-------------------------------------------------------------------------------
' Time Counter - Interrupt Service Routine to handle each timer tick
disable ' Disable interrupts during interrupt handler (or ISR)
TICK_INT:
Ticks = Ticks + 1 'Count pieces of seconds
If Ticks < 61 Then TICK_INT_RESET 'Continue count
' if Ticks >= 61, 1 second elasped => update time
Ticks = 0
Second = Second + 1
If Second >= 60 Then
Second = 0
minute = minute + 1
If minute >= 60 Then
minute = 0
Hour = Hour + 1
Endif
Endif
Update = 1
TICK_INT_RESET:
INTCON.2 = 0 'Reset timer interrupt flag and continue de Ticks count
Resume
enable
I'm stuck in trying to make a multiple alarms-timer based on Melanie's "Olympic Timer".
Doing it the way it is here, the timer will mess-up and the sound stop only after a little time (20 to 40 seconds).
This is probably due to the SOUND command witch takes to much time to execute and blocks the interrupt count or so.
I have the feeling it is not possible to get this working this way.
Can anybody confirm?
I think, I'll better go for a RTC (yes/no)?
' Fuses
@ DEVICE PIC12F675, XT_OSC ;Xtal 4MHz
@ DEVICE PIC12F675, WDT_OFF
@ DEVICE PIC12F675, PWRT_OFF
@ DEVICE PIC12F675, MCLR_ON
@ DEVICE PIC12F675, BOD_OFF
@ DEVICE PIC12F675, PROTECT_OFF
@ DEVICE PIC12F675, CPD_OFF
'-------------------------------------------------------------------------------
' Registers 76543210
CMCON = %00000111 'Comparator OFF
ANSEL = %00000000 'Analog/Digital ports
OPTION_REG = %00000101 'Pull-Ups ENabled, TMR0 prescaler 1:64=16.384 ms
INTCON = %10100000 'GPIO.2 External Interrupt enabled
GPIO = %00000000 'Ports High/Low
TRISIO = %00000000 'Set Input/Output
'-------------------------------------------------------------------------------
' Variables
Ticks var byte
Second var byte
Minute var byte
Hour var byte
Buzzer var GPIO.2
DOutPin var GPIO.1
Update var byte
second = 0
Minute = 0
hour = 0
Update = 0
'-------------------------------------------------------------------------------
' Program
On Interrupt Goto tick_int
MAIN:
if Update = 1 then
update = 0
if second = 0 and minute = 9 and hour = 0 then goto beep1
if second = 0 and minute = 27 and hour = 0 then goto beep1
endif
BEEP1:
sound buzzer,[100,10,50,10]
goto main
end
'-------------------------------------------------------------------------------
' Time Counter - Interrupt Service Routine to handle each timer tick
disable ' Disable interrupts during interrupt handler (or ISR)
TICK_INT:
Ticks = Ticks + 1 'Count pieces of seconds
If Ticks < 61 Then TICK_INT_RESET 'Continue count
' if Ticks >= 61, 1 second elasped => update time
Ticks = 0
Second = Second + 1
If Second >= 60 Then
Second = 0
minute = minute + 1
If minute >= 60 Then
minute = 0
Hour = Hour + 1
Endif
Endif
Update = 1
TICK_INT_RESET:
INTCON.2 = 0 'Reset timer interrupt flag and continue de Ticks count
Resume
enable