Altering a variable in a loop.


Closed Thread
Results 1 to 27 of 27

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Altering a variable in a loop.

    Hi,
    Several ways to do it, as usual. Here's one:
    Code:
    ' Setting is your variable that step or down between 0-5
    Lookup Setting, [12, 30, 55, 76, 98, 120], BaseDutyCycle
    Another way would be to not step the Setting variable between 0 and 5 but to actually step it directly between dutycycle values
    Code:
    Select Case Step
      Case 12
        IF DOWN THEN
           Setting = 12 ' We're at the bottom setting
        ELSE
           Setting = 30
     
      Case 30
         IF DOWN THEN
            Setting = 12
        ELSE
           Setting = 55
        ENDIF
    
    'And so on
      END SELECT
    
    PWMDuty = Setting
    /Henrik.
    Last edited by HenrikOlsson; - 12th September 2012 at 20:43.

  2. #2
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Altering a variable in a loop.

    Ok, but these 2 examples run into the same problem. You've set the pwm duty cycle using CASE and now the program must go into a loop to change the pwm duty according to feedback from a current sense resistor. In that loop the the program needs to start the pwm at the number in the correct CASE and then ignore it every time it loops through as the CASE number could be incorrect. Within that loop it will be monitoring for a change of SETTINGS so it can jump to the next loop for that particular current output. How would the CASE work to exclude the current CASE number in each loop after it has looped once?

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