Stuck on porting code to 18F4520


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    Richard, the MyTimer was left over from the previous code, and was used to scale the timing of the pwm as in the version of PBP there is no floating point maths. For example if the calculation gave the duration as 4.456 seconds, this would be rounded down to 4 seconds, so over the duration it would loose 255 x 0.456 or almost two minutes. In real terms that's not a problem, but the previous author used that to perform its function. Here is the routine

    Code:
    ' Timer used to scale the PWM pulse
     MyTimer:
        Tick_Tmr = Tick_Tmr + 1
        if Tick_Tmr >180 then     ;179
            Tick_Tmr = 0
            b_cnt = b_cnt + 1
            W_cnt = W_cnt + 1
        endif  
    @  INT_RETURN
    The temperature routine was an example found on the net and works well...

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    OK I've reverted to using a counter to dictate when each case statement is reached. The only issue i have is that for the life of me I can't work out how to slow the B_PWM=B_PWM+1 down so the PWM goes from 0 to 255 over the course of 30 minutes without stopping the clock running (such as would happen if a pause statement was used).

    To make this simple I'm going to remove any user programming for now just to make things simple. If anyone can help with some code to assist me in achieving this delay between increasing / decreasing the PWM once every seven seconds without upsetting the clock it would be most appreciated. The timings in the code below are for testing only, so I'm not waiting for things to happen

    Code:
    If Counter1 < 1200 then
    Blue_day_cycle = NIGHT
    endif
    
    if Counter1 = 1200 then
    Blue_day_cycle = DAWN
    endif
    
    if counter1 =1202 then
    Blue_day_cycle = DUSK
    endif
    
      '*** Do BLUE daily cycle
        select case Blue_Day_Cycle
        case DAWN 
        lcdout $FE,$80+13,"DAWN "
                B_PWM = B_PWM+1
            if B_PWM = b_max then
                Blue_Day_Cycle = DAY
            endif
        case DAY
        lcdout $FE,$80+13,"DAY  "
                Blue_Day_Cycle = DUSK
        CASE DUSK
        lcdout $FE,$80+13,"DUSK "
            if  B_PWM > B_Min then
                B_PWM = B_PWM - 1
            endif
            if B_PWM = b_min then 
                Blue_Day_Cycle = NIGHT
            endif
        case NIGHT
        lcdout $FE,$80+13,"NIGHT"
            if HH = S2H and MM = S2M then
                Blue_Day_Cycle = DAWN
                b_cnt = 0
            endif 
        end select
    Last edited by Scampy; - 30th October 2013 at 16:37. Reason: added code

Similar Threads

  1. Porting code to new PIC
    By malc-c in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 1st January 2011, 00:20
  2. Kind of stuck
    By gti_uk in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 31st May 2009, 21:45
  3. Getting Stuck in loop
    By Frozen001 in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 19th November 2008, 16: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, 20:21
  5. Replies: 1
    Last Post: - 8th May 2008, 01:52

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