EmbeddedRelated.com
Forums

Help for a beginner in MSP430

Started by Abhay June 28, 2011
Using either bitwise_OR or + is OK most of the time.

But if the data by mistake includes the same value more than ones.
The result will be very different.

2 + 4 + 8 + 16 = 30
2 or4 or8 or16 = 30

2 + 4 + 8 + 8 = 22 (not the same as below)
2 or4 or8 or8 = 14

Beginning Microcontrollers with the MSP430

On Sun, Jul 10, 2011 at 8:56 AM, Tony wrote:

> **
> Using either bitwise_OR or + is OK most of the time.
>
> But if the data by mistake includes the same value more than ones.
> The result will be very different.
>
> 2 + 4 + 8 + 16 = 30
> 2 or4 or8 or16 = 30
>
> 2 + 4 + 8 + 8 = 22 (not the same as below)
> 2 or4 or8 or8 = 14
Thank you for pointing out this potential pitfall. I just corrected my
latest project to take care of this.

--
Henry von Tresckow (hvontres)


On 9 July 2011 19:02, Peter Johansson wrote:
> On Sat, Jul 9, 2011 at 9:50 AM, Stuart_Rubin wrote:
>
>> For some strange reason, much, if not all, of the TI example code uses the +, not |.

And that example is sadly contaminating a lot of other code, too.

> Does anyone know why this is? Is there ever a reason to use "+" over
> "|" for setting/manipulating bitfields like this?

No. As for reference, The Book says (any typos are probably mine):

[0, p.48]

The bitwise AND operator & is often used to mask off some set of bits;
for example,

n = n & 0177;

sets to zero all but the low-order 7 bits of n.

The bitwose OR operator | is used to turn bits on:

x = x | SET_ON;

sets to one in x the bits that are set to one in SET_ON.
[0, p.149]

Certain idioms appear frequently:

flags |= EXTERNAL | STATIC;

turns on EXTERNAL and STATIC bits in flags, while

flags &= ~(EXTERNAL | STATIC);

turns them off and

if ((flags & (EXTERNAL | STATIC)) == 0) ...

is true if both bits are off.
It then continues on to bitfields. The Book is, of course, right when
it comes to C :)
[0] Brian W. Kernighan, Dennis M. Ritchie. The C Programmin Language.
Second Edition. Prentice Hall 2009.

--
I appear to be temporarily using gmail's horrible interface. I
apologise for any failure in my part in trying to make it do the right
thing with post formatting.
Dear,
Pls. check for the Flag concept.

Regards,
Milind Pagdhare
Embedded Technology Consultant.
On 7/11/11, Harri Haataja wrote:
> On 9 July 2011 19:02, Peter Johansson wrote:
>> On Sat, Jul 9, 2011 at 9:50 AM, Stuart_Rubin
>> wrote:
>>
>>> For some strange reason, much, if not all, of the TI example code uses
>>> the +, not |.
>
> And that example is sadly contaminating a lot of other code, too.
>
>> Does anyone know why this is? Is there ever a reason to use "+" over
>> "|" for setting/manipulating bitfields like this?
>
> No. As for reference, The Book says (any typos are probably mine):
>
> [0, p.48]
>
> The bitwise AND operator & is often used to mask off some set of bits;
> for example,
>
> n = n & 0177;
>
> sets to zero all but the low-order 7 bits of n.
>
> The bitwose OR operator | is used to turn bits on:
>
> x = x | SET_ON;
>
> sets to one in x the bits that are set to one in SET_ON.
> [0, p.149]
>
> Certain idioms appear frequently:
>
> flags |= EXTERNAL | STATIC;
>
> turns on EXTERNAL and STATIC bits in flags, while
>
> flags &= ~(EXTERNAL | STATIC);
>
> turns them off and
>
> if ((flags & (EXTERNAL | STATIC)) == 0) ...
>
> is true if both bits are off.
> It then continues on to bitfields. The Book is, of course, right when
> it comes to C :)
> [0] Brian W. Kernighan, Dennis M. Ritchie. The C Programmin Language.
> Second Edition. Prentice Hall 2009.
>
> --
> I appear to be temporarily using gmail's horrible interface. I
> apologise for any failure in my part in trying to make it do the right
> thing with post formatting.
>
any one can help me building pulse oxi with msp 430?
2011/7/11, Hans Henry von Tresckow :
> On Sun, Jul 10, 2011 at 8:56 AM, Tony wrote:
>
>> **
>> Using either bitwise_OR or + is OK most of the time.
>>
>> But if the data by mistake includes the same value more than ones.
>> The result will be very different.
>>
>> 2 + 4 + 8 + 16 = 30
>> 2 or4 or8 or16 = 30
>>
>> 2 + 4 + 8 + 8 = 22 (not the same as below)
>> 2 or4 or8 or8 = 14
> Thank you for pointing out this potential pitfall. I just corrected my
> latest project to take care of this.
>
> --
> Henry von Tresckow (hvontres)
>
Do we really need another MSP430-based pulsed oximeter? And aren't there TONS of examples of these out there?

If this is a student project, you're just copying someone's work. If it's a business, I think you need to do some more research.

Or at least ask for more specific, targeted help.

--- In m..., julius hasan wrote:
>
> any one can help me building pulse oxi with msp 430?
>

--- In m..., Peter Johansson wrote:
>
> On Sat, Jul 9, 2011 at 9:50 AM, Stuart_Rubin wrote:
>> For some strange reason, much, if not all, of the TI example code
>> uses the +, not |.

> Does anyone know why this is? Is there ever a reason to use "+" over
> "|" for setting/manipulating bitfields like this?

if you are putting a new value into a bitfield, where you need to clear some bits, set other bits, and leave the rest of the bits unchanged, one would clear out all the bits to be manipulated with the bitwise AND, the set the required bits with the bitwise OR. At this point one is ORing a 0 with a 1, which is the same operation as adding (no carry). In some microprocessors, adding takes less machine cycles to execute than setting bits.

do you have any sample of it?i can't copy it from any friends of mine
cause this ic is not available here in indonesia, please help me to
build one.this is for my final project

2011/7/13, Stuart_Rubin :
> Do we really need another MSP430-based pulsed oximeter? And aren't there
> TONS of examples of these out there?
>
> If this is a student project, you're just copying someone's work. If it's a
> business, I think you need to do some more research.
>
> Or at least ask for more specific, targeted help.
>
> --- In m..., julius hasan wrote:
>>
>> any one can help me building pulse oxi with msp 430?
>>
Did you look at this:
http://focus.ti.com/mcu/docs/litabsmultiplefilelist.tsp?sectionId&tabId02&literatureNumber=slaa274a&docCategoryId=1&familyId4
or this:
http://focus.ti.com/mcu/docs/litabsmultiplefilelist.tsp?sectionId&tabId02&literatureNumber=slaa458&docCategoryId=1&familyId4

I would suggest that you call your local TI representative and ask if you can get one of the demo boards shown in this clip:
http://www.youtube.com/watch?vSUiHYGDMg

Sadly, if this is too hard for a year-long final project, then perhaps the project is too much. I think you can do it, though.

Stuart

--- In m..., julius hasan wrote:
>
> do you have any sample of it?i can't copy it from any friends of mine
> cause this ic is not available here in indonesia, please help me to
> build one.this is for my final project
>
> 2011/7/13, Stuart_Rubin :
> > Do we really need another MSP430-based pulsed oximeter? And aren't there
> > TONS of examples of these out there?
> >
> > If this is a student project, you're just copying someone's work. If it's a
> > business, I think you need to do some more research.
> >
> > Or at least ask for more specific, targeted help.
> >
> > --- In m..., julius hasan wrote:
> >>
> >> any one can help me building pulse oxi with msp 430?
> >>
> >
> >
> >
>