PDA

View Full Version : PIC10F202 Variable trouble



George
- 6th October 2006, 03:50
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:

paul borgmeier
- 6th October 2006, 04:13
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.

George
- 8th October 2006, 20:47
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

sayzer
- 8th October 2006, 21:31
Hi George,

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


-------------------------

George
- 8th October 2006, 21:52
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

mister_e
- 9th October 2006, 03:46
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...

mister_e
- 9th October 2006, 05:03
Not tested but assuming you're not using any Gosubs... it could work.

Inspiration taken bellow
http://www.picbasic.co.uk/forum/showthread.php?t=3891&highlight=modifier

Sure it could be dangerous.... compile O.K


@ 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!

George
- 9th October 2006, 21:07
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.

mister_e
- 9th October 2006, 21:23
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?

George
- 9th October 2006, 22:26
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

George
- 9th October 2006, 22:58
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?

mister_e
- 10th October 2006, 02:24
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=1160443431">

sayzer
- 10th October 2006, 03:28
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.

Bruce
- 12th October 2006, 04:00
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.



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;


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}

mister_e
- 12th October 2006, 04:10
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 :D



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 :D

paul borgmeier
- 12th October 2006, 09:52
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.

picnaut
- 12th October 2006, 16:21
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,

Ron Marcus
- 12th October 2006, 17:03
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

Ron Marcus
- 12th October 2006, 18:11
Duh!
I asked the same question in February. I should probably do a search before I post and embarrass myself!

Ron

sayzer
- 12th October 2006, 18:53
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.

Ron Marcus
- 12th October 2006, 18:56
No...I got the answer back then too! I've got to switch to lead free solder!

mister_e
- 12th October 2006, 21:17
Another option is the Proton compiler (at least the latest version that comes with PDS).

i know you could'nt resist...

George
- 13th October 2006, 02:14
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