Word variable and storing correct value


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default Word variable and storing correct value

    Code:
    Fade:
        Vb_1 = ((B_Day_On_H - B_Dawn_On_H)*60)       ' difference between day start and dawn start hour, converted to min
        Vb_2 = (B_Day_On_M - B_Dawn_On_M)            ' difference between day start and dawn start mins 
        Vb_5 = (Vb_1+Vb_2)*60                        ' Get total duration time in seconds
        Vb_6 = B_Max - B_Min                         ' Work out the 'distance' the lights go from min to max
        B_Fadein_Time = Vb_5 / Vb_6                  ' Get number of seconds between each PWM pulse    
        Vb_7 = Vb_5 // Vb_6                                                                 'Get fractions of a second
        Vb_8 = B_Fadein_Time
    
     ' with B day on at 8:10 and a Dawn on at 8:00,  Vb1 = (8 - 8) * 60 which gives 0.  Vb2 = (10-0) = 10,  Vb5 = (0+10)*60 = 600
     ' Vb6 = 255-0 = 255
     ' so fadein time = 600/255 = 2.352941176470588
     ' Vb_8 therefore should equal 236
    I need VB_8 to = 235 (rounding down the fadein time and removing the decimal) but can't work out how - can someone please point me in the right direction

    Thanks

    Malcolm

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


    Did you find this post helpful? Yes | No

    Default Re: Word variable and storing correct value

    B_Fadein_Time = Vb_5 / Vb_6 * 100
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Word variable and storing correct value

    Thanks for the input. However using this command B_Fadein_Time reaches the 255 max in around 90 seconds

    I tried 1000 as the multiplier, but the timing is still out as it uses just the integer and not the full decimal value you get in the calculations. What I'm after is the ability to set the max value for the brightness (B_max - B_min) and then use this value (between 0 and 255) to work out the pulse duration so that it goes from 0 to B_Max in the difference between the two times. On paper it's a simple calculation, but getting it to work in PBP without any floating point maths is becoming the stumbling block. My code also used a 1307 RTC, so using the pause statement in DT's Multi SPWM routine might effect the time being displayed on the LCD -

Similar Threads

  1. SEROUT WORD variable problem
    By Tobias in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th April 2009, 11:20
  2. adding new word variable ?
    By iugmoh in forum General
    Replies: 4
    Last Post: - 21st February 2008, 00:26
  3. Storing a variable in EEPROM
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th October 2005, 13:53
  4. Convert a word variable to decimal
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th December 2004, 20:02
  5. word variable to 25lc640
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 6th July 2004, 19:59

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