CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

:grin: I learned something today!
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah
Guest







PostPosted: Mon Dec 08, 2003 10:16 am     Reply with quote

Mark wrote:
I only suggested the test for zero/ nonzero changed. I never said a damn thing about CCS enabling/disabling interrupts! All the code I posted was from the C18 compiler not CCS.

Quote:

Only if you are counting in ones. The problem _still remains_ if the 6F byte can change between the two lines.

I don't care what units I am counting in. If I check the high byte first and it is a non zero value, then it doesn't matter what the low value is!

Bad way:
Code:

MOVLB  0x0                     while (Note);
MOVF   0x6f,0x0,0x1
IORWF  0x70,0x0,0x1
BZ     0xba6
BRA    0xb9c


Better way
Code:

MOVLB  0x0                     while (Note);
MOVF   0x70,0x0,0x1
IORWF  0x6f,0x0,0x1
BZ     0xba6
BRA    0xb9c



Quote:

Basically, you are asking CCS to modify the compiler to suit a particular useage you have, which may well cause problems in other situations (I would not want interrupts disabled for each test involving a number accessed both inside and outside an ISR), when this can already be done by coding carefully yourself.


Again, I don't care what they do. I just said it would be better! If I wanted them to change it, I would have emailed them! And again, if they wanted to change it, they could have their normal case and then a special case when the variable is volatile.


You are missing the point.
Your 'better' way, is only better if you are counting downwards. If the count is up, it is better to use the CCS approach. If the count is at FFFF, and wraps to zero between the tests, exactly the same problem exists when you test the high byte first, as when you test the low byte first and the count is down with the standard code.
Given that the default CCS hardware counts upwards, it makes sense for the compiler to make this the default...

Best Wishes
DragonPIC



Joined: 11 Nov 2003
Posts: 118

View user's profile Send private message

I like flags.
PostPosted: Mon Dec 08, 2003 2:22 pm     Reply with quote

I have had problems like this in the past, or have just worried about it. It's just like an interrupt being called before you have a chance to compare an "if equal to" statement. The variable gets incremented or decremented before you had a chance to comare the #'s and you miss your #. You then have to wait for the variable to go around the ben again (0x00 to 0xFF and down again). If your interrupt is that close where it cannot make the complete compare before the variable changes again, you are getting yourself into more trouble than just comparing MSB or LSB first. As your projects grows, it may just come back to kick you in the a**. By that time, the conflict in your program may be even harder to debug.

I guess it has become more of a habit for me now to just set flags in the interrupt, or making the compare and all needed actions inside the interrupt.
Ttelmah
Guest







Re: I like flags.
PostPosted: Mon Dec 08, 2003 3:11 pm     Reply with quote

DragonPIC wrote:
I have had problems like this in the past, or have just worried about it. It's just like an interrupt being called before you have a chance to compare an "if equal to" statement. The variable gets incremented or decremented before you had a chance to comare the #'s and you miss your #. You then have to wait for the variable to go around the ben again (0x00 to 0xFF and down again). If your interrupt is that close where it cannot make the complete compare before the variable changes again, you are getting yourself into more trouble than just comparing MSB or LSB first. As your projects grows, it may just come back to kick you in the a**. By that time, the conflict in your program may be even harder to debug.

I guess it has become more of a habit for me now to just set flags in the interrupt, or making the compare and all needed actions inside the interrupt.

Exactly.
You accept that whichever way the compiler did it, there would be a potential problem, and handle it.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group