cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S Discovery + TSL + LED dimming possible?

anja
Associate II
Posted on July 06, 2010 at 15:53

Hello,

I'm trying to dim a LED with the touch sensor on the STM8S Discovery board.

After a touch the LED begins to dim until it's dark, but it should stop dimming, if I take my finger away again. This action is not recognized.

I think the code stays in an infinite loop at the line, which I have marked with the arrow.

When is the TSL_GlobalSetting.b.CHANGED-flag set? I cannot find it in the help files. Or must I use another flag? Or is anything else in my code wrong? Or is it impossible to use this flag two times in the ExtraCode_StateMaschine and if this is the case, how can I implement LED dimming with TSL?

Here is my code:

void ExtraCode_StateMachine(void)

{

  if (TSL_GlobalSetting.b.CHANGED)

  {

    TSL_GlobalSetting.b.CHANGED = 0;

    if (sSCKeyInfo[0].Setting.b.DETECTED)

    {

      GPIO_WriteHigh(GPIOD, GPIO_PIN_0);

      TIM3_OC1Init(TIM3_OCMODE_PWM1, TIM3_OUTPUTSTATE_ENABLE, 999, TIM3_OCPOLARITY_HIGH);

      while(TSL_GlobalSetting.b.CHANGED==0)<---------

      {

        if (TSL_Tick_Flags.b.User_Flag_100ms == 1)

         {

           Delay(&Dim, 1*MilliSec);

         }

      }

    }

  else

   {

   GPIO_WriteLow(GPIOD, GPIO_PIN_0);

  }

  }

}

void Dim (void)

{

 u16 pwm=0;

 if (dimming>20)

  {

    pwm=dimming-20;

    dimming=pwm;

  }

 TIM3_OC1Init(TIM3_OCMODE_PWM1, TIM3_OUTPUTSTATE_ENABLE, dimming, TIM3_OCPOLARITY_HIGH);

}

Greetings,

a.m.
1 REPLY 1
anja
Associate II
Posted on July 06, 2010 at 18:02

problem solved