need help on hpwm


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2007
    Posts
    6

    Default need help on hpwm

    hi everyone here
    i need some help on hpwm
    my code is as below:

    DEFINE OSC 4
    DEFINE CCP1_REG PORTC
    DEFINE CCP1_BIT 2
    DEFINE CCP2_REG PORTC
    DEFINE CCP2_BIT 1
    trisb = %11111111
    trisc = %00000000
    CCP1CON = %00001100
    CCP2CON = %00001100
    T2CON = %00000100
    i var byte
    a var byte
    L VAR BYTE
    M VAR BYTE

    main:
    L = 0
    m = 80
    hpwm 1,0,1000
    hpwm 2,0,1000
    if portb.0 == 1 then
    pause 1000
    goto LED
    endif
    goto main
    end

    LED:
    IF PORTB.1 == 1 THEN
    pause 500
    gosub ledincrease
    endif

    if portb.2 == 1 then
    pause 500
    gosub leddecrease
    endif

    if portb.0 == 1 then
    pause 1000
    goto motor
    else
    goto LED
    endif


    MOTOR:
    if portb.1 == 1 then
    pause 500
    gosub motorincrease
    endif
    if portb.2 == 1 then
    pause 500
    gosub motordecrease
    endif
    if portb.0 == 1 then
    pause 1000
    goto led
    else
    goto motor
    endif

    ledincrease:
    L = L + 16
    IF (L < 255) THEN
    HPWM 1,L,1000
    else
    if (l >= 255) then
    L = 255
    hpwm 1,L,1000
    endif
    endif
    return

    leddecrease:
    L = L - 16
    if (l > 0) then
    hpwm 1,l,1000
    else
    if (l <= 0) then
    L = 0
    hpwm 1,L,1000
    endif
    endif
    return

    motorincrease:
    m = m + 11
    IF (m < 255) THEN
    HPWM 2,m,1000
    else
    if (m >= 255) then
    M = 255
    hpwm 2,M,1000
    endif
    endif
    return
    motordecrease:
    m = m - 11
    if (m > 0) then
    hpwm 2,m,1000
    else
    if (m <= 0) then
    M = 0
    hpwm 2,M,1000
    endif
    endif
    return



    this program is used to control intensity of 2 application - led or motor
    when i high portb.1, the hpwm will increase
    and when i high portb.2, the hpwm will decrease.
    the problems i face is the hpwm will go from 100% to 0% when i further HIGH portb.1
    i wish the hpwm will stop at 100% until i decrease it.
    thank for your help~

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    Code:
    L = L + 16
    With this code, you are letting L overflow ... If L = 240 and you add 16, you get 0 (not 256). Bytes range from 0 – 255

    If L = 0 to start

    try something like this for the L increase routines:

    Code:
    IF L < 240 THEN
       L = L + 16
    ELSE
       IF L = 240 THEN L = 255
    ENDIF
    try something like this for the decrease routines:

    Code:
    IF L > 0 THEN
       IF L = 255 THEN
    	L = 240 
       ELSE
    	L = L – 16
       ENDIF
    ENDIF
    You can work out something similar for the m variable. Reply back if you need more hints.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Aug 2007
    Posts
    6


    Did you find this post helpful? Yes | No

    Red face

    hah! i was tried today....
    and i got it...
    i wrote

    if ( L >= 240) then
    hpwm 1,255,1000
    else
    if (L<240) then
    L=L+16
    hpwm 1,L,1000

    thank you paul....
    but i stil have problems with my shifting input

Similar Threads

  1. Multiple HPWM question
    By Johan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th October 2007, 13:00
  2. HPWM of the port of two HPWM
    By ja2rqk in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2007, 15:05
  3. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  4. HPWM and A to D interaction question 18F252
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th May 2006, 03:50
  5. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43

Members who have read this thread : 1

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