PDA

View Full Version : First time using comparators DT interrupts



aratti
- 2nd November 2011, 22:51
I am trying some experiments using both comparators on pic 16F88 (mind you my first time), where I need interrupts. It seems I am unable to compile due to some errore with the interrupt.

Below the code and the errors at the end of compilation (same thing with PBP 2.47 and PBP3)



INCLUDE "DT_INTS-14.bas" ; Base Interrupt System
'INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts

DEFINE OSC 20

CMCON = %00000100
TrisA = %00001111
TrisB = %00000000
PortB = 0

Led var PortB.3
Flag var bit
wsave VAR BYTE $70 SYSTEM ' alternate save location for W
Q_New var Byte
Q_Old var byte
Q_Count var word


' Set variable value @ startup

Flag = 0
Q_New = 0
Q_Old = 0
Q_Count = 0


ASM
INT_LIST macro ; IntSource, Label, Type, Resetflag?
INT_Handler CMP1_INT _Encoder, ASM, yes
INT_Handler CMP2_INT _Encoder, ASM, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM


@ INT_ENABLE CMP1_INT ; enable comp1 (INT) interrupts
@ INT_ENABLE CMP2_INT ; enable comp2 (INT) interrupts


Goto Main_Loop


Encoder:

Q_New = CMCON.7 + CMCON.7 + CMCON.6

if Q_Old = 0 then
if Q_New = 2 then Minus_Count
if Q_New = 1 then Plus_Count
endif

if Q_Old = 1 then
if Q_New = 0 then Minus_Count
if Q_New = 3 then Plus_Count
endif

if Q_Old = 3 then
if Q_New = 1 then Minus_Count
if Q_New = 2 then Plus_Count
endif

if Q_Old = 2 then
if Q_New = 3 then Minus_Count
if Q_New = 0 then Plus_Count
endif

goto Q_Skip

Minus_Count:
Q_Count = Q_Count - 1

goto Q_Skip

Plus_Count:
Q_Count = Q_Count + 1

Q_Skip:
Q_Old = Q_New

Led = !Led

@ INT_RETURN

Main_Loop:

goto Main_Loop

end


Surely is something due to my inexperience with comparators, so need some help. Any suggestion is welcome.

Cheers

Al.

Darrel Taylor
- 3rd November 2011, 03:17
Hi Al,

The 16F88 doesn't have separate interrupt flags for the 2 comparators.
Both comparators use the same flag.

So with DT_INTS, use the single CMP_INT handler.

aratti
- 3rd November 2011, 06:50
Thank you Darrel for the quick answer.

Cheers

Al.

aratti
- 3rd November 2011, 16:59
Used CMP_INT without any luck. Stil getting two asm errors :

553 - missing argument
472 - "INT_HANDLER" interrupt flag not found.

Any suggestion?

Cheers

Al.

Darrel Taylor
- 3rd November 2011, 18:01
Al,

I think you just need a comma in your INT_Handler line.

INT_Handler CMP_INT, _Encoder, ASM, yes

aratti
- 3rd November 2011, 19:21
Yes Darrel, it was just the comma missing. Thank you again.

Cheers

Al.