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...
I hope the code is reasonably self explanatory.Code:'**************************************************************** ' 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
Thanks for any observations.
bo




Bookmarks