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.

Converting 12 bit value to 16 bit value TMS570

Other Parts Discussed in Thread: HALCOGEN

Hi

I work on a TMS570LS31USB kit and I want to send CAN data to the computer

I already made CANcommunication example which is in the halcogen>help>example file and it Works.But at this program which I write below when I want to send ADC data it gives error about the value.How can I convert the value which CAN communication want.

CAN communication gives maximum 8 bit but my ADC value is 12 bit.How can I convert it?

Thanks 

 double x;
  double y;
  adcData_t adc_data; //ADC Data Structure
  adcData_t *adc_data_ptr = &adc_data; //ADC Data Pointer
  unsigned int NumberOfChars, value; //Declare variables
  adcInit(); //Initializes the ADC module
  hetInit();
  canInit();
  while(1) // Loop to acquire and send ADC sample data via the SCI (UART)
  {
  adcStartConversion(adcREG1, 1U); //Start ADC conversion
  while(!adcIsConversionComplete(adcREG1, 1U)); //Wait for ADC conversion
  adcGetData(adcREG1, 1U, adc_data_ptr); //Store conversion into ADC pointer
  value = (unsigned int)adc_data_ptr->value;
  NumberOfChars = ltoa(value,(char *)command);
  x=value;//* ADC değeri ata *//

  canTransmit(canREG1, canMESSAGE_BOX1, x);
 

   if(x<4096)
  {
  y=100-(100*x/4096);

  pwmSetDuty(hetRAM1, pwm0, y);
  }
  else
  {
   pwmSetDuty(hetRAM1, pwm0, 0);
  }

  • Hi,

      You will need to pass a pointer for the data you want to write to the message box. Somehow you need to break up the 12bit ADC data as two 8-bit data. 

    uint32 canTransmit ( canBASE_t node,
    uint32  messageBox,
    const uint8 data 
    )

    Transmits a CAN message.

    Parameters
    [in] node Pointer to CAN node:
    • canREG1: CAN1 node pointer
    • canREG2: CAN2 node pointer
    • canREG3: CAN3 node pointer
    [in] messageBox Message box number of CAN node:
    • canMESSAGE_BOX1: CAN message box 1
    • canMESSAGE_BOXn: CAN message box n [n: 1-64]
    • canMESSAGE_BOX64: CAN message box 64
    [in] data Pointer to CAN TX data 
  • Hi,
    I understand how can I sen CAN data? but in my code you can see I have to send "x" value with CAN,but I couldnt do it.In my program what kind of change I have to do? I send adc data to"x" value,It is 12 bit ,I want to send it with 2x8 bit message for CAN message.
    Thanks,
  • Hi,
    The canTransmit() expects a pointer to be passed. Note that the CAN payload is 8bytes and this is the reason that you need to pass a pointer of 8bit array of data.
    When the ADC finishes the conversion and these conversion will logically occupy 16bits of space. You can store these conversion result into an array and pass the pointer of the array to the canTransmit(). For example:

    uint16 adc_data[4] = {0x0122, 0x0344,0x0566,0x0788};
    uint8 *can_data;

    can_data = &adc_data;
    canTransmit(canREG1, canMESSAGE_BOX1, can_data);