This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADC TMS5700432 Temperature

Other Parts Discussed in Thread: TMS5700432, HALCOGEN

Hello everyone, I am working with TMS5700432 HDK. I would like to read ADC value and convert it to degrees Celsius. I applied formulas on the forums for conversion; however, the results is wrong and in the hex (rether than in decimal as expected). May somebody recommend me other formula? This is my code:

 adcData_t adc_data;
    adcData_t *adc_data_ptr = &adc_data;

     /** - Start Group1 ADC Conversion
     *     Select Channel 8 - Temprature Sensor for Conversion
     */
    adcStartConversion_selChn(adcREG1, Temperature_Sensor, 1, adcGROUP1);

     /** - Wait for ADC Group1 conversion to complete */
     while(!adcIsConversionComplete(adcREG1, adcGROUP1));

    /** - Read the conversion result
    *     The data contains the Temprature sensor data
    */
    adcGetSingleData(adcREG1, adcGROUP1, adc_data_ptr);

    /** - Transnmit the Conversion data to PC using SCI
    */
    temp=  adc_data_ptr->value*423/1024 - 278;
    sciSend_32bitdata(scilinREG, ((unsigned int) (temp)));

Is there anyone ever do this problem before. How can we read the temperature correctly?

  • Hello,

    Can you post the adcGetSingleData and sciSend_32bitdata function bodies? These are not generated by HALCoGen.
  • Yeah, i took these functions from "Hercules Safety MCU Demos" program.

    void adcGetSingleData(adcBASE_t *adc, unsigned group, adcData_t *data)
    {
        unsigned  buf;
        adcData_t *ptr = data; 
    
        /** -  Get conversion data and channel/pin id */
        buf        = adc->GxBUF[group].BUF0;
        ptr->value = (unsigned short)(buf & 0xFFFU);
        ptr->id    = (unsigned short)((buf >> 16U) & 0x1FU); // int to unsigned short
    
        adc->GxINTFLG[group] = 9U;
    
        /**   @note The function canInit has to be called before this function can be used.\n
        *           The user is responsible to initialize the message box.
        */
    }
    void sciSend_32bitdata(sciBASE_t *sci, unsigned int data)
    {
    	unsigned char c_get ;
      	volatile int i = 0;
      	for( i = 8 ; i > 0 ; i-- )
      	{
     		c_get = (data>>28)&15 ;
    		if( c_get > 9 )
    			c_get += 7 ;
    		c_get += 48 ;
    		while ((sci->FLR & SCI_TX_INT) == 0) { /* wait */ };
    		sci->TD = c_get;
    		data = data<<4 ;
    	}
    }
    
    void adcStartConversion_selChn(adcBASE_t *adc, unsigned channel, unsigned fifo_size, unsigned group)
    {
        /** - Setup FiFo size */
        adc->GxINTCR[group] = fifo_size;
    
        /** - Start Conversion */
        adc->GxSEL[group] = 1 << channel;
    }