Showing posts with label signed. Show all posts
Showing posts with label signed. Show all posts

Wednesday, 12 October 2011

Notes on the MSP430 header files

Browsing MSP430 header files I came across a syntax I wasn't familiar with and searching online failed to give me a good explanation (or rather, I was missing the obvious) here is the section from the header file so hopefully you can find this via google :D

#define INCH_0 (0*0x1000u) /* Selects Channel 0 */
#define INCH_1 (1*0x1000u) /* Selects Channel 1 */
#define INCH_2 (2*0x1000u) /* Selects Channel 2 */
#define INCH_3 (3*0x1000u) /* Selects Channel 3 */
#define INCH_4 (4*0x1000u) /* Selects Channel 4 */
#define INCH_5 (5*0x1000u) /* Selects Channel 5 */
#define INCH_6 (6*0x1000u) /* Selects Channel 6 */
#define INCH_7 (7*0x1000u) /* Selects Channel 7 */
#define INCH_8 (8*0x1000u) /* Selects Channel 8 */
#define INCH_9 (9*0x1000u) /* Selects Channel 9 */
#define INCH_10 (10*0x1000u) /* Selects Channel 10 */
#define INCH_11 (11*0x1000u) /* Selects Channel 11 */
#define INCH_12 (12*0x1000u) /* Selects Channel 12 */
#define INCH_13 (13*0x1000u) /* Selects Channel 13 */
#define INCH_14 (14*0x1000u) /* Selects Channel 14 */
#define INCH_15 (15*0x1000u) /* Selects Channel 15 */


These definitions are used to set the input channel for the ADC, reading the family guide (slau144) Section 22.3.2 the above numbers should map to bits 15-12, notably INCH_10 should map to 1010 on those bits which is the internal temperature sensor where available.

But how does 10*0x1000u produce 1010?

Looking at the u threw me first, all that symbolises is that the number is unsigned. If it was signed the 15th bit would be to denote positive or negative but in this case its just a part of the number, for our purposes here we can ignore it.

The next problem I had was the multiplication. I opened up a programming calculator set to hex and typed in

10*1000 = 10000 and converted to binary 1 0000 0000 0000 0000

In a case of missing the obvious… The first set of digits isn't hex! Its decimal!

Decimal 10 = Hex A, A*1000 = A000 = 1010 0000 0000 0000