Generate a 120Khz signal using the pic16F877a


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Posts
    45

    Default Generate a 120Khz signal using the pic16F877a

    i try to generate a 120khz signal using pin 17(rc2/ccp1) of pic16f877a.i use 8Mhz osc.the code as shown below(search from internet):

    void main()
    {
    TRISC = 0 ;

    /*
    * PWM registers configuration
    * Fosc = 8000000 Hz
    * Fpwm = 117647.06 Hz (Requested : 120000 Hz)
    * Resolution is 6 bits
    * Prescaler is 1
    * Ensure that your PWM pin is configured as digital output
    * see more details on http://www.micro-examples.com/
    * this source code is provided 'as is',
    * use it at your own risks
    */
    PR2 = 0b00010000 ;
    T2CON = 0b00000100 ;
    CCPR1L = 0b00001000 ;
    CCP1CON = 0b00011100 ;
    }

    are those coding will work.can someone help me briefly translate it into basic pro language cause i use microcode studio basic pro to compile.hope mr skimask would help me once again.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    are those coding will work.can someone help me briefly translate it into basic pro language cause i use microcode studio basic pro to compile.hope mr skimask would help me once again.
    I don't see a lot of helping going on...
    Why don't you try coding it yourself...then when it doesn't work right, I'll jump in and help you fix it.

  3. #3
    Join Date
    Aug 2008
    Posts
    45


    Did you find this post helpful? Yes | No

    Default

    this is my coding:

    DEFINE OSC 8
    DEFINE CCP1_REG PORTC 'Hpwm 1 pin port
    DEFINE CCP1_BIT 2 'Hpwm 1 pin bit


    HPWM 1,127,120000 ' Send a 50% duty cycle PWM signal at 120kHz

    the problem is i can't compile.it says "120000 numeric overflow, value truncated"

  4. #4
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    From the manual
    Quote Originally Posted by PBP Manual

    5.29. HPWM
    HPWM Channel,Dutycycle,Frequency

    ....Not all frequencies are available at all oscillator settings. The highest
    frequency at any oscillator speed is 32767Hz.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Wink

    Manual? What's that?

    That being said...
    PIC16F877A datasheet, DS39582B, Table 8-3, Page 68, says you can do 156.3Khz with a 7 bit resolution...if capable of manually setting the registers 'by hand'...

    And I'm not 100% sure, but I think with PBPL, you can actually set those frequencies to a much higher value, as long as you're using PBPL and an 18F series PIC. I know I've got a LONG variable driving my HPWM on my 18F4685...can't remember if it goes over 32767 though...
    Last edited by skimask; - 10th September 2008 at 16:55.

  6. #6
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    So in other words, you won't be able to use the HPWM command for that high of a frequency. But as Skimask points out, you can achieve that frequency by setting up the PWM registers manually. As mentioned, section 8.3 of the PIC16F87XA datasheet will explain this. If you get stuck, ask.... I've never set these up before, but I'm pretty confident someone here can guide you.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

Similar Threads

  1. Measuring p-p of a 1.5v to 12v ac signal?
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th October 2009, 16:22
  2. PIC16F877A pwm use for IR transmission
    By mcbeasleyjr in forum General
    Replies: 0
    Last Post: - 11th July 2009, 18:51
  3. PIC16F877A for application in mobile robot...
    By mcbeasleyjr in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th January 2009, 14:47
  4. PIC16F684 + LCD to use the 256bytes of EEPROM - HELP
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th March 2008, 14:19
  5. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36

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