PDA

View Full Version : Code Compatibility Issue



ALFRED
- 5th July 2007, 19:59
Hello, I am working on a program that checks the continuity of several circuits and processes the data to genarate several output signals. I have the code working flawlessly on my 16F84A but when I run the same code on other PICs such as the 16F88 and 16F767 it does not run properly. The code seems to constantly reset the output signals resulting in a signal that rapidly switches from high to low when it should be steady high or low (this is probably not the only thing that the code is doing wrong). I have disabled the ADC module and the comparators on the PICs that have them and I have no idea what I am doing wrong. I have tried disabling the watchdog timers and changing a few other configuration setting but nothing seems to work. My final application will most likly use a PIC16F57 so just using the F84A is not an option. Does anyone have any ideas about what I might be doing wrong.
Thanks!

skimask
- 5th July 2007, 20:40
Hello, I am working on a program that checks the continuity of several circuits and processes the data to genarate several output signals. I have the code working flawlessly on my 16F84A but when I run the same code on other PICs such as the 16F88 and 16F767 it does not run properly...................Does anyone have any ideas about what I might be doing wrong.
Thanks!

PBP, the actual text based source code is relatively transferrable between PICs. However, at the actual binary level, trying to run code for a 16F84a on anything will get you nothing but trouble. You'll probably only have to recompile it for the PIC you want to use. At any rate, you MUST check the datasheets to see the main differences between the 2 types of PICs, the differences in the pins, differences in registers, etc. You can't just go slappin' one PICs code into another type and expect it to work.

ALFRED
- 5th July 2007, 22:49
I have been recompiling the code for the PIC I want to use all along and it still does not work. My hardware is built so that all the corsponding I/O pins on ports A and B are conected to the same things on each PIC. In my own experience I have been able to use the PIC16F767 normaly by disabling the ADC and the comparator but this time that doesnt seem to be enough. Any other ideas?

skimask
- 5th July 2007, 23:20
Any other ideas?

Without seeing any code, yes, I do have an idea...
Show some code...

andrewwaack
- 5th July 2007, 23:27
hi its andrew i just compilled your program using micro code studio (pic basci pro compiller ) and it compiles fine microcode studio is a free download
i don't know what compiller editor software you are using but you could try these 2 programs


andrew

Archangel
- 6th July 2007, 01:56
Hi Andrew,
Just a Wild Arse Guess on my part, but the config registers look much more complicated on that particular chip than the 16f84, which is simple. See 15.1 of the data sheet for more confusion. :)
JS

ALFRED
- 6th July 2007, 03:22
Here's the code:

TRISA = 0
TRISB = 2
CMCON = 7
ADCON1 = %00001111
ADCON0 = 0

symbol Off_1 = PortA.0
Symbol On_1 = PortA.1

symbol Off_2 = PortA.2
symbol On_2 = PortA.3

Symbol Speaker = PortA.4

SYMBOL Ground_1 = PortB.0
SYMBOL Positive_1 = PortB.1
symbol Lame_1 = PortB.2

symbol Ground_2 = PortB.3
Symbol Positive_2 = PortB.4
Symbol Lame_2 = PortB.5

SYMBOL Switch = PortA.5
symbol LED_1 = PortB.6
Symbol LED_2 = PortB.7


Positive_Ground_1 var bit
Ground_Lame_1 var bit
Positive_Lame_1 var bit
Positive_Bell_1 var bit

Positive_Ground_2 var bit
Ground_Lame_2 var bit
Positive_Lame_2 var bit
Positive_Bell_2 var bit

PG1_Count var byte
PG2_Count var byte
PL1_Count var byte
PL2_Count var byte
Cal var byte
Lockout var Word
Lockout_Cal var word

On1_Flag var bit
Off1_Flag var bit
On2_Flag var bit
Off2_Flag var bit

let cal = 18
let lockout_cal = 373

'''''''''''''
high on_1
pause 500
low on_1
high off_1
pause 500
low off_1
high off_2
pause 500
low off_2
high on_2
pause 500
low on_2
'''''''''''''''

input lame_1
INPUT LAME_2
Foil:
input positive_1
input positive_2
input ground_1
input ground_2
high positive_1
let positive_ground_1 = Ground_1
let positive_lame_1 = lame_2
let positive_bell_1 = ground_2
low positive_1

input positive_1
input positive_2
input ground_1
input ground_2
high positive_2
let positive_ground_2 = ground_2
let positive_lame_2 = lame_1
let positive_bell_2 = ground_1
low positive_2
input positive_2
high ground_1
let ground_lame_1 = lame_1
low ground_1

INPUT GROUND_1
high ground_2
let ground_lame_2 = lame_2
low ground_2

if positive_ground_1 = 0 and positive_bell_1 = 0 then
let pg1_count = pg1_count + 1
else
let pg1_count = 0
endif

if positive_ground_2 = 0 and positive_bell_2 = 0 then
let pg2_count = pg2_count + 1
else
let pg2_count = 0
endif

if positive_lame_1 = 1 AND POSITIVE_GROUND_1 = 0 then
let pl1_count = pl1_count + 1
else
let pl1_count = 0
endif

if positive_lame_2 = 1 AND POSITIVE_GROUND_2 = 0 then
let pl2_count = pl2_count + 1
else
let pl2_count = 0
endif


if pl1_count => cal then
high on_1
let on1_flag = 1
endif

if pl2_count => caL then
high on_2
let on2_flag = 1
endif

if pg1_count => cal AND PL1_COUNT < CAL then
high off_1
let off1_flag = 1
endif

if pg2_count => cal AND PL2_COUNT < CAL then
high off_2
let off2_flag = 1
endif

LET LED_1 = GROUND_LAME_1
LET LED_2 = GROUND_LAME_2

if On1_flag = 1 or off2_flag = 1 or on2_flag = 1 or off1_flag = 1 then
let lockout = lockout + 1
else
let lockout = 0
endif


if lockout => lockout_cal then
pause 2000
low on_1
low on_2
low off_1
low off_2
let on1_flag = 0
let on2_flag = 0
let off1_flag = 0
let off2_flag = 0
endif
goto foil

end

skimask
- 6th July 2007, 03:51
See the PBP manual, section 4.7...(may as well look at section 5.40 while you're at it)...

trisa=0:trisb=2:cmcon=7:adcon1=15:adcon0=0:Off_1 var PortA.0:On_1 var PortA.1:Off_2 var PortA.2:On_2 var PortA.3:Speaker var PortA.4:Ground_1 var PortB.0:Positive_1 var PortB.1:Lame_1 var PortB.2
Ground_2 var PortB.3:Positive_2 var PortB.4:Lame_2 var PortB.5:Switch var PortA.5:LED_1 var PortB.6:LED_2 var PortB.7:Positive_Ground_1 var bit:Ground_Lame_1 var bit:Positive_Lame_1 var bit
Positive_Bell_1 var bit:Positive_Ground_2 var bit:Ground_Lame_2 var bit:Positive_Lame_2 var bit:Positive_Bell_2 var bit:PG1_Count var byte:PG2_Count var byte:PL1_Count var byte:PL2_Count var byte
Cal var byte:Lockout var Word:Lockout_Cal var word:On1_Flag var bit:Off1_Flag var bit:On2_Flag var bit:Off2_Flag var bit:cal=18:lockout_cal=373:high on_1: pause 500:low on_1:high off_1: pause 500
low off_1:high off_2: pause 500:low off_2:high on_2: pause 500:low on_2:input lame_1:INPUT LAME_2
Foil:
input positive_1:input positive_2:input ground_1:input ground_2:high positive_1: positive_ground_1=Ground_1: positive_lame_1=lame_2: positive_bell_1=ground_2:low positive_1:input positive_1
input positive_2:input ground_1:input ground_2:high positive_2: positive_ground_2=ground_2: positive_lame_2=lame_1: positive_bell_2=ground_1:low positive_2:input positive_2:high ground_1
ground_lame_1=lame_1:low ground_1:iNPUT GROUND_1:high ground_2:ground_lame_2=lame_2:low ground_2
if positive_ground_1 = 0 and positive_bell_1 = 0 then
pg1_count = pg1_count + 1
else
pg1_count = 0
endif
if positive_ground_2 = 0 and positive_bell_2 = 0 then
pg2_count = pg2_count + 1
else
pg2_count = 0
endif
if positive_lame_1 = 1 AND POSITIVE_GROUND_1 = 0 then
pl1_count = pl1_count + 1
else
pl1_count = 0
endif
if positive_lame_2 = 1 AND POSITIVE_GROUND_2 = 0 then
pl2_count = pl2_count + 1
else
pl2_count = 0
endif
if pl1_count => cal then
high on_1 : on1_flag = 1
endif
if pl2_count => caL then
high on_2 : on2_flag = 1
endif
if pg1_count => cal AND PL1_COUNT < CAL then
high off_1 : off1_flag = 1
endif
if pg2_count => cal AND PL2_COUNT < CAL then
high off_2 : let off2_flag = 1
endif
LED_1 = GROUND_LAME_1 : LED_2 = GROUND_LAME_2
if On1_flag = 1 or off2_flag = 1 or on2_flag = 1 or off1_flag = 1 then
lockout = lockout + 1
else
lockout = 0
endif
if lockout => lockout_cal then
pause 2000 : low on_1 : low on_2 : low off_1 : low off_2 : on1_flag = 0 : on2_flag = 0 : off1_flag = 0 : off2_flag = 0
endif
goto foil
end

Darrel Taylor
- 6th July 2007, 04:49
Is anyone supposed to be able to actually read that?

Everyone's got a "Colon", and they all stink. :eek:
<br>

mister_e
- 6th July 2007, 08:22
<table><td>http://www.mister-e.org/Pics/LaughingDog</td><td>http://www.mister-e.org/Pics/PitcherBriqueParLaTete.gif</td><td>http://www.mister-e.org/Pics/deadhorse.gif</td></table>

skimask
- 6th July 2007, 13:50
Is anyone supposed to be able to actually read that?
Everyone's got a "Colon", and they all stink. :eek:
<br>

It's exactly the same code, except for the changes/fixes...you know it, I know it, the guy that wrote it knows it and should be able to read his own stuff....and you don't have to scroll thru 17 pages of stuff to get to the end...

Darrel Taylor
- 6th July 2007, 15:32
It's exactly the same code, except for the changes/fixes...

Ha, It's exactly the same. Except EVERYTHING'S different.

You've changed the SYMBOL's to VAR's, removed the LET's and changed a binary number to decimal. And while the program now looks completely different. After compiling, the HEX file will be byte for byte identical to the original code. No changes. No fixes.


you know it, I know it, the guy that wrote it knows it and should be able to read his own stuff....and you don't have to scroll thru 17 pages of stuff to get to the end...
Since it doesn't look anything like the original program, the "guy that wrote it" now has to spend probably several hours searching colon by colon, trying to find what it was that you changed. (took me an hour)

And won't he be pissed after doing all that, only to find out that it doesn't make any difference. Because it's exactly the same program, just written with different words, and a really bad format.

There's no way to follow the flow of the program. You can't see any type of structure. It's just a bunch of lines of code. Very long lines at that. My guess is that you have a Wide screen monitor and make the code fit a maximized window, all the way across the screen. For anyone with a normal sized screen, they're now scrolling left and right, instead of up and down. And when viewing in a browser, it all wraps around and you can't find where one line ends and the next one begins.

And one last problem ... There's no room for comments.
Come back to that program in 6 months, and you're going to need some laxitives for those Colon's.

On a scale of 1-10, I'd give this formatting a 9 for the the best way to NOT write your program.
<br>

skimask
- 6th July 2007, 16:00
Ha, It's exactly the same. Except EVERYTHING'S different.
And I come back to reading the manual once again...


You've changed the SYMBOL's to VAR's, removed the LET's and changed a binary number to decimal. And while the program now looks completely different. After compiling, the HEX file will be byte for byte identical to the original code. No changes. No fixes.
The manual says 'Symbol can only be used to alias a variable, not to create it'. As far as the LET and SYMBOL, I referenced both of those at the beginning of the post... No changes, no fixes? I'm wondering...


Since it doesn't look anything like the original program, the "guy that wrote it" now has to spend probably several hours searching colon by colon, trying to find what it was that you changed. (took me an hour)
Huh...I'm fairly handy with an 'Enter' key, and maybe a little bit of the 'Delete' key. Only took me about a couple of minutes or so to get one command per line. And again, the guy should be able to recognize what's where in the first place.


And won't he be pissed after doing all that, only to find out that it doesn't make any difference.
Maybe so, but maybe he'll learn a bit of something here and there and fix his own problem.


There's no way to follow the flow of the program. You can't see any type of structure. It's just a bunch of lines of code. Very long lines at that. My guess is that you have a Wide screen monitor and make the code fit a maximized window, all the way across the screen. For anyone with a normal sized screen, they're now scrolling left and right, instead of up and down.
Could be... I run 16 x 12, turned 90 degrees. And who's to say what's normal? What does your newspaper, comic book, any other book look like? I'll bet if you put a page from one of those across your screen, it would fit a lot better if the screen was rotated about 90 degree, left or right... If anything, I'd say the way 'normal' people use a monitor is 'abnormal' compared to the way people have been reading printed material for years.


And one last problem ... There's no room for comments. Come back to that program in 6 months, and you're going to need some laxitives for those Colon's.
True...but I won't be coming back to it.


On a scale of 1-10, I'd give this formatting a 9 for the the best way to NOT write your program.
I think what you really mean is that you'd give this formatting a 9 for the best way NOT to write YOUR program.
However, I'd give this formatting a 10 for the BEST way to write MY program.

Pic_User
- 6th July 2007, 16:09
I use “find and replace” to “de-colon-ize” the code and flip it from a big horizontal file to a big vertical file.

Two problems, have to watch for wanted colons like labels, and the vertical code still has no comments. :)

-Adam-

skimask
- 6th July 2007, 16:12
I use “find and replace” to “de-colon-ize” the code and flip it from a big horizontal file to a big vertical file. Two problems, have to watch for wanted colons like labels, and the vertical code still has no comments. :)
-Adam-

All the labels have a space after the colon. The colons in the middle of the code (except for here with the vB smilies and such) always have characters on both sides. And Cntrl-H (Word) and Cntrl-R (MCS) are my friend.

Darrel Taylor
- 6th July 2007, 16:23
The manual says 'Symbol can only be used to alias a variable, not to create it'.
The only uses of SYMBOL in the original program was as an ALIAS. So nothing disagrees with the manual.

And LET is shown in the manual as a valid statement. (although optional)

Huh...I'm fairly handy with an 'Enter' key, and maybe a little bit of the 'Delete' key. Only took me about a couple of minutes or so to get one command per line.
So to read your re-formatted program, we have to re-format it again???
<br>

skimask
- 6th July 2007, 16:29
The only uses of SYMBOL in the original program was as an ALIAS. So nothing disagrees with the manual.
But it doesn't really agree either. doesn't say anything about being able to use one of the 'predefined' variables, such as PortA...


So to read your re-formatted program, we have to re-format it again???
<br>
You don't have to do anything...

Hey, at least I'm not wasting time posting spam for cheap phones, laptops and camera's! :D

mister_e
- 6th July 2007, 19:01
Let's see if i remove my usual 'code template' from and try to format the code a little bit... i've never read/check it carefully if it make sense so far... at least, no compilation error.

<font color="#000000"> TRISA = 0
TRISB = 2
CMCON = 7
ADCON1 = 15
ADCON0 = 0

Ground_1 <font color="#000080">VAR </font>PortB.0
Ground_2 <font color="#000080">VAR </font>PortB.3
Lame_1 <font color="#000080">VAR </font>PortB.2
Lame_2 <font color="#000080">VAR </font>PortB.5
LED_1 <font color="#000080">VAR </font>PortB.6
LED_2 <font color="#000080">VAR </font>PortB.7
Off_1 <font color="#000080">VAR </font>PortA.0
Off_2 <font color="#000080">VAR </font>PortA.2
On_1 <font color="#000080">VAR </font>PortA.1
On_2 <font color="#000080">VAR </font>PortA.3
Positive_1 <font color="#000080">VAR </font>PortB.1
Positive_2 <font color="#000080">VAR </font>PortB.4
Speaker <font color="#000080">VAR </font>PortA.4
Switch <font color="#000080">VAR </font>PortA.5

Cal <font color="#000080">VAR BYTE
</font>Ground_Lame_1 <font color="#000080">VAR BIT
</font>Ground_Lame_2 <font color="#000080">VAR BIT
</font>Lockout <font color="#000080">VAR WORD
</font>Lockout_Cal <font color="#000080">VAR WORD
</font>On1_Flag <font color="#000080">VAR BIT
</font>Off1_Flag <font color="#000080">VAR BIT
</font>On2_Flag <font color="#000080">VAR BIT
</font>Off2_Flag <font color="#000080">VAR BIT
</font>PG1_Count <font color="#000080">VAR BYTE
</font>PG2_Count <font color="#000080">VAR BYTE
</font>PL1_Count <font color="#000080">VAR BYTE
</font>PL2_Count <font color="#000080">VAR BYTE
</font>Positive_Bell_1 <font color="#000080">VAR BIT
</font>Positive_Bell_2 <font color="#000080">VAR BIT
</font>Positive_Ground_1 <font color="#000080">VAR BIT
</font>Positive_Ground_2 <font color="#000080">VAR BIT
</font>Positive_Lame_1 <font color="#000080">VAR BIT
</font>Positive_Lame_2 <font color="#000080">VAR BIT


</font>Cal=18
Lockout_Cal=373
<font color="#000080">HIGH </font>On_1
<font color="#000080">PAUSE </font>500
<font color="#000080">LOW </font>On_1

<font color="#000080">HIGH </font>Off_1
<font color="#000080">PAUSE </font>500
<font color="#000080">LOW </font>Off_1

<font color="#000080">HIGH </font>Off_2
<font color="#000080">PAUSE </font>500
<font color="#000080">LOW </font>Off_2

<font color="#000080">HIGH </font>On_2
<font color="#000080">PAUSE </font>500
<font color="#000080">LOW </font>On_2

<font color="#000080">INPUT </font>Lame_1
<font color="#000080">INPUT </font>Lame_2

Foil:
<font color="#000080">INPUT </font>Positive_1
<font color="#000080">INPUT </font>Positive_2
<font color="#000080">INPUT </font>Ground_1
<font color="#000080">INPUT </font>Ground_2
<font color="#000080">HIGH </font>Positive_1
Positive_Ground_1=Ground_1
Positive_Lame_1=Lame_2
Positive_Bell_1=Ground_2
<font color="#000080">LOW </font>Positive_1
<font color="#000080">INPUT </font>Positive_1
<font color="#000080">INPUT </font>Positive_2
<font color="#000080">INPUT </font>Ground_1
<font color="#000080">INPUT </font>Ground_2
<font color="#000080">HIGH </font>Positive_2
Positive_Ground_2=Ground_2
Positive_Lame_2=Lame_1
Positive_Bell_2=Ground_1
<font color="#000080">LOW </font>Positive_2
<font color="#000080">INPUT </font>Positive_2
<font color="#000080">HIGH </font>Ground_1
Ground_Lame_1=Lame_1
<font color="#000080">LOW </font>Ground_1
<font color="#000080">INPUT </font>Ground_1
<font color="#000080">HIGH </font>Ground_2
Ground_Lame_2=Lame_2
<font color="#000080">LOW </font>Ground_2

<font color="#000080">IF </font>(Positive_Ground_1 = 0) <font color="#000080">AND </font>(Positive_Bell_1 = 0) <font color="#000080">THEN
</font>PG1_Count = PG1_Count + 1
<font color="#000080">ELSE
</font>PG1_Count = 0
<font color="#000080">ENDIF

IF </font>(Positive_Ground_2 = 0) <font color="#000080">AND </font>(Positive_Bell_2 = 0) <font color="#000080">THEN
</font>PG2_Count = PG2_Count + 1
<font color="#000080">ELSE
</font>PG2_Count = 0
<font color="#000080">ENDIF

IF </font>(Positive_Lame_1 = 1) <font color="#000080">AND </font>(Positive_Ground_1 = 0) <font color="#000080">THEN
</font>PL1_Count = PL1_Count + 1
<font color="#000080">ELSE
</font>PL1_Count = 0
<font color="#000080">ENDIF

IF </font>(Positive_Lame_2 = 1) <font color="#000080">AND </font>(Positive_Ground_2 = 0) <font color="#000080">THEN
</font>PL2_Count = PL2_Count + 1
<font color="#000080">ELSE
</font>PL2_Count = 0
<font color="#000080">ENDIF

IF </font>PL1_Count =&gt; Cal <font color="#000080">THEN
HIGH </font>On_1
On1_Flag = 1
<font color="#000080">ENDIF

IF </font>PL2_Count =&gt; Cal <font color="#000080">THEN
HIGH </font>On_2
On2_Flag = 1
<font color="#000080">ENDIF

IF </font>(PG1_Count =&gt; Cal) <font color="#000080">AND </font>(PL1_Count &lt; Cal) <font color="#000080">THEN
HIGH </font>Off_1 : Off1_Flag = 1
<font color="#000080">ENDIF

IF </font>(PG2_Count =&gt; Cal) <font color="#000080">AND </font>(PL2_Count &lt; Cal) <font color="#000080">THEN
HIGH </font>Off_2
<font color="#000080">LET </font>Off2_Flag = 1
<font color="#000080">ENDIF

</font>LED_1 = Ground_Lame_1
LED_2 = Ground_Lame_2

<font color="#000080">IF </font>(On1_Flag = 1) <font color="#000080">OR </font>(Off2_Flag = 1) <font color="#000080">OR </font>(On2_Flag = 1) <font color="#000080">OR </font>(Off1_Flag = 1) <font color="#000080">THEN
</font>Lockout = Lockout + 1
<font color="#000080">ELSE
</font>Lockout = 0
<font color="#000080">ENDIF

IF </font>Lockout =&gt; Lockout_Cal <font color="#000080">THEN
PAUSE </font>2000
<font color="#000080">LOW </font>On_1
<font color="#000080">LOW </font>On_2
<font color="#000080">LOW </font>Off_1
<font color="#000080">LOW </font>Off_2
On1_Flag = 0
On2_Flag = 0
Off1_Flag = 0
Off2_Flag = 0
<font color="#000080">ENDIF

GOTO </font>Foil
<font color="#000080">END
</font>

now comments, code section, steps should fit

ALFRED
- 6th July 2007, 23:27
I fixed the problem. As it turned out there was no problem with my origonal code. The problem lay in the configuration of pin B0. I traced the bad signals I was getting back to that point with my oscilloscope and when I switched the functions of B0 over to C7 it worked as expected. Also, there is absolutly nothing wrong with using the SYMBOL command the way I used it in my origonal code. It simply throws in an alias name for a pin, constant or whatever and makes the program easier to work with. I also prefer to include the LET command as it gives the code a more finished look and in my opinion makes it easier to read.

Darrel Taylor
- 8th July 2007, 00:50
Just another jab with a pointy object ...

See the PBP manual, section 4.7...(may as well look at section 5.40 while you're at it)...

<table><tr><td align="center">From my "Little Green Book"<br>
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1840&stc=1&d=1183852037"></td><td align="center">From the online PDF<br>
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1841&stc=1&d=1183852045">
</td></tr></table>

P.S. Glad to hear it Alfred. <img src="http://www.picbasic.co.uk/forum/images/icons/icon14.gif">
<br><br>

skimask
- 8th July 2007, 01:05
Just another jab with a pointy object ...

Great...now I've got to figure out which manual is the latest version.
I know I used to have 2 or 3 PBP manuals laying around, I'm down to one now, Copyright 2004 inside the front cover. Not sure if that's the latest version or not...

Darrel Taylor
- 8th July 2007, 01:15
Well actually, that one was from a 2002 manual. (I think I'll throw that one away)
I have another one (2005) that has 5.40 as {LET}

But since you can't really know which version someone might have.
It might be a good idea to include the Title of the section along with the number.

Just a thought.
<br>