Dwayne: I can share the code... it was a "quick and dirty" (and is very reliable) for personal use. The project was rf transmission transmit and receive so you have the working core of the detect and discriminate sequence of the receiver...done on a 12F683 with 16MHz crystal.... Written in Mikroelectronica PIC Basic Pro. Rich 'Dedicated uC to capture RF transmissions, alert main uC that it has new data 'and transfer the data serially to the main uC. Original code from kitchen 'light controller. 'Internal Oscillator w/16MHz crystal oscillator, no MSTRCLR 'Pin2 =3D Clock OUT GPIO.5 'Pin3 =3D Data OUT GPIO.4 'Pin4 =3D Main uC OK to Transmit IN GPIO.3 'Pin5 =3D CCP In; RF IN IN GPIO.2 'Pin6 =3D Oscillator 1 GPIO.1 'Pin7 =3D Oscillator 2 GPIO.0 dim cnt as word 'Ambient light level read counter dim i, j, Number_of_passes as byte 'general purpose variable dim ii, tim, tim1, tim2, tim3, old_tim3 as word dim Dat as byte[11] dim Important_Data as byte[4] dim First_Pass, New_Data_Received as byte sub procedure Preamble_Pulse_Detect '5x 1000uS pulses Initialize_Detect: Number_of_passes =3D 0 Detect: T1CON =3D 0x05 ' TMR1 ON, 1:1 prescaler CCP1CON =3D 0x05 ' CCP Capture mode, every rising e= dge PIR1.5 =3D 0 ' Clear bit 5 TMR1L =3D 0 ' Clear the TMR1L value TMR1H =3D 0 ' Clear the TMR1H value tim1 =3D 0 ' Reset variable while PIR1.5 =3D 0 nop wend if PIR1.5 =3D 1 then ' Capture occured on rising edge TMR1L =3D 0 ' Clear the TMR1L value TMR1H =3D 0 ' Clear the TMR1H value CCP1CON =3D 0x04 ' CCP Capture mode, every falling edge PIR1.5 =3D 0 ' Clear bit 5 (capture occured inf= o) end if while PIR1.5 =3D 0 nop wend if PIR1.5 =3D 1 then ' Capture occured on rising edge tim1 =3D TMR1H<<8 + TMR1L ' Retain TMR1 value =3D ON time CCP1CON =3D 0x05 ' CCP Capture mode, every rising e= dge PIR1.5 =3D 0 ' Clear bit 2 (capture occured inf= o) end if If tim1 <3700 then TMR1L =3D 0 ' Clear the TMR1L value TMR1H =3D 0 ' Clear the TMR1H value tim1 =3D 0 ' Reset variable goto Initialize_Detect end if If tim1 > 4200 then TMR1L =3D 0 ' Clear the TMR1L value TMR1H =3D 0 ' Clear the TMR1H value tim1 =3D 0 ' Reset variable goto Initialize_Detect end if TMR1L =3D 0 ' Clear the TMR1L value TMR1H =3D 0 ' Clear the TMR1H value tim1 =3D 0 ' Reset variable Number_of_passes =3D Number_of_passes + 1 If Number_of_passes <> 5 then goto Detect else goto Preamble_Detected end if goto Initialize_Detect Preamble_Detected: for j =3D 0 to 10 'There are 10 variables for i =3D 0 to 7 'Each is an 8-bit byte T1CON =3D 0x05 'TMR1 ON, 1:1 prescaler CCP1CON =3D 0x05 'CCP Capture mode, every rising ed= ge PIR1.5 =3D 0 'Clear bit 2 TMR1L =3D 0 'Clear the TMR1L value TMR1H =3D 0 'Clear the TMR1H value tim1 =3D 0 'Reset variable while PIR1.5 =3D 0 nop wend if PIR1.5 =3D 1 then 'Capture occured on rising edge TMR1L =3D 0 'Clear the TMR1L value TMR1H =3D 0 'Clear the TMR1H value CCP1CON =3D 0x04 'CCP Capture mode, every falling e= dge PIR1.5 =3D 0 'Clear bit 2 (capture occured info= ) end if while PIR1.5 =3D 0 nop wend if PIR1.5 =3D 1 then 'Capture occured on rising edge tim1 =3D TMR1H<<8 + TMR1L 'Retain TMR1 value =3D ON time CCP1CON =3D 0x05 'CCP Capture mode, every rising ed= ge PIR1.5 =3D 0 'Clear bit 2 (capture occured info= ) end if If tim1 < 550 then Dat[j].i =3D 0 else Dat[j].i =3D 1 end if next i next j end sub sub procedure Transmit_to_uC cnt =3D 0 'Pin2 =3D Clock OUT GPIO.0 'Pin3 =3D Data OUT GPIO.1 'Pin4 =3D uC2 OK to Transmit IN GPIO.3 Start_Transmit: GPIO.0 =3D 1 'Notify uC of new data while GPIO.3 =3D 0 'Wait for uC to reply nop wend for j =3D 0 to 3 'There are 10 variables for i =3D 0 to 7 'Each is an 8-bit byte GPIO.1 =3D Important_Data[j].i GPIO.0 =3D 0 'Bit set and ready for transfer while GPIO.3 =3D 1 'Wait for uC to reply with "0" nop wend GPIO.0 =3D 1 while GPIO.3 =3D 0 'Wait for uC to reply nop wend next i next j GPIO.0 =3D 0 while GPIO.3 =3D 1 cnt =3D cnt + 1 delay_us(120) if cnt > 220 then cnt =3D 0 goto Finish_Transmit end if wend Finish_Transmit: cnt =3D 0 end sub main: CMCON0 =3D %00000111 'Comparators OFF ADCON0 =3D %00000000 'All pins digital ANSEL =3D %00000000 'All pins digital OPTION_Reg =3D 7 TRISIO =3D %00011100 INTCON =3D %11000000 GPIO =3D 0 'Baseline Output cnt =3D 0 First_Pass =3D 0 New_Data_Received =3D 0 delay_ms(100) Important_Data[0] =3D %10011101 Important_Data[1] =3D 0 Important_Data[2] =3D 0 Important_Data[3] =3D 0 Operate: Preamble_Pulse_Detect 'If 5 1000uS pulses are not detected, reset '______________________________Collect Pertinent Data__________________________ If Dat[0] =3D 204 then 'Dat[0] =3D $CC tim2 =3D Dat[1] +Dat[2] +Dat[3] +Dat[4] +Dat[5] +Dat[6] +Dat[7] +Dat[8= ] +Dat[9] 'CRC checksum calculation If Dat[10] =3D tim2 then 'Data is OK New_Data_Received =3D 1 Important_Data[0] =3D Dat[1] 'Average Outside Temperature Important_Data[1] =3D Dat[2] 'Hour (24 Hr format) Important_Data[2] =3D Dat[3] 'Minute (0-59) Important_Data[3].0 =3D Dat[6].0 'Porch Contoller POWER Status Important_Data[3].1 =3D Dat[6].1 'Vacation Mode Status Important_Data[3].2 =3D Dat[6].4 'Porch Occupied (Novitas Signal) end if end if If Dat[0] =3D 238 then 'Dat[0] =3D $EE tim2 =3D Dat[1] +Dat[2] +Dat[3] +Dat[4] +Dat[5] +Dat[6] +Dat[7] +Dat[8= ] +Dat[9] 'CRC checksum calculation If Dat[10] =3D tim2 then New_Data_Received =3D 1 Important_Data[3].3 =3D Dat[7].0 'Alarm Status (ON or OFF) end if end if If New_Data_Received =3D 1 then New_Data_Received =3D 0 tim3 =3D Important_Data[0] + Important_Data[1] + Important_Data[2] + Important_Data[3] If First_Pass =3D 0 then First_Pass =3D 1 old_tim3 =3D tim3 'Establish reference data value Transmit_to_uC 'Send first data to uC end if If old_tim3 <> tim3 then old_tim3 =3D tim3 'Update reference data value Transmit_to_uC 'Send new data to uC end if end if goto Operate end. -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of Dwayne Reid Sent: Monday, July 21, 2014 11:45 AM To: Microcontroller discussion list - Public. Subject: RE: [PIC] Looking for frequency counter software Many thanks! There isn't anything wrong with using Basic. One of the best (and fastest) programmers that I have ever worked with does all of his PIC stuff using PIC Basic Pro from MELabs. He does most of his other stuff in C but seems to prefer PIC Basic for his PIC stuff. It works very well for him. dwayne PS - are you free to share your entire project? dwayne At 06:24 AM 7/19/2014, Richard Pytelewski wrote: >Dwayne: > >Just finishing project with similar reqt's. Using the CCP in Capture >mode, and using TMR1, you can get excellent results. FWIW: use a good >high freq crystal.... my measurements are in microseconds and anything >but a crystal will yield inconsistent results. > >I use ME Basic (OK, I know, BASIC is not cool) but here is my working >code that may provide a start > >Detect: > T1CON =3D 0x05 ' TMR1 ON, 1:1 pre-scaler > CCP1CON =3D 0x05 ' CCP Capture mode, every rising edge > PIR1.5 =3D 0 ' Clear bit 5 > TMR1L =3D 0 ' Clear the TMR1L value > TMR1H =3D 0 ' Clear the TMR1H value > tim1 =3D 0 ' Reset variable > while PIR1.5 =3D 0 > nop > wend > if PIR1.5 =3D 1 then ' Capture occurred on rising edg= e > TMR1L =3D 0 ' Clear the TMR1L value > TMR1H =3D 0 ' Clear the TMR1H value > CCP1CON =3D 0x04 ' CCP Capture mode, every fallin= g >edge > PIR1.5 =3D 0 ' Clear bit 5 (capture occurred info) > end if > while PIR1.5 =3D 0 > nop > wend > if PIR1.5 =3D 1 then ' Capture occurred on rising e= dge > tim1 =3D TMR1H<<8 + TMR1L ' Retain TMR1 value =3D ON time > CCP1CON =3D 0x05 ' CCP Capture mode, every rising edge > PIR1.5 =3D 0 ' Clear bit 2 (capture occurred info) > end if > If tim1 <3700 then > TMR1L =3D 0 ' Clear the TMR1L value > TMR1H =3D 0 ' Clear the TMR1H value > tim1 =3D 0 ' Reset variable > goto Initialize_Detect > end if > >Rich > >-----Original Message----- >From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On >Behalf Of Dwayne Reid >Sent: Friday, July 18, 2014 9:01 PM >To: pic microcontroller discussion list >Subject: [PIC] Looking for frequency counter software > >Good day to all. > >The recent discussion about controlling the frequency of a signal >generator reminded me of a project that I've been meaning to do for >years. But it's been sitting for so long that I should see if anyone >has done anything similar to what I want. > >I have a couple of older BK Precision function generators. These cover >the range of sub-Hz through, I think, 5 MHz. They work well but suffer >one tragic flaw: it is not possible to know what frequency you are >generating without using an external frequency counter or scope. > >I want to add a digital frequency readout to these units. There is >space in the upper-left corner of the front panel that is just crying >out for some form of readout. > >I've seen a couple of frequency meter projects over the past few years >- most are simple and use a PIC's TMR0 and its' prescaler to measure a >signal up to 50 MHz. But I'm picky. I want something that measures >and displays frequency when the generator freq is above, say, 1 KHz but >measures period and converts that period measurement to frequency at >lower freqs. This allows quick display updates even when generating low-frequency signals. > >Bonus points if the unit can also measure and display period as well as >both positive and negative pulse width. > >I could write it myself but surely someone has already done something >similar to this. I hope. > >Any thoughts? > >Many thanks! > >dwayne > >-- >Dwayne Reid >Trinity Electronics Systems Ltd Edmonton, AB, CANADA >(780) 489-3199 voice (780) 487-6397 fax >www.trinity-electronics.com >Custom Electronics Design and Manufacturing > >-- >http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >View/change your membership options at >http://mailman.mit.edu/mailman/listinfo/piclist > >-- >http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive >View/change your membership options at >http://mailman.mit.edu/mailman/listinfo/piclist -- Dwayne Reid Trinity Electronics Systems Ltd Edmonton, AB, CANADA (780) 489-3199 voice (780) 487-6397 fax www.trinity-electronics.com Custom Electronics Design and Manufacturing -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/chang= e your membership options at http://mailman.mit.edu/mailman/listinfo/piclist -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .