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.

TMDX570LS31USB kit program setting led brightness using light sensor

Other Parts Discussed in Thread: TMS570LS3137, HALCOGEN

Hi 

I am very new with the TMS570 and actually with programming.I use TMS570ls3137 usb kit

I made adc reading program giving example in the videos of the ti. I mention about reading light sensor output from the terminal. I used this output value for lighting led on the usb kit you can see below when value less than 2000  turn on led when it much more turn off led.

But now I want make this program different .  When I read light sensor value i want to set led brightness about this value.

When I put light on the light sensor it gives 4096 value maximum, it gives 0 when dark happen  . I want to use 0 to 4096 value for arrange brightness of any led

on the usb kit it doesnt matter. When full 4096 value the led must be dark and it slowly increase brightness,when it reach 0 value it gives full bright.

Thanks from now

oid main(void)
{
/* USER CODE BEGIN (3) */
gioSetDirection(hetPORT1, 0xFFFFFFFF);
adcData_t adc_data; //ADC Data Structure
adcData_t *adc_data_ptr = &adc_data; //ADC Data Pointer
unsigned int NumberOfChars, value; //Declare variables
sciInit(); //Initializes the SCI (UART) module
adcInit(); //Initializes the ADC module
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);
sciSend(scilinREG, 2, (unsigned char *)"0x"); //Sends '0x' hex designation chars
sciSend(scilinREG, NumberOfChars, command); //Sends the ambient light sensor data
sciSend(scilinREG, 2, (unsigned char *)"\r\n"); //Sends new line character

if(NumberOfChars<0x2000)
{
gioSetBit(hetPORT1, 0, 1);
}
else
{
gioSetbit(hetPORT1, 0, 0);
}
}

  • Hi,
    I think what you are looking for is a 12-bit PWM. You should take a look at the NHET module in the device. What you want is to create a PWM that can vary the duty cycle from 0% to 100% with a 12-bit resolution.
  • How can I look at this informations in the Usb kit page I didnt find anything about it,I know the light sensor give me 12 bit resolution becasue of the value 4096 but how can I arrange pwm 12 bit and what kind of code should I have to write for this

    For example
    for every bit resolution we give 5volt/4096=0,00122070
    for every increase of the voltage pwm increase 100/4096= 0,0244

    I will write something like

    for(x=0,x<5,x +=0,00122070)for voltage increase
    for(y=0,y<100,y +=0,0244)for pwm increase

    But if this code sense is true or not I dont know?
    Maybe I have to do something for pwm

    At halcogen Do i have to arrange something for it?
  • Hi,

    You need to use the NHET module on the chip. NHET is a hardware that supports timer, PWM, Input Capture capability. Please refer to the NHET userguide in the TRM. It may take you a bit to learn NHET but I think NHET is the solution for it.