顯示具有 com - hardware 標籤的文章。 顯示所有文章
顯示具有 com - hardware 標籤的文章。 顯示所有文章

2020年9月12日 星期六

LP5560 - Single-LED Driver With Single-Wire Control


這是一顆我們俗稱的呼吸燈,因為預設的行為就像呼吸一樣,由滅到緩慢至亮,再由亮緩慢至滅。可以透過Single-Wire控制其行為,作法大同小異。這裡就稍微筆記一下。

6.6 Single-Wire Interface Timing Requirements

這裡描述了每個階段的high/low以及min/max時間,比如TC_ON > 20us,TC_OF > 30us之類的,簡略的code如下
#define SHORT_DELAY 10
#define TC_ON (20 + SHORT_DELAY)
#define TC_OFF (30 + SHORT_DELAY)
#define T_ENTER (500 + 10*SHORT_DELAY)
#define T_BLANK (1500 - 500)

// T-ENTER 
GPIO(CTRL_PIN, high);
us_delay(TC_ON);
GPIO(CTRL_PIN, low);
us_delay(TC_OFF);

GPIO(CTRL_PIN, high);
us_delay(TC_ON);
GPIO(CTRL_PIN, low);
us_delay(TC_OFF + T_ENTER + T_BLANK); // over T-BLANK period


7.3.3.4 Entering Follow Mode

這裡描述Entering Follow Mode的指令結構,基本上就是,"Training start command" + "Blank Period" + "Follow Mode command" + "Training end command"
#define SHORT_DELAY 10
#define TC_ON (20 + SHORT_DELAY)
#define TC_OFF (30 + SHORT_DELAY)
#define T_ENTER (500 + SHORT_DELAY)
#define T_BLANK (1500 - 500)
#define TCAL (350 + 10 * SHORT_DELAY))
#define TT_OFF (200 + 10 * SHORT_DELAY)
#define TIMEOUT (127 * TCAL)

static void training_start_command(void)
{
  int i = 0;
  while (i++ < 2) {
    GPIO(CTRL_PIN, high);
    us_delay(TC_ON);
    GPIO(CTRL_PIN, low);
    us_delay(TC_OFF);
  }
  us_delay(T_ENTER + T_BLANK); // over T-BLANK period due to 
}

static void follow_mode(uint32_t i, uint32_t r1, uint32_t on1, uint32_t f1, uint32_t off1)
{
  // C
  GPIO(CTRL_PIN, high);
  us_delay(TCAL);
  GPIO(CTRL_PIN, low);
  us_delay(TT_OFF);

  // I
  GPIO(CTRL_PIN, high);
  us_delay(i * TCAL);
  GPIO(CTRL_PIN, low);
  us_delay(TT_OFF);

  // r1
  GPIO(CTRL_PIN, high);
  us_delay(r1 * TCAL);
  GPIO(CTRL_PIN, low);
  us_delay(TT_OFF);

  // on1
  GPIO(CTRL_PIN, high);
  us_delay(on1 * TCAL);
  GPIO(CTRL_PIN, low);
  us_delay(TT_OFF);

  // off1
  GPIO(CTRL_PIN, high);
  us_delay(off1 * TCAL);
  GPIO(CTRL_PIN, low);
  us_delay(TT_OFF);
}

static void training_start_command(void)
{
  int i = 0;
  while (i++ < 3) {
    GPIO(CTRL_PIN, high);
    us_delay(TC_ON);
    GPIO(CTRL_PIN, low);
    us_delay(TC_OFF);
  }
  // more than 127 × TCAL time this is interpreted as timeout.
  us_delay(TIMEOUT );
}





熱門文章