Hello all, I'm trying to figure out a way to have a 12F683 take a variable frequency square wave in and generate a pulse train out from two pins. The input would never go above 3Khz and the output would look like this:
pin3-pin2-pin2-pin2-pin2-pin3-pin2-pin2-pin2-pin2-pin3
One pulse from pin 3 and then four pulses from pin 2 all depending on the incoming frequency. The code so far doesn't seem to work very well.
Am I way off here or on the right track?Code:@ __CONFIG _INTOSCIO & _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _BOD_OFF & _CP_OFF & _MCLRE_ON & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF DEFINE OSC 8 ' Internal 8MHz 'DEFINE ADC_BITS 8 ' 8-bit resolution 'DEFINE ADC_CLOCK 2 ' Set clock source to Frc/32 'DEFINE ADC_SAMPLEUS 50 ' Sample time in uS before A/D conversion is started CMCON0 = 7 'Comparators off ADCON0 = %00000000 ANSEL = %00000000 INTCON = 0 'INTERRUPTS off OSCCON = %01110000 '8 Mhz TRISIO = %000100 GPIO = %00000100 OPTION_REG = %00101000 A VAR byte TMR0= 0 ' clear count low GPIO.4 low GPIO.5 input GPIO.2 A=0 main: while TMR0 <= 5 wend TMR0= 0 ' clear count A= A+1 if A = 4 then largepulse pulsout GPIO.5, 100 '500 uS short pulses pin 2 gosub main largepulse: pulsout GPIO.4, 100 '500 uS big pulse pin 3 A=0 return




Bookmarks