Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege [RSS Feed]

#1 Nov. 4, 2005 15:57:08

David B.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege


> From: Vincent Trouilliez <>
>
>
>
> >About the -Os flag, I noticed this morning that it managed MASSIVE code
> >size reduction ! SO far I had been using just -O (I guess that means no
> >particular optimisation ?), and the program is about 13KB in size. With
> >-Os, it's only 10KB !!! Sadly, for some reason, when compiled with this
> >flag, my program misbehaves badly (I get massive corruption of the LCD
> >display) !! Too bad... :o(
>
> I believe it was Gerry Weinburg who once wrote that "optimization is
easy --
> if you don't have to get the right answer."
>
> I suspect, though, that some of your code might be relying on behavior
> that's not guaranteed (e.g., the value of an uninitialized variable)
rather
> than a bug in the optimizer.
>
> Regards,
>
> -=Dave
>

The bug is almost certainly a delay loop variable that is not declared
volatile. The delay function is probably something like:

void shortDelay(void) {
uint8_t n = 50;
while (n--);
}

That (might) work fine with little or no optomisation, but when optomisation
is on, it fails. The solution is simply to make n "volatile". Note that it
will not give you precise control of your delay - different optomisations or
different compiler versions might give slightly different code, and may or
may not inline the function. But in a case like this it doesn't matter -
all you are looking for is a slight delay, and it doesn't matter if it is
too long. I've done exactly this sort of thing (with "volatile", naturally)
myself for LCD routines.

mvh.,

David






_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Nov. 5, 2005 18:02:20

Vincent T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege


> The bug is almost certainly a delay loop variable that is not declared
> volatile. The delay function is probably something like:
>
> void shortDelay(void) {
> uint8_t n = 50;
> while (n--);
> }


Correct :-)
actually I did'nt even make it a function, as I use it only in one
place, the routine the send the character to LCD and waits 40us for the
LCD to process it.
I delcared the loop counter volatile and that indeed fixed it, thanks !
I can now enjoy the massive shrinking (13KB+ down to 10KB !) of the -Os
flag :o)


> Note that it will not give you precise control of your delay - different
> optomisations or
> different compiler versions might give slightly different code, and may or
> may not inline the function. But in a case like this it doesn't matter -
> all you are looking for is a slight delay, and it doesn't matter if it is
> too long.

That's it... minimum delay is about 40us, but the actual delay is
completely irrelevant, as long as it doesn't take an hour to print a
string...
But well, admittedly, it's only a work around, and no real substitue for
proper polling of the busy flag. But that will keep me going until all
else is sorted, and I can get round to wiring the R/W line and updating
the LCD routines.... Okay, should take under 15 minutes door to door,
but well, I think I am just lazy today ;-)



--
Vince



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 Nov. 5, 2005 18:44:04

David K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege


On Nov 4, 2005, at 6:18 PM, Vincent Trouilliez wrote:Correct :-)
actually I did'nt even make it a function, as I use it only in oneplace, the routine the send the character to LCD and waits 40us fortheLCD to process it.I delcared the loop counter volatile and that indeed fixed it,thanks !I can now enjoy the massive shrinking (13KB+ down to 10KB !) of the-Osflag :o)Didn't I tell you to poll the LCD's busy bit in the first place?Wouldn't have had the above problem if you had. :-)--
David Kelly N4HHE,
========================================================================
Whom computers would destroy, they must first drive mad.



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#4 Nov. 5, 2005 19:04:23

Vincent T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege


> Didn't I tell you to poll the LCD's busy bit in the first place?
> Wouldn't have had the above problem if you had. :-)
>
> --
> David Kelly N4HHE,


Yes yes, you did ;-)
So I decided to tackle it last night, and I wired the LCD R/W line.
I now poll the Busy Flag successfully, but I am a bit confused about how
it really works. The data sheet of the LCD module doesn't give much
detail about this particular point. All it says is to read a byte, and
that the BF is bit 7. But I use the 4 bit interface and somehow, I
couldn't get it to work. I now wonder if it's possible to read the LCD
in 4-bit mode at all ?! The data sheet is completely mute about this
point, they don't even give timing diagrams for the 4 bit mode, so I had
to improvise.
In despair, I tried to simply read bit 7 without pulsing the 'Enable'
line at all, and well, it happened to work. But had it not worked, I
would have been completely in the dark and would have had to give up on
polling, because of the lack of reference information in the datasheet !
What's that for a datasheet...pfff....


--
Vince



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] How to (efficeiently !!!) test a bitwithinamulti-byte intege [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support