PDA

View Full Version : 16F88 and TMR0 Interrupt - where's the fish?



flotulopex
- 4th November 2007, 19:44
Hello,

I just sublimized my two last 16F690 and had to replace and adapt the code to my old 16F88... ones...

Since I did so, I can't make the INTerrupt routine work anymore.

I compared with former programs I made and can't find the difference.

Why isn't it working; where's the fish?

' Fuses
@ DEVICE HS_OSC
@ DEVICE PROTECT_OFF
@ DEVICE WDT_ON
@ DEVICE PWRT_ON
@ DEVICE MCLR_OFF
@ DEVICE BOD_OFF
@ DEVICE LVP_OFF
@ DEVICE CPD_OFF
@ DEVICE DEBUG_OFF
@ DEVICE CCPMX_OFF

'-------------------------------------------------------------------------------
' Registers 76543210
OPTION_REG = %10000000 'PORTB Pull-Ups disabled
OSCCON = %00000000 'Internal RC set External Xtal
ANSEL = %00000000 'Disable analog inputs
ADCON0 = %00000000 'A/D Module is OFF
CMCON = %00000111 'Comparator Module is OFF
INTCON = %10100000 'Set Interrupts
TRISA = %00000000 'Set Input/Output
PORTA = %00000000 'Ports High/Low
TRISB = %00000000 'Set Input/Output
PORTB = %00000000 'Ports High/Low

'-------------------------------------------------------------------------------
' Variables
Ticks var byte
Second var byte
Minute var byte
Hour var byte
LED1 var PORTB.5
LED2 VAR PORTB.4

'-------------------------------------------------------------------------------
' Program
clear
On Interrupt Goto tick_int

TEST:
if second = 2 then
second = 0
toggle led1
goto test
endif
end

'-------------------------------------------------------------------------------
disable
TICK_INT:
Ticks = Ticks + 1
If Ticks < 61 Then TICK_INT_RESET
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
toggle led2 'control LED - blink every second

TICK_INT_RESET:
INTCON.2 = 0

Resume
enable

Bruce
- 4th November 2007, 20:47
Hi Roger,

You have an END there so it's putting the PIC to sleep unless second = 2

Replace the END with GOTO TEST.

Also you have no DEFINE OSC so it's using the default speed of 4MHz.

It works fine if I add DEFINE OSC 20 and GOTO TEST VS END.

flotulopex
- 4th November 2007, 21:15
That was so obvious!!! Where are my glasses...

Thanks a lot, Bruce, I pasted this GOTO TEST one line to early ;)

By the way, any idea why my PIC seems to be running much faster than 4MHz?

I use a 4MHz Xtal.

As you mentionned, there is no DEFINE OSC in my code. So my PIC should run at the Xtal's speed, no?

Bruce
- 4th November 2007, 21:19
Try XT_OSC. May be over-driving your 4MHz crystal and producing some odd harmonics?

flotulopex
- 4th November 2007, 21:33
First thing I tried when I noticed...

No change. Just strange.

I even removed the Xtal and set the internal oscillator to 4MHz... Still running appearently very fast.

Have to check.

Bruce
- 4th November 2007, 21:58
Why it appears to be running faster I can't say. What are you placing in OSCCON?

flotulopex
- 5th November 2007, 06:54
I set bits <2:0> to specify the oscillator's mode selection (set in the config Word).

Oooops! Just found I forgot to set the TMR0 prescaler rate in the OPTION_REG register...

Everything is fine now.

Thanks a lot.