Integer casting ADC

This is a discussion on Integer casting ADC within the C Programming forums, part of the General Programming Boards category; We are writing code to read data from an ADC voltage convertor, the code we have written so far is: ...

  1. #1
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005
    Location
    Cambridge
    Posts
    121

    Integer casting ADC

    We are writing code to read data from an ADC voltage convertor, the code we have written so far is:

    Code:
      signed int i, x;
      unsigned short inData = 0; 
      	
      init();	      // Set the PCLK to 15MHz
      init_UART1(); // Initialise the UART Serial port
      
      while(1){
    	inData = getAD(0x01);
    	// testing 2's compliment bit - twelth bit
    	if (0x00000800 & inData) {
    	  // stuff first 4 bits of short int with 1's
    	  x = (inData | 0xFFFFF000);
    	}
    	else {
    	  // stuff first 4 bits of short int with 0's
    	  x = (inData & 0x000007FF);
    	}
    	printf("DATA: x = %d    |   inData = %d\n", x, inData); 	   
    	for (i=0; i<800000; i++);
      }
    OK!!! ...I was being an idiot!!!! ...x was an unsigned int so it would never print a negative value!!!!!!!!!!!!!!
    Last edited by bobthebullet990; 10-25-2006 at 07:34 AM.
    Many junglists take pride in their belongin to what may be referred to as a globalised drum & bass subculture, as a subculture though, it is not nearly as distinct at gothic or punk!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory issue
    By t014y in forum C Programming
    Replies: 2
    Last Post: 02-20-2009, 11:37 PM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 05:55 PM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  5. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21