Hi,
Using 16F627A with 4MHz resonator.
I am having lots of issues here I don't know where to start...
Ok I am driving an ultrasonic Transducer from RB3 and RA3
RB3 is sending HWPM to one pin of the Tx and also feeding RA0 (the input of the chip's comparator. The inverted output (RA3) is connected to the other pin of the Tx.
The Rx is on a different circuit, amplified and going through an external comparator and the final output fed into RB0.
Mesurments on the scope is as expected, see bellow:
CH1 is the 40KHz burst lasting 169uS
CH2 is the signal from the Rx showing my sealing at about 6 feet high.
The time scale is 2.5mS
and this is my code:
If I REM-out INT_INT or TMR1_INT I endup getting either nothing on the scope orthe HPWM burst is nonstop. For one thing I know I have to somehow define the 60mS timeout for TMR1 but I can't figure it out.Code:@ __config _XT_OSC & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF DEFINE OSC 4 FLAGS = 0 TRISA = %10111 TRISB = %00000001 CMCON = %110 ;T1CON.0=1 ; Start timer1 ;INTCON = %10011000 TMR1H = 0:TMR1L = 0 INCLUDE "DT_INTS-14.bas" ; Base Interrupt System INCLUDE "ReEnterPBP.bas" ; Include if using PBP interrupts ASM INT_LIST macro ; IntSource, Label, Type, ResetFlag? INT_Handler INT_INT, _SignalDetect, PBP, yes INT_Handler TMR1_INT, _SignalTimeOut, PBP, yes endm INT_CREATE ; Creates the interrupt processor ENDASM ;@ INT_ENABLE INT_INT ; enable external (INT) interrupts ;@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts ;-------------------temp lcd display ---------------------------- LCD_DB4 VAR PORTB.4 ; Set port for 4 bits bus LCD_DB5 VAR PORTB.5 LCD_DB6 VAR PORTB.6 LCD_DB7 VAR PORTB.7 LCD_RS VAR PORTB.2 ; Set RS bit port LCD_E VAR PORTB.1 ; Set Enable bit port LCD_Lines CON 2 ; # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines) LCD_DATAUS CON 50 ; Data delay time in us LCD_COMMANDUS CON 2000 ; Command delay time in us INCLUDE "LCD_AnyPin.pbp" ; Must go after LCD initialization Pause 500: LCDOUT $FE,1: pause 250 LCDOUT $FE,$80,"Display test OK" ;------------------------lcd-------------------------------------- Goto main Main: hpwm 1, 127,40000 ; Send burst, Ch1, D.Cycle50%, Freq 40Khz pauseus 169 ; length of burst. CCP1CON = 0 ; Stop sending HPWM pauseus 950 ; To prevent Rx from picking up local burst pause 60 goto main '---[INT - interrupt handler]-------Got Signal within 60mS SignalDetect: @ INT_DISABLE INT_INT @ INT_DISABLE TMR1_INT LCDOUT $FE,$C0,dec TMR1H," " pause 500 @ INT_ENABLE INT_INT @ INT_ENABLE TMR1_INT @ INT_RETURN '---[TMR1 - interrupt handler]------TMR1 Overflow, got no signal SignalTimeOut: @ INT_DISABLE INT_INT @ INT_DISABLE TMR1_INT LCDOUT $FE,$C0,"No Signal" pause 500 LCDOUT $FE,$C0," " @ INT_ENABLE INT_INT @ INT_ENABLE TMR1_INT @ INT_RETURN end
To make a long story short, I would like to accomplish 2 things:
1 - Use INT_INT to pick up the signal from the Rx at RB0 and calculate the distance based on TMR1.
2 - If I get no signal after 60mS I would like to use TMR1_INT to display a different mesage.
I think my code looks simple but obviously too good to be true.
Hopefully someone can help.
Thanks
Mike




Bookmarks