PIC10F202 Variable trouble


Closed Thread
Results 1 to 23 of 23
  1. #1
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171

    Default PIC10F202 Variable trouble

    I'm converting an old PIC12C671 program to run on a a 10F202 but for some reason it's not working.

    I'm using microcode 2.3 and pbp2.46 it has the 10f202 library in it.

    The errors I get are: ERROR unable to fit variable dim
    it also says this about every other variable I'm using

    Any thoughts would be greatly appreciated

    Program starts like:

    @ device pic10F202, mclr_off, protect_off, wdt_off

    TRISIO = %1100

    triac VAR GPIO.2
    trigger VAR GPIO.3

    dim VAR WORD
    Time VAR WORD
    Time2 VAR BYTE
    startup VAR BYTE
    b0 VAR BYTE

    Clear
    GPIO = 0
    dim = 100


    Start:

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    The 10F202 has only 24 bytes of SRAM (Data Memory). The System variables associated with PBP require 20 bytes - that leaves you with 4. (From the PBP manual "Several system variables, using about 24 bytes of RAM" - its only 20 for the 10F202)

    You can have 2 additional WORDS or 4 additional BYTES- that is it (you have 7 bytes defined). Can you reuse variables?

    EDIT - The PBP manual is great - read section 7.6. If you do not have nested Gosubs or they are not nested 4 deep you might be able to steal a byte or two from the stack array.
    Last edited by paul borgmeier; - 6th October 2006 at 04:26.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  3. #3
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Like the last edit on yr reply - tho not sure how to do it, the program is only 183 words long and I have no gosubs at all and only one goto at the very end.

    Are you able to elaborate on how to steal a couple of bytes from the stack?

    I was thinking that the 10F202 was going to be a neat little chip to use, but am having 2nd thoughts about it now knowing the ram limitations. Would be good to see if PBP could use only simple instructions for the 10F20X series chips and use say only 12bytes.

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi George,

    If it is not a secret government project, can you post your code?


    -------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Sure, all it does is dims a light down after 20 minutes of being on.

    @ device pic10F202, mclr_off, protect_off, wdt_off

    TRISIO = %1100

    triac VAR GPIO.2
    trigger VAR GPIO.3

    dim VAR WORD
    Time VAR WORD
    Time2 VAR BYTE
    b0 VAR BYTE

    Clear
    GPIO = 0
    dim = 100


    Start:

    time = time + 1 'increment timer in 1/50 seconds

    IF time > 30000 Then 'make a 10 min increment
    time = 0
    time2 = time2 + 1
    EndIF

    b0 = b0 + 1 'increment for every 4 phase cycles
    IF b0 >= 3 Then b0 = 0

    IF time2 >= 2 AND b0 = 2 Then dim = dim + 1 'if over 20 min then start dimming dim period 4 cycles = 10 mins

    IF dim > 7500 Then dim = 7500 'down to dim level - 9000 = off, 7500 approx 15%

    if time2 > 72 then 'turn off after 12 hours
    dim = 9000
    time2 = 73 'prevent from cycling
    endif

    LowSide: 'look for trigger points and trigger triac

    IF trigger = 1 Then lowside 'wait for phase to go low
    GPIO.5 = 0 'weight input to sense zero crossing
    PauseUs dim 'wait for dim period
    Output triac 'fire triac
    triac = 0
    PauseUs 400
    Input triac

    HighSide:

    IF trigger = 0 Then HighSide
    GPIO.5 = 1
    PauseUs dim
    Output triac
    triac = 0
    PauseUs 400
    Input triac

    GoTo start

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    It's the down side of those nifty 10Fs with most compiler. The use of assembler is handy in this case... but i'll have a look at this one to see what i can do...
    Last edited by mister_e; - 9th October 2006 at 03:58.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Not tested but assuming you're not using any Gosubs... it could work.

    Inspiration taken bellow
    http://www.picbasic.co.uk/forum/show...light=modifier

    Sure it could be dangerous.... compile O.K
    Code:
    @ device pic10F202, mclr_off, protect_off, wdt_off
    
    TRISIO = %1100
    
    asm
    dim=SOFT_STACK  		
    Time=SOFT_STACK + 2
    Time2=SOFT_STACK_PTR
    endasm
    dim   VAR WORD ext
    Time  VAR WORD ext   
    Time2 VAR BYTE ext
    b0    VAR BYTE 
    
    Clear
    GPIO = 0
    dim = 100
    
    
    Start:
        time = time + 1 'increment timer in 1/50 seconds
        
        IF time > 30000 Then 'make a 10 min increment
            time = 0
            time2 = time2 + 1
            EndIF
        
        b0 = b0 + 1 'increment for every 4 phase cycles
        IF b0 >= 3 Then b0 = 0
        
        IF (time2 >= 2) then 
           if b0 = 2 Then dim = dim + 1 'if over 20 min then start dimming dim period 4 cycles = 10 mins
           endif
    
        IF dim > 7500 Then dim = 7500 'down to dim level - 9000 = off, 7500 approx 15%
        
        if time2 > 72 then 'turn off after 12 hours
            dim = 9000
            time2 = 73 'prevent from cycling
            endif
    
    LowSide: 'look for GPIO.3 points and GPIO.3 GPIO.2
        IF GPIO.3 = 1 Then lowside 'wait for phase to go low
        GPIO.5 = 0 'weight input to sense zero crossing
        PauseUs dim 'wait for dim period
        TRISIO.2=0 'fire GPIO.2
        GPIO.2 = 0
        PauseUs 400
        TRISIO.2=1
    
    HighSide:
        IF GPIO.3 = 0 Then HighSide
        GPIO.5 = 1
        PauseUs dim
        TRISIO.2=0
        GPIO.2 = 0
        PauseUs 400
        TRISIO.2=1
        GoTo start
    Good luck!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Hey steve - that looks like some funky stuff yr doing there - tho it's still saying that it's unable to fit variable b0. Any easy way to solve it? Else I'm gonna move to a 12F - seems such a waste tho as I'm only using 2 I/Os. I'm trying to design it for a production run - so I did like the cost and form of the 10F.

  9. #9
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    be sure you copy past the whole thing above. It compile ok to me. I did few minors change to the one you posted before.

    I guess about a IF (condition a) AND (condition b) then... line... right?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  10. #10
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Unhappy

    Hey - copied it all across and it compiled thanks - however - it won't program :s

    "ROM programming error at address 0x0000
    Good 0x0025
    Bad 0x0FE7"

    Any ideas on what that could mean?

    Thanks
    Brendon

  11. #11
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    One thing that strikes me as odd is that when you look at the hex file im my programmer it's in groups of 3 instead of groups of 4 - any clues why?

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    This programming error message seems to be popular now. Do a search within the forum or the website of your device programmer AND/OR software.

    Compile and program fine here.
    <img src='http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1111&stc=1&d=116044343 1">
    Attached Images Attached Images  
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  13. #13
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    As mister_e mentioned, it is a popular error. You seem to be having a low voltage issue on your programmer.

    If you can, try a simple code on 12F508.

    If you get the same error then you definitely have a low voltage issue.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  14. #14
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I haven't tested this, but I think this should work if your code is not going to
    grow or use other PBP commands.

    Try this.

    Comment out RR1, RM1, and FLAGS in your PBPPIC12.RAM file and save it.

    Code:
    R0      VAR     WORD BANK0 SYSTEM       ' System Register
    R1      VAR     WORD BANK0 SYSTEM       ' System Register
    R2      VAR     WORD BANK0 SYSTEM       ' System Register
    R3      VAR     WORD BANK0 SYSTEM       ' System Register
    R4      VAR     BYTE $0F SYSTEM		' System Register
    ;RR1     VAR     BYTE BANK0 SYSTEM       ' Pin 1 Register
    ;RM1     VAR     BYTE BANK0 SYSTEM       ' Pin 1 Mask
    GOP     VAR     BYTE BANK0 SYSTEM       ' Gen Op Parameter
    ;FLAGS   VAR     BYTE BANK0 SYSTEM       ' Static flags
    OPTION_REG VAR  BYTE BANK0 SYSTEM       ' OPTION_REG shadow register
    SOFT_STACK VAR	BYTE[4] SYSTEM		' Software return stack
    SOFT_STACK_PTR VAR BYTE BANK0 SYSTEM	' Sotware stack pointer
    PBP will allocate RAM space by default. Even if it's never used.

    Now simplify this equation by breaking it down;

    Change: IF time2 >= 2 AND b0 = 2 Then dim = dim + 1

    to;
    Code:
    IF time2 >= 2 Then
           IF b0 = 2 Then
              dim = dim + 1 'if over 20 min then start dimming dim period 4 cycles = 10 mins
           ENDIF
    ENDIF
    It's the same logic, but PBP doesn't create temp variables just to figure it out.

    Try compiling your code for a 12F629 without making this change, and take a
    peek at how temp variables get created in the .LST file.

    Now make the change, and re-compile it for the 12F629. Temp variables are
    gone. Works the same on pretty much any target I suspect. Just simplify your
    equations by breaking them down into smaller parts. Especially for little parts
    like the 10F.

    Don't forget you have those line items commented out in your .RAM file. As
    your program grows, you compile for another device, use more PBP commands
    etc, one or more might be needed by a library function. You should get an
    error if you have one commented out that's needed.

    It should compile & work leaving you with a whopping whole byte of free
    RAM...;o}
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  15. #15
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Sure it's another approach wich also works and it's free-up 3 Bytes of RAM.

    SOFT_STACK -> 4 BYTE
    SOFT_STACK_PTR -> 1 Byte

    The advantage to use of the EXT modifier avoid to comment-out those .Lib file. Also nice for short-term memory like mine as i should forgot to remove the comment in the right .LIB file

    Quote Originally Posted by bruce
    IF time2 >= 2 Then
    IF b0 = 2 Then
    dim = dim + 1 'if over 20 min then start dimming dim period 4 cycles = 10 mins
    ENDIF
    ENDIF
    Yup sounds familiar to my example
    Last edited by mister_e; - 12th October 2006 at 04:16.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  16. #16
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Another option that does not involve ASM, EXT, or altering files (but should work even though it is slightly contrived.)... You are low on Data Ram but big on Program Space (200 of 512 words used) right?

    1) Change the IF-AND-THEN to nested IF-THENs as noted by Steve and Bruce

    2) b0 ranges from 0-3 (2 bits). Drop the b0 variable and stash the values in OPTION_REG<1:0> (with the prescaler pointed to the Timer, which you are not using)

    3)Time2 ranges from 0-73 (7 bits). Drop the Time2 variable and store the lower 5 bits in the FSR register, the 6th bit in OPTION_REG<2>, and the 7th bit in OPTION_REG<4>.

    The rest of your variables fit – the code to deal with the above changes adds some complexity but would not be hard to implement.

    Yet another option (you said commercial product – the price difference between the 202 and the 629 in quantity is about 0.30USD). Live with the loss or charge your customer a little more and have a clean solution with the 12F629.

    Yet another option – take a week to learn ASM if you do not already know it. This part (10F202) has little complexity and it would not be difficult to convert your code to ASM. Bruce has a good ASM example posted in the example code section plus there are lots of good tutorials out there.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  17. #17


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi,

    Depending on the volume of sales you expect, it may be worth the expense of switching to a different compiler for this project.
    I’ve heard that the Hitech PIC C-compiler is very good at producing lean and reliable code. It’s pricey though.

    Another option is the Proton compiler (at least the latest version that comes with PDS). A guy on that forum was able to compile your program using only 12 vars. This is a much cheaper option and should be really easy to port over from PBP (both are basic compilers).

    Alternatively, maybe someone on the PDS forum could simply give you the HEX file for your program (for free or maybe only a small fee).
    It’s a pretty simple program so, unless you’re planning on making lots of changes to it, that may be the cheapest option.

    Cheers,
    ---> picnaut

  18. #18
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Question

    Quote Originally Posted by paul borgmeier

    Yet another option – take a week to learn ASM if you do not already know it. This part (10F202) has little complexity and it would not be difficult to convert your code to ASM. Bruce has a good ASM example posted in the example code section plus there are lots of good tutorials out there.
    Off/on topic... Can I use PBP to compile for the 202, but other than declaring constants and variables, do everything in assembly? And...will this add code to the program as opposed to writing it on MPASM?

    Thanks,
    Ron

  19. #19
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Unhappy

    Duh!
    I asked the same question in February. I should probably do a search before I post and embarrass myself!

    Ron

  20. #20
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Ron Marcus
    Duh!
    I asked the same question in February. I should probably do a search before I post and embarrass myself!

    Ron

    It shall be your right to ask the same question again if you did not get the (an) answer in Feb. I see no embarrassing.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  21. #21
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    No...I got the answer back then too! I've got to switch to lead free solder!

  22. #22
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by picnaut
    Another option is the Proton compiler (at least the latest version that comes with PDS).
    i know you could'nt resist...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  23. #23
    Join Date
    Oct 2005
    Location
    New Zealand
    Posts
    171


    Did you find this post helpful? Yes | No

    Default

    Thanks for all your help guys very useful info all of you - I'll have a play with it next week and see what I can sort if I can't sort it I might see if one of you guys wouldn't mind being paid to convert to asm.

    Cheers

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. problem with variable on PIC10f202
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th October 2009, 17:29
  3. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. Trouble with Serin2 and variable size
    By Ryan7777 in forum Serial
    Replies: 6
    Last Post: - 5th October 2006, 16:40

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