PDA

View Full Version : 12F683, DT_INTs, and Lost pulses



boroko
- 3rd September 2020, 11:06
Hi All,

Been fighting with unpredictable behavior on a project and need some fresh eyes.
Here is the minimal subset of the program that I'm fighting.
Without any pulses on the input, I get a steady output on the Heartbeat LED (HI in this case). As soon as there is a pulse on the input (1Hz-250Hz+), I get the heartbeat, and the LED showing entry into the INT handler. As soon as the input pulse goes to 0 again, everything stops.
Very puzzled...

'************************************************* ***************
' 12F683 default 4MHz, running 8MHz
' ------------u-----------
' -|vdd (+) vss(-) |-
' LED out -|gp5 p_a0/pgd |- Pulse in
' -|p4/a4 p_a1/pgc |- LED2 out
' -|p3/Vpp/MCLR p_a2/ccp1 |-
' ------------------------
'************************************************* ***************
#CONFIG
__config _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF
; __config _FOSC_INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF
#ENDCONFIG
INCLUDE "DT_INTS-14.pbp" ; Base Interrupt System. Ver 1.10
INCLUDE "ReEnterPBP.pbp" ; Include for DT_INTS. ver 3.4
'************************************************* **************************
define OSC 8 ' tell compiler that OSC is 8MHz
IN var GPIO.0 ' monitor Input pulse
LED2 var GPIO.1 ' INT function LED
LED var GPIO.5 ' Heartbeat LED
Cnt var word ' word var for TMR1 high and low bytes
PulseFlag var byte '

OSCCON = %01110000 ' 8MHz instead of 4MHz
'INTCON = %11001000 ' GIE,PEIE:ON, T0IE,INTE:OFF, GPIE:ON, TOIF,INTF,GPIF:CLEAR
IOC = %00000001 ' Enable IOC on GPIO0 to capture pulse
T1CON = %00000001 ' TMR1 prescale=1:1 clock=Fosc/4, TMR1=on
GPIO = %00001001 ' Outputs (except 0&3) = 0 on bootup
OPTION_REG = %00000110 ' ind pull-ups, int clk,Tmr0=1:(111=256, 110=128)
TRISIO = %00001001 ' Pins output(except 0&3)
CMCON0 = %00001111 ' Comparator off. NEEDED to avoid RWM problem
ANSEL = %00000000 ' Set all digital
;----[Interrupts]----------------------------------------
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler GPC_INT, _Capture, PBP, yes
endm
INT_CREATE ; Creates the High Priority interrupt processor
INT_ENABLE GPC_INT ; enable Capture interrupts
ENDASM

Main:
toggle LED ' heartbeat
pause 10
if PulseFlag then
toggle LED2
PulseFlag = 0
endif
GOTO Main
'---[IOC - interrupt handler]------------------------------------------
Capture: ' Enter here with Pulse (IOC)
PulseFlag = 1 ' Caught a pulse
Cnt.highbyte = TMR1H ' grab TMR1
Cnt.lowbyte = TMR1L ' Cnt stays the same until the next pulse.
T1CON.0=0 ' Turn TMR1 off
TMR1H = 0 ' clear TMR1
TMR1L = 0 '
T1CON.0=1 ' Turn TMR1 on
PIR1.0 = 0 ' Clear TMR1IF.
@ INT_RETURN

END

I hope the code is reasonably self explanatory.
Thanks for any observations.
bo

richard
- 3rd September 2020, 12:23
you cannot clear the gpio change flag until you read the gpio port



Capture: ' Enter here with Pulse (IOC)
PulseFlag = 1 ' Caught a pulse
Cnt.highbyte = TMR1H ' grab TMR1
Cnt.lowbyte = TMR1L ' Cnt stays the same until the next pulse.
T1CON.0=0 ' Turn TMR1 off
TMR1H = 0 ' clear TMR1
TMR1L = 0 '
T1CON.0=1 ' Turn TMR1 on
PIR1.0 = 0 ' Clear TMR1IF.
tmp=gpio.0

@ INT_RETURN

boroko
- 3rd September 2020, 15:43
(beating head against wall) Thank you Richard. For the life of me, I couldn't see that. Saw your reply, and DUH, of course.
I appreciate the help.

bo

Fujimanme
- 8th October 2020, 22:39
Hello Bo,

Were you able to get your 12F683 working? I am also using a 12F683 for a remote pressure sensor application but I am unable to compile the code as I get the interrupt error.

ERROR: Variable wsave2 position request 288 beyon RAM_END 191.

I have edited the DT_INTS-14.bas and left the wsave $20 and wsave $A0 enable, but alas still no go.

I know my setup is OK because if I grab an older code I was playing with years ago with DT Interrupts for 16F648A, it successfully compiles without any issues and I can program it to the PIC...

Cheers
Attila

boroko
- 11th October 2020, 12:07
I have been working on the bigger chips for this project to get some other features. I'm going back to the 12F683 to use what I learned. If I get an answer, I'll let you know.

Is it the INT on change that you are trying to use?

bo