Thread: Integer casting ADC

  1. #1
    Matt Conway bobthebullet990's Avatar
    Join Date
    Nov 2005

    Integer casting ADC

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

      signed int i, x;
      unsigned short inData = 0; 
      init();	      // Set the PCLK to 15MHz
      init_UART1(); // Initialise the UART Serial port
    	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-21-2009, 12:37 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06: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, 10:43 AM