Maximum frequency output from a PIC


Closed Thread
Results 1 to 40 of 69

Hybrid View

  1. #1
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    As the wise man once said “necessity is the mother of invention”.
    I’m sure that it will take you no time to build a “tool” to solve your problem. What about employing one more PIC to do the job for you? Set it up to count incoming pulses from your DUT for a set period of time and send the results to a LCD or to your preferred PC communication terminal for a visual. You just built yourself a home made, dirty cheap frequency counter ready to solve your problem now and help you in the future.
    Just a thought.
    Some experimenting and results in that matter were done in the beginning of this thread but unless you are starting with a really high clock flexibility is not that great. I’m not sure if the Assembly approach will bring any more advantage but, again it is out of my league.


    Regards,

    Nick

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Looks like I'll have to.
    I always thought if I have a 5 Volt square wave,
    that my multimeter would measure it as 2.5 Volts.
    I never considered the sampling frequency of the multimeter has
    no connection with the frequency of the signal being measured.

  3. #3
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Hi again,

    I’m trying to move what I learned last week to a larger PIC (PIC16F819) which I have a lot of leftovers and I’m trying to make use of. I’m also trying to increase my output frequency by using a 16MHz oscillator.

    Based on what the data sheet shows I should have about the same setup as I had with PIC12F683 except that I could select between RB2 and RB3 as my output.

    With the above code I get good output on RB1 (led out which proves that the system is running) but I do not get any output on RB2 or RB3. I was hoping that it will go by default on one of them.
    Code:
    @	device  pic16F819, wdt_off, hs_osc, pwrt_on, mclr_off, lvp_off, protect_on
    DEFINE OSC 16         ' We're running at 16 Mhz
    
    ADCON1=%01001110            ' Digital only for all pins
    
    led     var         PORTB.1
    i       var         byte
    
    CCP1CON = %00001100     ' Normal PWM 
    PR2 = 3            
    CCPR1L =0         
    CCP1CON.5 = 1
    CCP1CON.4 =1
    
    For i = 0 to 9
        Toggle LED
        Pause 500
    NEXT
    
    Main:
        high led
        CCP1CON = %00001100     ' Normal PWM mode
        T2CON.2 = 1             ' Timebase ON
        PAUSE 15
    
        low led
        T2CON.2 = 0             ' Timebase OFF
        CCP1CON = %00000000     ' Disable PWM to regain control of PortA.2
        PAUSE 5
    Goto Main
    The data sheet states:

    The CCP module’s input/output pin (CCP1) can be
    configured as RB2 or RB3. This selection is set in bit 12
    (CCPMX) of the Configuration Word register.

    I have no idea how to change this setting and if this is the reason why I get no output.
    Is there anything that I should do differently?

    Thank you in advance for any input.

    Nick

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,622


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Hi Nick,

    1) Add _CCP1_RB2 or _CCP1_RB3 to your line of config directives in order to select which pin to be used as the CCP1-pin. But yes it WILL default to one of them.

    2) When the PIC starts all pins are set to be input. You need to set RB2 or RB3 to be an output by clearing the coresponding bit in the TRISB register. The reason the LED works is because commands like TOGGLE, HIGH and LOW handles clears the TRIS-bit for you - each and every time the command is executed.....

    3) Not that it matters but anyway, as far as I can see the 16F819 can not do 16MHz on its internal oscillator, up goes the partcount you said you want to keep low. If running at 16MHz is the main reason for switching to the 16F819 you could just as well stuck that 16MHz oscillator on the 12F683.

    /Henrik.

  5. #5
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Hi Henrik,

    Thank you for pointing out my stupid mistake. I knew it must be something I overlooked.
    In my defense I have to say that after copying the code from 683 I made the necessary changes on the top of the code to apply it to 819. In the process I removed the TRISIO line from the old code and look up the corresponding line for 819. I got distracted (which is quite easy at my age) and did not finish it. My mind was set that I did it so I was looking for something else.

    I will add extra configs and test it again after work tonight.

    To answer your question why I’m using an external oscillator: I would like to experiment with higher frequencies and I have plenty of 819 (some of them on PCBs ready to use as prototyping boards).
    I will order some more oscillators (or try to locate the ones I have somewhere in my garage) for all PBP supported frequencies and have a wide range of available frequencies in the range of 250KHz to 5MHz. Also I could not find any PIC supported by my setup that will do more than 8MHz on internal oscillator.
    After Art’s post I realized that my signal generator outputs only signals lower than 2MHz so I have to compensate for the difference.
    I’m doing the same thing with the 683 (recycling old rev boards) but the 683 version is extremely small (less than 1² inch) and they do not have the padding for the oscillator.
    For the working project I’m still using the low part count concept.

    Regards,

    Nick

  6. #6
    Join Date
    Oct 2012
    Posts
    83


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    I've added the two extra configs and I got output on RB2.
    I did not have time to play more but I will do as soon as I will return from a two weeks vacation.

    Regards,

    Nick

  7. #7
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    You could try putting the code you want to be called the fastest, closest to zero vector.
    Labels called with a Goto command causes the program counter to start looking for your label from zero,
    so the closest it is to zero, the faster it is found, and run.

    So without looking at anything else about your code:


    Code:
    // the following is not run time code, so who cares…
    @	device  pic16F819, wdt_off, hs_osc, pwrt_on, mclr_off, lvp_off, protect_on
    DEFINE OSC 16         ' We're running at 16 Mhz
    led     var         PORTB.1
    i       var         byte
    
    // jump to config vector
    Goto Config
    
    Main:
        high led
        CCP1CON = %00001100     ' Normal PWM mode
        T2CON.2 = 1             ' Timebase ON
        PAUSE 15
    
        low led
        T2CON.2 = 0             ' Timebase OFF
        CCP1CON = %00000000     ' Disable PWM to regain control of PortA.2
        PAUSE 5
    Goto Main
    
    
    Config:
    ADCON1=%01001110            ' Digital only for all pins
    CCP1CON = %00001100     ' Normal PWM 
    PR2 = 3            
    CCPR1L =0         
    CCP1CON.5 = 1
    CCP1CON.4 =1
    
    For i = 0 to 9
        Toggle LED
        Pause 500
    NEXT
    
    // run main program
    Goto Main

Similar Threads

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

Members who have read this thread : 0

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