Maximum frequency output from a PIC


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    81

    Default Maximum frequency output from a PIC

    Not too long ago there was a tread in this forum that wasdealing with maximum frequency output from a PIC for any given master clock. Unfortunatelymy searches did not return any good information.

    I’m interested to get a small PIC device (10F or 12F type)to act as a high frequency clock generator using its internal clock and I wouldlike to know what to expect.
    I have an application where the space is very tight and Ineed a modulated clock source with decent stability in the order of hundreds ofkHz but ideal will be 1MHz.

    Using PBP I understand that something like:

    main_loop:
    Togglepin_x
    GOTOmain_loop

    should give maximum frequency output. Assuming that theToggle and GOTO commands will take two cycles each that will give me possibleoutput frequency of Main_clock/4/4 which will be 250 kHz for a 4MHz clock.
    My question is if one uses Assembly (which is not my strongestfield) will it get any faster? Will itbe possible to make it run in the background?
    Ideally I need a 1 MHz output that will be ON for 15 mS andOFF for 5 mS.

    Thank you in advance for any input in this matter.


  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Nick, Here ia a program I wrote a few years ago to take a 10F222 and use it as a modulator for some serial data I was pushing to the surface about 200 feet below the water surface. It worked quite well. As you can see it is done in assembly wrapped inside PBP. I hope this will give you a starting point.

    ' SURFCOMM1.BAS
    ' WRITTEN FOR 10F222
    ' PROGRAM TO SEND:
    'STATUS DATA READING,TEMPERATURE REDAING,SERVO POSITION READING and
    'DEPTH SENSOR READING TO SURFACE @ 1 SECOND INTERVALS. TRANSMIT DATA
    '@ 3000 BAUD MODULATED @ 125Khz.
    '
    ' WRITTEN BY DAVID PUROLA 07/13/2006
    '
    ' INCORPORATED INTO 216229 REV.D "NEW TUBSUB" (12/28/2006)
    '
    DEFINE OSC 8
    '
    ' ************************************************** ******************
    ' Define Port Variables
    ' ************************************************** ******************
    DATA_OUT VAR GPIO.0 '0-MODULATED DATA TO HEAD UNIT
    TXENAB VAR GPIO.1 '1-TRANSMIT ENABLE INPUT
    DATA_IN VAR GPIO.2 '1-INPUT DATA FROM SOURCE
    SPARE3 VAR GPIO.3 '1-

    ' ************************************************** ******************
    ' Declare Variables
    ' ************************************************** ******************
    ' DO NOT CHANGE THESE LINES
    ' ************************************************** ******************
    TRISIO = %11111110 'SET PORT DIRECTION REGISTER
    OPTION_REG = %11000000 'DISABLE PULL-UPS,PSA to TMR0,PSA 1:2
    ADCON0 = %00000000 ' LEFT JUSTIFIED,REF = VDD,Channel 0,A/D Off

    '************************************************* ********************
    LOOP: 'MAIN LOOP FOR PROGRAM
    '************************************************* ********************
    ASM
    BCF GPIO,0 ;DISABLE TRANSMITTER OUTPUT INITIALLY
    NXTPLS BTFSS GPIO,1 ;TEST DATA ENABLE INPUT PIN BIT STATE
    GOTO NXTPLS ;DON'T WAIT FOR PERIOD TO EXPIRE BEFORE TESTING ENABLE BIT
    BTFSC GPIO,2 ;TEST DATA INPUT PIN BIT STATE
    GOTO NXTPLS ;DON'T WAIT FOR PERIOD TO EXPIRE BEFORE TESTING BIT
    BSF GPIO,0 ;IF NOT SET THEN MODULATE OUTPUT (ENABLE OUTPUT PIN)
    NOP ;BIT ON TIME
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    BCF GPIO,0 ;(DISABLE OUTPUT PIN)
    NOP
    GOTO NXTPLS
    ENDASM
    GOTO LOOP
    STOP
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Oct 2012
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Hi Dave,

    Thank you for your sample code.
    I do expect some PIC10F222 any day now and I will start testing with.
    Just to make things easier for me understanding your code what is the output of this piece of code?

    Regards,

    Nick

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Dave, that was a cool project. Did you use a 'depth sounder transducer' to modulate ? They are generally used at 52 and 125KHZ. How far in water do you suppose the signal can travle at that freq ?
    don

  5. #5
    Join Date
    Oct 2012
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    While waiting for my 10F PICs I had a little time today and did some experiments with a PIC12F683.
    Using the internal oscillator set for 4MHz and a close loop with Toggle GPIO.x I was getting in the neighborhood of 70 kHz output and 143 kHz for 8 MHz clock.
    Interestingly enough with simple High / Low GPIO.x loop I got about 200 kHz.

    Then I realized that one of the clock options is to use internal clock with clock/4 on clock out pin. This method got me the 1 MHz output for the 4 MHz internal clock and 2 MHz for the 8 MHz internal clock.

    The oscilloscope shows a pretty steady output and my frequency counter gives about 0.15% error.

    If this will prove to be my path I will use a one gate chip to buffer and modulate the output.

    I still wish I will be able to solve it with only one PIC10F and I will try my best to find a solution.

    Nick

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Hi,
    The toggle command first makes the pin an output, then it reads the state of the pin, then it inverts the state, then it writes the new state to the pin - takes time.
    High/Low first makes the pin an outout then sets the pins state - takes a little less time.
    You'll get more speed of you write to the pin directly
    Code:
    TRISO.0 = 0  'Make pin an output
    DoIt:
    GPIO.0 = 1
    GPIO.0 = 0
    Goto DoIt
    If you can handle some jitter / discontinuity in the output then something likw this will give you even higher average frequency with the drawback that every 6th pulse will be "missing" due to the GOTO.
    Code:
    DoIt:
    GPIO.0 = 1
    GPIO.0 = 0
    GPIO.0 = 1
    GPIO.0 = 0
    GPIO.0 = 1
    GPIO.0 = 0
    GPIO.0 = 1
    GPIO.0 = 0
    GPIO.0 = 1
    GPIO.0 = 0
    Goto DoIt
    Another aproach would be to use the CCP module, though I'm not sure if the 10F series have that built in.

    Of course if all you need is stable 1MHz (or whatever that can be derived from the oscillator) signal then use clock-out option of the chips oscillator.

    /Henrik.

Similar Threads

  1. internal TMR for frequency output
    By Samoele in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th January 2009, 09:38
  2. How to calculate PIC sampling frequency
    By minmin in forum General
    Replies: 1
    Last Post: - 26th September 2006, 18:02
  3. Replies: 2
    Last Post: - 20th January 2006, 21:09
  4. Maximum frequency count on 16F628/4MHz
    By solara in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 23rd May 2005, 10:38
  5. Low frequency output
    By barkerben in forum General
    Replies: 5
    Last Post: - 16th November 2004, 15:25

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts