Stuck on porting code to 18F4520


Closed Thread
Results 1 to 40 of 43

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    OK, seems you've got it going now but during that time I tried "my version" of the formula with the following code:
    Code:
    PsuedoSeconds VAR WORD
    Hours VAR WORD
    Minutes VAR WORD
    
    Start:
        HSEROUT["Program start",13,13]
    
        Minutes = 30
        Hours = 0
        GOSUB Calculate
        GOSUB PrintResult
        
        Minutes = 59
        Hours = 0
        GOSUB Calculate
        GOSUB PrintResult
        
        Minutes = 0
        Hours = 1
        GOSUB Calculate
        Gosub PrintResult
        
        Hours = 2
        Minutes = 15
        GOSUB Calculate
        Gosub PrintResult
    
        Hours = 3
        Minutes = 59
        GOSUB Calculate
        Gosub PrintResult
                
        Hours = 10
        Minutes = 0
        GOSUB Calculate
        Gosub PrintResult
        
        Pause 100
        
    END
    
    Calculate:
        PsuedoSeconds = (Hours * 3600 + Minutes * 60) / 255
    RETURN
    
    PrintResult:
        HSEROUT[DEC2 Hours, ":", DEC2 Minutes, " - ", DEC PsuedoSeconds,13]
    RETURN
    And it outputs:
    Code:
    Program start
    
    00:30 - 7
    00:59 - 13
    01:00 - 14
    02:15 - 31
    03:59 - 56
    10:00 - 141
    Which seems correct to me.

    /Henrik.

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


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    I have no idea what you're doing.....
    I've tried three versions of the formula and the only one to give correct results are the one I posted. Please see the following code and the results:
    Code:
    PsuedoSeconds VAR WORD
    Hours VAR WORD
    Minutes VAR WORD
    
    Start:
        HSEROUT["Program start",13,13]
    
        Minutes = 30
        Hours = 0
        GOSUB Calculate
        
        Minutes = 59
        Hours = 0
        GOSUB Calculate
        
        Minutes = 0
        Hours = 1
        GOSUB Calculate
      
        Hours = 2
        Minutes = 15
        GOSUB Calculate
    
        Hours = 3
        Minutes = 59
        GOSUB Calculate
        
        Hours = 10
        Minutes = 0
        GOSUB Calculate
       
        Pause 100
        
    END
    
    Calculate:
        PsuedoSeconds = (Hours * 3600 + Minutes * 60) / 255
        HSEROUT["Version 1: "]
        GOSUB PrintResult
        
        PsuedoSeconds = (Hours * 3600) + (Minutes * 60) / 255
        HSEROUT["Version 2: "]
        GOSUB PrintResult
        
        PsuedoSeconds = Hours * 3600 + Minutes * 60 / 255
        HSEROUT["Version 3: "]
        GOSUB PrintResult
        
        HSEROUT[13]
    RETURN
    
    PrintResult:
        HSEROUT[DEC2 Hours, ":", DEC2 Minutes, " - ", DEC PsuedoSeconds,13]
    RETURN
    Result:
    Code:
    Program start
    
    Version 1: 00:30 - 7
    Version 2: 00:30 - 7
    Version 3: 00:30 - 7
    
    Version 1: 00:59 - 13
    Version 2: 00:59 - 13
    Version 3: 00:59 - 13
    
    Version 1: 01:00 - 14
    Version 2: 01:00 - 3600
    Version 3: 01:00 - 3600
    
    Version 1: 02:15 - 31
    Version 2: 02:15 - 7203
    Version 3: 02:15 - 7203
    
    Version 1: 03:59 - 56
    Version 2: 03:59 - 10813
    Version 3: 03:59 - 10813
    
    Version 1: 10:00 - 141
    Version 2: 10:00 - 36000
    Version 3: 10:00 - 36000
    As you can see, the only one to give correct results are the first one. Why, because the other two both will take the result of the Minutes*60 divided by 255 and add THAT result to Hours*60 while the first (correct) one will divide the sum of the multiplications by 255. How you are getting the correct results from the formula without any parenthesis is beyond me.

    /Henrik.

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    I found the cause. I had duplicated the fade in / fade out lines within another subroutine which was being called and thus overwriting the changes made - I guess that's what happens when you spend too long coding into the wee hours of the night !! - Mistakes happen

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    Hi Guys,

    I've stumbled on a small issue that is doing my head in.

    Whilst using 8 bit resolution for the fading (ie 0 - 255) the code works and allows a minimum fade up / down time of 5 minutes, I now want to increase the resolution to 4095 steps.

    Code:
    blue_delay_in = fadesetHR[0] * 3600 + fadesetMN[0] * 60 / 255
    white_delay_in = fadesetHR[1] * 3600 + fadesetMN[1] * 60 / 255
    blue_delay_out = fadeoutHR[0] * 3600 + fadeoutMN[0] * 60 / 255
    white_delay_out = fadeoutHR[1] * 3600 + fadeoutMN[1] * 60 / 255
    If the above is changed by removing the 255 at the end of each line and replacing that with 4095 it means the minimum fade in/out time is now 68 minutes as anything less results in an FP decimal which isn't supported by PBP

    The resulting value for blue_fade_in etc is then used in the case statements to perform the PWM

    Code:
    case DAWN 
    lcdout $FE,$80+15,"DAWN "   
    if ss//blue_delay_in = 0 then
    if ss != old_ss_blue then
    B_PWM=B_PWM+1
    old_ss_blue=ss
    endif
    endif
    if B_PWM = B_Mid then
    Blue_Day_Cycle = MORN
    endif
    Is there anything I can do to the code as it stands to get the timing so that I can use the 4095 resolution, and still have fade in/out times of 5 minutes or more rather than 68 minutes.

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,170


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    Could this be a byte VS word issue?

    Sorry, falling asleep.

    Robert

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    Hi Rob,

    Yes I've changed the variable from byte to word.

Similar Threads

  1. Porting code to new PIC
    By malc-c in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 31st December 2010, 23:20
  2. Kind of stuck
    By gti_uk in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 31st May 2009, 20:45
  3. Getting Stuck in loop
    By Frozen001 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 19th November 2008, 15:46
  4. Any idea's on porting this to PBP?
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 10th October 2008, 19:21
  5. Replies: 1
    Last Post: - 8th May 2008, 00:52

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