Stuck on porting code to 18F4520 - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 43 of 43
  1. #41
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    Tried that and the steps are too much, almost rising in 5% increments - this is why I'm looking for an alternative. Shame PBP doesn't support FP and recognise 0.073s as a value

  2. #42
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    The only issue is timing!

    You have set TMR0 at 1/2 second intervals

    Code:
    ClockLoop: IF intcon.2=0 THEN ClockLoop	'Poll for TMRO overflow
    INTCON.2=0 ' Clear TMRO overflow flag
    
    HzTimer=HzTimer-$1000	'decrement timer count
    
    IF HzTimer < $1000  THEN
    IF Col=10 THEN    ' update time'
    SS=SS+1
            
    IF SS=60 THEN   ' minute
    SS=0 
    MM=MM+1
    IF MM=60 THEN    ' hour            
    MM=0
    HH=HH+1
    IF HH=24 THEN HH=0
    ENDIF                           
    counter1 = (HH*60)+MM
    ENDIF
    ENDIF
    Col=Col+1
    
    HzTimer=HzTimer+$7A12	' Add 0.5 seconds to count
    ELSE
        ' Do something here but must be less than 65.5 mSec
    ENDIF
    And again this code works every second

    Code:
    case DAWN 
    lcdout $FE,$80+13,"DAWN "   
    if ss//1= 0 then
    if ss != old_ss then
    B_PWM=B_PWM+1
    old_ss=ss
    endif
    endif
    if B_PWM = b_max then
    Blue_Day_Cycle = DAY
    endif
    Change your TMR0 code +$7A12 to a lower value for say 1 msec. Then include for milliseconds in your clock and change all of the ss//1=0 instructions to trigger every 73 ms. I guess there will be more issues thrown up but looks easy to me.

  3. #43
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Stuck on porting code to 18F4520

    Hi,
    I'll admit, I don't quite follow what you're doing here but (as far as I can see) with the increased resolution you must change either "step change" per update (what Richard suggest but which basically defeats the incresed resolution) OR change the update rate if you want to keep the orignial "cycle time".

    If the CASE code, which is what's actually updating the PWM dutycycle, is currently executed at 1Hz then changing that to 16Hz will allow B_PWM to reach 4095 in the same amount of time as it's currently taking to reach 255.

    /Henrik.

    EDIT: Ah, Steve posted while I was typing and retyping....

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