Maximum frequency output from a PIC


Results 1 to 40 of 69

Threaded View

  1. #15
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,613


    Did you find this post helpful? Yes | No

    Default Re: Maximum frequency output from a PIC

    Hi Nick,
    No problem, I didn't have a 12F683 at home but I did have a 12F1840. Now, the 1840 has an ECCP module while the 683 has a standard CCP module so the following code MAY need to be changed slightly (the CCP1CON register) in order to work properly on the 683 (I'm not using the data modulator here). It sets the CCP module up to output a 1MHz, 50% dutycycle PWM on PortA.2. The main program then simply toggles the timebase (TMR2) for the CCP module on and off to modulate the output.
    Code:
    ' ***************************************************************
    ' Pin Connections
    ' ***************************************************************
    
    ' RA0                       -> Not used
    ' RA1                       -> Not used
    ' RA2                       -> CCP1 output
    ' RA3                       -> Not used
    ' RA4                       -> Not used
    ' RA5                       -> Not used
    
    ' ***************************************************************
    ' Device Fuses
    ' ***************************************************************
    
    #CONFIG
       __config _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF
       __config _CONFIG2, _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_OFF
    #ENDCONFIG
    
    ' ***************************************************************
    ' Compiler directives
    ' ***************************************************************
    DEFINE OSC 8               ; We're running at 16Mhz
    
    ' ***************************************************************
    ' Initialization
    ' ***************************************************************
    
    OSCCON   = %01110000        ' 8MHz internal osc
    ANSELA   = 0                ' Digital only for all PortA pins
    TRISA    = %00000000        ' Make PORTA outputs
    
    CCP1CON = %00001100     ' Normal PWM 
    PR2 = 1                 ' 1MHz output @8MHz system clock
    CCPR1L = 0              ' 50% Dutycycle
    CCP1CON.5 = 1
    CCP1CON.4 = 1
    
    ' ***************************************************************
    ' Actual program
    ' ***************************************************************
    Main:
        T2CON.2 = 1             ' Timebase ON
        PAUSE 15
        T2CON.2 = 0             ' Timebase OFF
        PAUSE 5
    Goto Main
    I have a scope screen grab of the output but for some reason the file upload manager on the forum refuses to work, the upload just hangs...aarghh....

    Now, if you intend to do other things with the PIC as well then this simple aproach obviously won't work. But you could use a timer interrupt in order to turn on and off the carrier at the correct intervals. I haven't personally used the data signal modulator module in the 12F1840 but it sure sounds like the "correct" way forward. The 12F1840 also allows you to run at 32MHz using the internal oscillator and 4x PLL which would allow you to get higher output frequency using the CCP module than on the 12F683 which tops out at 8MHz.

    /Henrik.
    Last edited by HenrikOlsson; - 23rd August 2013 at 18:22.

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 : 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