Hi Darrel and Hendrick,
I'm still moving along dabbling with this project.
Since I have the 16F887A in a LABX-1 project board, and I had a 12F683 mounted in a bread-board, I decided for convenience to see if I can make another step in this project using the 12F683. I got the 32khz crystal up and running on Timer1. By loading a preset value into Timer1's hi-byte, I can initiate the the frequency counting gate and Timer1 will interrupt right at 1Sec. (close enough on my Oscope).
So then I moved to add using Timer0 as the counter for the external frequency.
I'm only playing with a max input frequency of 300Khz right now, so I can utilize the PICs internal oscillator.
The following code is my progress.
It doesn't yet have the step of capturing the remainder value within Timer0.
Just got the point of attempting to counting Timer0 overflows.
But since I added the Timer0 register settings, it appears that I can't shut off the Timer1 overflow no matter what I do. Its supposed to display the timer0 overflow count and then go into a forever loop. But it keeps popping back up to "Display_Results". So I suspect timer1 is still initiating the interrupt routine.
Code:' Name : Frequency Counter Clock in Timer0 - Gate with Timer1 ' Compiler : PICBASIC PRO Compiler 2.6 ' Assembler : PM or MPASM ' Target PIC : PIC12F683 ' Hardware : 32.768khz crystal on OSC1-ISC2 for 1sec gate ' Oscillator : 4MHz internal osc for PIC ' Keywords : ' Language : PICBASIC PRO ' ' VDD --- 1|----|8--- vSS ' GP5/TICKI/OSC1/CLKIN --- 2|----|7--- GP0/AN0/CIN+/ICSPDAT/ULPWU ' GP4/AN3/T1G/OSC2/CLKOUT --- 3|----|6--- GP1/AN1/CIN-/VREF/ICSPCLK ' GP3/MCLR/VPP --- 4|----|5--- GP2/AN2/T0CKI/INT/COUT/CCP1 '------------------------------------------------------------------------ Include "modedefs.bas" ' Include serial modes for LCD display define osc 4 OSCCON = %01100100 ' internal oscillator at 4 MHZ runs the pic CMCON0 = 7 ' Comparators off ANSEL = 0 ' Set all digital WPU = 0 ' Internal pull-ups = off GPIO = %00000000 ' clear GPIO port TRISIO = %00000100 ' All outputs except gpio.2 (input to frequency) CCP1CON=0 ' ccpm module off LCD var GPIO.1 'use GPIO1 pin 6 to LCD display GATE var byte 'variable for 1 second gate flag TMR_CNT var word 'variable for counting timer0 overflows on interrupt goto TMR1_INT 'setup Timer0 option_register OPTION_REG = %10100111 'bit 7 pullups disabled 'bit 6 don't care 'bit 5 Transition on TOCKI pin 'bit 4 Increment on low to high TOCKI pin 'bit 3 Prescaller assigned to TIMER0 'bit 2-0 Prescaller setting 1:256 INTCON.2 = 0 'set Timer0 ovrflow flag zero TMR0 = 0 'clear the Timer0 counter register 'clear Timer1 interrupt registers T1CON.0 = 0 'TMR1ON disable interrupts for now TMR1L = 0 'clear lower 8 bits of Timer1 counter INTCON = 0 'clear the system interrupt control register PIR1 = 0 'clear the system interrup flag bits register PIE1 = 0 'clear perephrial interrupt enable register pause 1000 'configure Timer1 interrupt settings T1CON.3 = 1 'T1OSC of the T1CON register enabled PIE1.0 = 1 'Timer1 overflow enable bit enabled INTCON.6 = 1 'Perephrial enable bit set to enable INTCON.7 = 1 'GIE Global interrupt enable bit enabled T1CON = 14 'T1OSCEN enable 'T1Sync disabled 'TMR1CS external source for Timer1 TMR1H = 207 'preload hi-byte of Timer1 counter so 'when interrupt occurs with 32khz crystal 'on OSC1 + OSC2, it will be 1 second T1CON.0 = 1 'T1CON.TMR1ON Timer1 enabled *NOW* GATE = 1 main: while GATE > 0 'After 1 Second Gate interrupt this ends @ BTFSC INTCON,2 ;Test Timer0 overflow flag bit @ incf _TMR_CNT,f ;If flag set then increment TMR_CNT by 1 @ BTFSC INTCON,2 ;Test Timer0 overflow flag bit again @ BCF INTCON,2 ;If flag set then clear it wend Display_Results: serout LCD,T9600, [#TMR_CNT] pause 2000 loop_here: goto loop_here ' ************ TIMER1 GATE INTERRUPT ROUTINE AFTER 1 SEC ************** disable TMR1_INT: GATE = 0 T1CON.0 = 0 'TMR1ON disable interrupts for now INTCON = 0 'clear the system interrupt control register PIR1 = 0 'clear the system interrup flag bits register PIE1 = 0 'clear perephrial interrupt enable register INTCON.2 = 0 'set Timer0 ovrflow flag zero INTCON.7 = 0 'GIE OFF - Turn off all Interrupts resume 'goto main End




Bookmarks