IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Volatile Bit Adc_go @ Adcon0 . Go;
ryeg
post Nov 7 2009, 11:15 AM
Post #1


Enthusiast
**

Group: EstablishedMember
Posts: 103
Joined: 14-November 04
From: North Carolina, USA
Member No.: 505



What do these statment mean?

volatile bit adc_go @ ADCON0 . GO;
volatile bit adc_on @ ADCON0 . ADON;

It's one of those mysteries that I can't seem to find in the books.

Rye
update SourceBoost release 6.97 is available.
Download Now
Go to the top of the page
 
+Quote Post
Reynard
post Nov 7 2009, 01:40 PM
Post #2


Super Enthusiast
***

Group: EstablishedMember
Posts: 429
Joined: 24-October 07
From: Scotland
Member No.: 3,861



Hi Rye,

It is sort of shown on page 45 of the C manual.

Basically you are creating an alias for a bit address.

adc_go is the same as ADCON0.GO

Where you would say: ADCON0.GO = true;

you would say something that is clearer: adc_go = true;

Cheers

Reynard
Go to the top of the page
 
+Quote Post
IanM
post Nov 7 2009, 01:44 PM
Post #3


Enthusiast
**

Group: EstablishedMember
Posts: 146
Joined: 11-June 09
From: UK
Member No.: 5,160



QUOTE (ryeg @ Nov 7 2009, 11:15 AM) *
What do these statement mean?

volatile bit adc_go @ ADCON0 . GO;
volatile bit adc_on @ ADCON0 . ADON;

It's one of those mysteries that I can't seem to find in the books.

Rye

Now 'linkified' to the BoostC manual and part of the PIC mid-range datasheet. I doubt you will find them in any paper book. Its quite clear *what* the statements *do*, but *what* they *mean* depends on the context in which you use them. To clarify:

'adc_go' is thus defined as a single bit variable to start conversion and check if it is finished yet and 'adc_on' is defined as another single bit variable that turns the whole ADC module on or off.

The bit syntax is a BoostC language extension. The ANSI way of doing this would be to define a bitfield structure type to map bit names to positions in the register then cast an unsigned integer address to a pointer to the bitfield. Its OK for a couple of references but rapidly gets ugly when you have hundreds of bits to 'twiddle'. With liberal use of typedefs and #define, you might even get the syntax in main.c identical, but the header files would be *F*UGLY!

Both are volatile to warn the compiler that reading from them and writing to them have side effects not defined in the ANSI C language standard - i.e. they affect hardware so not to cache them in a temporary variable or optimise out references to them.

This post has been edited by IanM: Nov 7 2009, 01:45 PM
Go to the top of the page
 
+Quote Post
ryeg
post Nov 7 2009, 05:41 PM
Post #4


Enthusiast
**

Group: EstablishedMember
Posts: 103
Joined: 14-November 04
From: North Carolina, USA
Member No.: 505



Thanks for clearing that up for me guys. I had seen the stuff in the manual (yes, I occasionally read the manual) but the examples were a bit obscure in this case.

I might suggest that Dave and Pavel consider beefing up the manual on this. Particularly the use of the .h file references.

Regards
Rye
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 9th September 2010 - 10:48 AM