LPC1343 7seg LEDを制御する on-off駆動をして電力セーブする

7segのLEDをon-offさせて電力をセーブします。

コンセプトは下の図のようなon-off駆動です。
前回記事では
8の場合1秒間ずっと8を点灯させています。(左側)
1秒間に何回もon-offさせる(右側)事で電力が減ります(明るさも当然減ります)


さらに今回は電流変化も平均化させます。
単純に8を点灯⇔消灯の繰り返しでは
電流0→70mAの変化の繰り返しになります。
大きな電流変化は電源の不安定化につながります。

これを対策するために下図の右側のように8の部分部分を点灯させていきます。
平均電流は右も左も同じですが、電流変化が少ない分、回路にやさしい駆動方法です。



コード

#ifdef __USE_CMSIS
#include "LPC13xx.h"
#endif

#include
#include

__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

int main(void) {
volatile static uint32_t period; // Assigned to a variable for debug
volatile static int i = 0 ; // dummy counter

// Configure PORT PIO2_0 - 2_6
LPC_IOCON->PIO2_0 &= 0x00; // Configure PIO2-0 Pullup off
LPC_IOCON->PIO2_1 &= 0x00; // Configure PIO2-1 Pullup off
LPC_IOCON->PIO2_2 &= 0x00; // Configure PIO2-2 Pullup off
LPC_IOCON->PIO2_3 &= 0x00; // Configure PIO2-3 Pullup off
LPC_IOCON->PIO2_4 &= 0x00; // Configure PIO2-4 Pullup off
LPC_IOCON->PIO2_5 &= 0x00; // Configure PIO2-5 Pullup off
LPC_IOCON->PIO2_6 &= 0x00; // Configure PIO2-6 Pullup off
LPC_GPIO2->DIR |= 0x7F; // PIO2-0-6 as output

// Configure System tick timer in 1msec period
period = SystemCoreClock / 1000; // Period for 1msec SYSTICK
SysTick_Config(period); // Configuration


// Enter an infinite loop
while(1) { // Infinite loop
i++; // dummy count.
}
return 0 ;
}

void SysTick_Handler(void) {
static int count = 0; // Software counter
static int sec=0; // second counter
static int cnt2 = 0; // 7ms counter
int data,mask;

mask=0;
if (++count >= 1000) { // wait for 1000 system ticks =1s
if(sec>=10){
sec = 0;
}
count = 0; // Reload counter
++sec;
}


switch (sec) {
case 0:

data = 0x02; break;
case 1:
data = 0x2F; break;
case 2:
data = 0x41; break;
case 3:
data = 0x05; break;
case 4:
data = 0x2C; break;
case 5:
data = 0x14; break;
case 6:
data = 0x10; break;
case 7:
data = 0x27; break;
case 8:
data = 0x00; break;
case 9:
data = 0x04; break;
default:
data = 0x02; break;
}

if(++cnt2>=7){
cnt2=0;
}

mask |= (1<DATA = data | ~mask;
}

前回記事からの比較で説明します。

period = SystemCoreClock / 1000; // Period for 1msec SYSTICK
10ms毎に割り込み→1ms毎に割り込みに変更しました。
LEDの点滅が見える事を避けるためです。


static int count = 0; // Software counter
count変数をintにしました。 1ms割り込みに変更したために、1000カウントしなければなりません。
unit8では255でカウントオーバーするためです。


static int cnt2 = 0; // 7ms counter
cnt2を追加しました。 0-6をカウントするものです。7segの各LEDのマスクに使います。


int data,mask;
data=表示する7seg デコード, mask=マスク信号です。


mask |= (1<マスク信号作成です。1になっているビットだけ点灯させるイメージです。
cnt2=0 : mask=000 0001;
cnt2=1 : mask=000 0010;
   ・
   ・
cnt2=6 : mask=100 0000;


LPC_GPIO2->DATA = data | ~mask;
実際はGNDで点灯ですのでmask信号は反転させてorをとっています。


これで動作します。
見た目は点滅していることはわかりません。

しかし、以下2行の値を変更すると、点滅速度が遅くなり
人間の目でもどのように動いているか確認できるようになります。

period = SystemCoreClock / 10; //(1000→10 : 1ms→100ms)
if (++count >= 100) { // wait for 1000→100 system ticks