Pulse width modulation


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2006
    Location
    Isle of Man
    Posts
    32

    Cool Pulse width modulation

    I am attempting to use the 10 bit PWM facility on the PIC18F452. Following guidance in the data sheet I have written this code:

    'Program to test use of PWM out PortC.2 (Pin 17, CCP1) on 18F452
    'Does not work yet!

    Include "modedefs.bas"
    define LOADER_USED 1 'Bootloader
    define OSC 20 'Sets clock to 20MHz


    PR2=%11111111 'Set PWM period. Gives 1220.7Hz (0.82ms) with 20MHz clock
    CCPR1L=%11110000 'Set PWM duty cycle in CCPR1L register
    CCP1CON.4=0: CCP1CON.5=0 'Set PWM duty cycle in CCP1CON<5:4> bits (total of 0.2ms)
    TRISC.2=0 'Make CCP1 pin an output
    T2CON.0=0: T2CON.1=1 'Set TMR2 prescale value
    T2CON.2=1 'Enable Timer2
    CCP1CON.0=0: CCP1CON.1=0
    CCP1CON.2=1: CCP1CON.3=1 'Configure the CCP1 module for PWM operation


    Loop:

    goto loop

    End


    However ... no luck!

    Any suggestions?

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default May be this will help

    Hi,

    This link may help :

    http://www.picbasic.co.uk/forum/atta...6&d=1125842860

    Regards

    Sougata

  3. #3
    Join Date
    Feb 2006
    Location
    Isle of Man
    Posts
    32


    Did you find this post helpful? Yes | No

    Default PWM methods

    Sougata,

    Thanks for your suggestion which I will test shortly.

    In the meantime, I have found a way of producing an effective 16 bit PWM output on the 18F452 by combining the PWM outputs of the two CCP1 and CCP2 channels. Both channels are driven at the same frequency, as required by the PIC specification: this is 2KHz in my system and the outputs are used to drive each of the 2 bridges in an L293 chip. CCP1 is assigned to the lower byte of the 16bit Word (and then out to bridge 1) and CCP2 to the upper byte (then out to bridge 2). The maximum current from CCP2 is set to 1/256th of CCP1 by a series resistor. The summed current from the 2 bridges is then 16bit. Easy!

    Two MOSFETs could be used instead of the L293 to produce a 16bit controlled DC supply. However, in my application I need to reverse the current to produce a controlled AC. Since the polarity is being switched in this instance, we effectively have 17bit current control!

    The same method could be used on any other PIC with two CCP registers.

Similar Threads

  1. Pulse Capture and byte building
    By boroko in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st July 2009, 01:59
  2. measure pulse width 0-150Hz
    By kewetman in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th November 2007, 21:38
  3. PIC12f675 timer1 pulse width
    By ck1223 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th February 2006, 04:05
  4. pulse width modulation
    By cheznez in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 16th February 2005, 17:14
  5. Pulse Width Measurement
    By atomski in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 29th January 2005, 00:53

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