pwm 18f2431


Closed Thread
Results 1 to 21 of 21

Thread: pwm 18f2431

Hybrid View

  1. #1
    Join Date
    Aug 2009
    Posts
    63


    Did you find this post helpful? Yes | No

    Default

    ahhh thank you, thats cleared many things up for me. my picbasic pro just arrived so ill be testing all my attempted codings now!

    cheers mack

  2. #2
    Join Date
    Aug 2009
    Posts
    63


    Did you find this post helpful? Yes | No

    Default

    ok well these are the bare bones of my code so far... i havnt actually created the algorithm yet so i havnt actually got a proper dutycycle to put in yet. and things like config settings etc i still have yet to choose. just hope its going in the right direction

    '''''''''''''''''''''''''''''''''''Assembley to collect period on cap1 cap2 and cap3''''''
    asm

    cap1m0 = 0101
    cap1ren = 1
    cap2m0 = 0101
    cap2ren = 1
    cap3m0 = 0101
    cap3ren = 1

    endasm

    '''''''''''''''''''''''''''values put in var for us in calculation''''''''''''''''''

    F69H VAR BYTE 'Value of period at CAP1 ready for calculation
    F67H VAR BYTE 'Value of period at CAP2 ready for calculation
    F65H VAR BYTE 'Value of period at CAP3 ready for calculation

    ''''''''''''''''''''''''''''''''''''Algorithm for finding average''''''''''''''''''''''''


    'yet to write it



    '''''''''''''''''''''''''''''''''''pwm output'''''''''''''''''''''''''''''''''''''''''''' '''

    HPWM 1, 127, 20000
    'obviously unfinished and dutycycle would not be a fixed 50%

  3. #3
    Join Date
    Aug 2009
    Posts
    63


    Did you find this post helpful? Yes | No

    Default

    whoops just realised the pwm output wasnt quite anything...

    DutyCycle var byte 'byte being the one that is answer of algorithm when thats created
    CCP1CON=0 'output of pwm pin
    TRISC= $00000000

    HPWM 1,DutyCycle,20000

    end
    hopefully that should work

  4. #4
    Join Date
    Aug 2009
    Posts
    63


    Did you find this post helpful? Yes | No

    Default

    hey sorry again,

    getting the right ideas but im a little stuck on one bit...

    i need to set the PWM period by writing to the PR2 register and then set the PWM duty cycle by writing to the CCPR1L register and CCP1CON<5:4> bits. would this require assembley language and how would i do it?



    afterwards i need to make the CCP1 pin an output by clearing the
    TRISC<2> bit. would that just be trisc.2 = 0 ?


    also i need to set the TMR2 prescale value and enable Timer2
    by writing to T2CON. but im not too sure on how to work out the prescale value? and how to write to it?
    and i need to configure the CCP1 module for PWM operation, how would i decide upon specific configurations? leave it as standard config until i find there is a problem then try and sort out the config?

    will this give me hpwm? since i cant find anywhere in the datasheet that its hardwarepwm, but i am presuming it is since its whole purpose seems to revolve around pwm outputs and ccp.

    additionally if i am updating the pwm constantly as it is giving an output... will this cause any delay in the output? for example when it updates... there will be a significant pause in the pwm?

  5. #5
    Join Date
    Aug 2009
    Posts
    63


    Did you find this post helpful? Yes | No

    Default

    unforunately since i cant actually test it yet without the real algorithms, i just wanna know if this sounds about right?

    '''''''''''''''''''''''''''''''''''Assembley to collect period on cap1 cap2 and cap3''''''
    asm

    cap1m0 = 0101
    cap1ren = 1
    cap2m0 = 0101
    cap2ren = 1
    cap3m0 = 0101
    cap3ren = 1

    endasm

    '''''''''''''''''''''''''''''''''Read values taken and write to var (no longer needed since file name can be used in calculations)''''''''''''''''''

    start:

    F69H VAR BYTE 'Value of period at CAP1 ready for calculation
    F67H VAR BYTE 'Value of period at CAP2 ready for calculation
    F65H VAR BYTE 'Value of period at CAP3 ready for calculation

    ''''''''''''''''''''''''''''''''''''Algorithm for finding power''''''''''''''''''''''''

    averageperiod var byte 'saving average period to ram
    averageperiod = (F69H+F67H+F65H)/3 'average period found using 3 periods

    'for now im using arbitary random scaling factors, until i have the actual graphs to get the real rpm against power

    rpmvalue var byte 'saving rpm value to ram
    rpmvalue=60/(8*averageperiod) 'finding rpm value using current period measurement

    power var byte 'saving power to ram

    IF rpmvalue<=300 Then
    power=rpmvalue/15
    else
    power=rpmvalue/10
    endif


    ' now i need to link power to the arbitary pwm output
    'this is a standard quadratic function (quadratic in example case anyway)

    dutycycle var byte 'byte being the one that is answer of algorithm when thats created
    dutycycle = (power^2)+(5*power)+3 'finding dutycycle using rpmvalue


    '''''''''''''''''''''''''''''''''''pwm output (possibly need interupts so as not to cause delay in hpwm output'''''''''''''''''''''''''''''''''''''''''''' '''


    CCP1CON=0 'output of pwm pin
    TRISC= $00000000

    HPWM 1,DutyCycle,20000

    goto start

    end

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I am not going to comment much on you code as I am still reading the data sheet and my chips have not arrived yet. But I do not think the ASM stuff is quite right.

    Have you seen this thread? Post #4.
    http://www.picbasic.co.uk/forum/showthread.php?t=7095
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Aug 2009
    Posts
    63


    Did you find this post helpful? Yes | No

    Default

    yeah i didnt really know where i was going with the assembley stuff... just kinda wrote down a few commands that seemed kinda suitable...

Similar Threads

  1. Half-bridge PWM with a 16F684 ?
    By Byte_Butcher in forum General
    Replies: 7
    Last Post: - 17th January 2010, 23:18
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 07:03
  3. PWM setting PIC16F887
    By Gevo in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th June 2008, 08:24
  4. using all pins of pwm in pic 18f2431
    By jorgequesada in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 4th May 2007, 22:43
  5. Tidying Up PWM Routine
    By Tissy in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st February 2005, 01:26

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