Just looking for an explanation


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jan 2010
    Posts
    88

    Default Just looking for an explanation

    Hi guys,

    OK, encountered a weird result and was wondering if anyone could explain it. I am using a PIC12F683 and I wrote A LOT of lines of code. I actually filled the chip and had to make modifications to the code to consolidate space. Anyway, I found that when I wrote the code,
    Code:
        FOR fade = 0 to 255 STEP fadevalue
    
          PWM left, fade, 1
          PWM right, fade, 1
    
          gosub buttoncheck          ' check for a button press
    
        NEXT fade
    
        FOR fade = 255 to 0  STEP -fadevalue
    
          PWM left, fade, 1
          PWM right, fade, 1
    
          gosub buttoncheck          ' check for a button press
    
        NEXT fade
    the chip compiled just fine, leaving VERY LITTLE space left. But when the fade result was a little too long for me and I rewrote the code to,
    Code:
        FOR fade = 0 to 150  STEP fadevalue
    
          PWM left, fade, 1
          PWM right, fade, 1
    
          gosub buttoncheck          ' check for a button press
    
        NEXT fade
    
        FOR fade = 150 to 0  STEP -fadevalue
    
          PWM left, fade, 1
          PWM right, fade, 1
    
          gosub buttoncheck          ' check for a button press
    
        NEXT fade
    I got an error message saying I was out of space. By just changing the value from 255 to 150, I ran out of space? Not sure why this was happening, but I wound up going through my code again and consolidating some more to make it fit on the chip.

    I just want to know what's going on and why it was doing that. Anybody know why?

    Thanks,
    Tony

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default Re: Just looking for an explanation

    Probably because this compiler is intelligent ...

    0 to 255 can be obtained without any value calculation ( yesss ... 255 + 1 = 0 for a byte ! ) , but 0 -150 need to compare actual value to 150 ( implies a calculation and resetting value to 0 when 150 reached ) @ each loop ...

    just a possible explanation ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Jan 2010
    Posts
    88


    Did you find this post helpful? Yes | No

    Default Re: Just looking for an explanation

    Huh? Not really sure what you are talking about. Can you elaborate a little more please? Thanks.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Just looking for an explanation

    I think what Alain means is when you go from 0 to 255, it simply adds 1 to the present number. When it reaches 255 it doesn't do any resetting. It simply adds 1 to 255 and it goes back to 0 itself. On 0 to 150 it has to constantly monitor the number and reset to 0 after 150. This uses more memory. I just learned a lesson from your post myself.

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


    Did you find this post helpful? Yes | No

    Default Re: Just looking for an explanation

    Comparing the generated Assembler code might give more clues.

    Robert

  6. #6
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Just looking for an explanation

    Yes the generated assembler would be smaller.
    An example of two BASIC IF...THEN comparisons in assembler
    Code:
    @ movf		_Variable	,W	'IF Variable = $A0 THEN...
    @ sublw		0xA0			'subtract comparison
    @ btfss		status		,Z	'test if result is zero
    // condition is here
    
    @ movf		_Variable	,W	'IF Variable = $00 THEN...
    @ btfss		status		,Z	'test if result is zero
    // condition is here
    You are always testing for zero, helps if the comparison is zero!

Similar Threads

  1. Help/Explanation needed
    By SahdowSA in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th February 2010, 08:23
  2. Need explanation
    By tishri in forum General
    Replies: 4
    Last Post: - 21st February 2008, 09:54
  3. explanation of step array
    By Rabm in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th September 2006, 18:00
  4. explanation about serout2 and serin2
    By micro in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 6th January 2006, 16:50
  5. ADCON Explanation
    By eoasap in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th December 2005, 19:08

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