more switches enables

This commit is contained in:
hg 2016-02-14 19:14:36 +01:00
parent 90c568ec8d
commit 585c920b34
4 changed files with 59 additions and 13 deletions

View File

@ -12,30 +12,42 @@
volatile uint32_t tickCnt = 0;
const uint16_t DIVIDER = 2;
const uint16_t TICK = 1024;
uint16_t pwmVal = 512;
volatile uint16_t onTime = 500;
volatile uint16_t offTime = 200;
// unit: 100us
const uint32_t STEP_100ms = 1000;
volatile uint32_t onTime = STEP_100ms * 1; // 1000 = 100ms
volatile uint32_t offTime = 0;
interrupt (TIMER0_A0_VECTOR) timer0a0_isr(void) {
static uint8_t state = 0;
static uint16_t timestamp = 0;
static uint32_t timestamp = 0;
static uint16_t divCnt = 0;
divCnt++;
if (divCnt >= DIVIDER) {
divCnt = 0;
timestamp++;
P1OUT &= ~BIT7;
P1OUT |= BIT7;
}
timestamp++;
switch (state) {
case 0:
if (timestamp >= onTime) {
timestamp = 0;
P1SEL &= ~BIT6;
P1OUT &= ~BIT6;
P1SEL |= BIT6;
state = 1;
}
break;
case 1:
if (timestamp >= offTime) {
if ((offTime != 0) && (timestamp >= offTime)) {
timestamp = 0;
P1SEL |= BIT6;
P1SEL &= ~BIT6;
P1OUT &= ~BIT6;
state = 0;
}
break;
@ -69,3 +81,25 @@ uint16_t engineMaxPwmValue() {
void engineSetPwmValue(uint16_t val) {
TACCR1 = val;
}
void engineIncOffTime() {
offTime += STEP_100ms;
}
void engineIncOnTime() {
onTime += STEP_100ms;
}
void engineDecOffTime() {
if (offTime != 0) {
offTime -= STEP_100ms;
}
}
void engineDecOnTime() {
if (onTime != 0) {
onTime -= STEP_100ms;
}
}

View File

@ -13,6 +13,10 @@
void engineInit();
uint16_t engineMaxPwmValue();
void engineSetPwmValue(uint16_t val);
void engineIncOffTime();
void engineIncOnTime();
void engineDecOffTime();
void engineDecOnTime();

View File

@ -81,14 +81,14 @@ public:
SwitchPort intensitySwitch = SwitchPort2(BIT1);
//SwitchPort onTimeSwitch = SwitchPort2(BIT2);
//SwitchPort offTimeSwitch = SwitchPort2(BIT3);
SwitchPort onTimeSwitch = SwitchPort2(BIT2);
SwitchPort offTimeSwitch = SwitchPort2(BIT3);
//SwitchPort modeSwitch = SwitchPort2(BIT4);
int16_t intensity = 0;
uint16_t maxIntensity = 0;
uint16_t intensityStep = 0;
const uint16_t intensityStepCnt = 8;
const uint16_t intensityStepCnt = 16;
void hmiInit() {
@ -108,4 +108,12 @@ void hmiExec() {
debugWrite(intensity);
engineSetPwmValue(intensity);
}
if (onTimeSwitch.get()) {
engineIncOnTime();
}
if (offTimeSwitch.get()) {
engineIncOffTime();
}
}

View File

@ -41,8 +41,8 @@ int main() {
while (1) {
P1OUT &= ~BIT7;
P1OUT |= BIT7;
//P1OUT &= ~BIT7;
//P1OUT |= BIT7;
hmiExec();
}