more switches enables
This commit is contained in:
@ -12,30 +12,42 @@
|
|||||||
|
|
||||||
|
|
||||||
volatile uint32_t tickCnt = 0;
|
volatile uint32_t tickCnt = 0;
|
||||||
|
const uint16_t DIVIDER = 2;
|
||||||
const uint16_t TICK = 1024;
|
const uint16_t TICK = 1024;
|
||||||
uint16_t pwmVal = 512;
|
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) {
|
interrupt (TIMER0_A0_VECTOR) timer0a0_isr(void) {
|
||||||
static uint8_t state = 0;
|
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) {
|
switch (state) {
|
||||||
case 0:
|
case 0:
|
||||||
if (timestamp >= onTime) {
|
if (timestamp >= onTime) {
|
||||||
timestamp = 0;
|
timestamp = 0;
|
||||||
P1SEL &= ~BIT6;
|
P1SEL |= BIT6;
|
||||||
P1OUT &= ~BIT6;
|
|
||||||
state = 1;
|
state = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (timestamp >= offTime) {
|
if ((offTime != 0) && (timestamp >= offTime)) {
|
||||||
timestamp = 0;
|
timestamp = 0;
|
||||||
P1SEL |= BIT6;
|
P1SEL &= ~BIT6;
|
||||||
|
P1OUT &= ~BIT6;
|
||||||
state = 0;
|
state = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -69,3 +81,25 @@ uint16_t engineMaxPwmValue() {
|
|||||||
void engineSetPwmValue(uint16_t val) {
|
void engineSetPwmValue(uint16_t val) {
|
||||||
TACCR1 = 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,10 @@
|
|||||||
void engineInit();
|
void engineInit();
|
||||||
uint16_t engineMaxPwmValue();
|
uint16_t engineMaxPwmValue();
|
||||||
void engineSetPwmValue(uint16_t val);
|
void engineSetPwmValue(uint16_t val);
|
||||||
|
void engineIncOffTime();
|
||||||
|
void engineIncOnTime();
|
||||||
|
void engineDecOffTime();
|
||||||
|
void engineDecOnTime();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
14
src/hmi.cpp
14
src/hmi.cpp
@ -81,14 +81,14 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
SwitchPort intensitySwitch = SwitchPort2(BIT1);
|
SwitchPort intensitySwitch = SwitchPort2(BIT1);
|
||||||
//SwitchPort onTimeSwitch = SwitchPort2(BIT2);
|
SwitchPort onTimeSwitch = SwitchPort2(BIT2);
|
||||||
//SwitchPort offTimeSwitch = SwitchPort2(BIT3);
|
SwitchPort offTimeSwitch = SwitchPort2(BIT3);
|
||||||
//SwitchPort modeSwitch = SwitchPort2(BIT4);
|
//SwitchPort modeSwitch = SwitchPort2(BIT4);
|
||||||
|
|
||||||
int16_t intensity = 0;
|
int16_t intensity = 0;
|
||||||
uint16_t maxIntensity = 0;
|
uint16_t maxIntensity = 0;
|
||||||
uint16_t intensityStep = 0;
|
uint16_t intensityStep = 0;
|
||||||
const uint16_t intensityStepCnt = 8;
|
const uint16_t intensityStepCnt = 16;
|
||||||
|
|
||||||
|
|
||||||
void hmiInit() {
|
void hmiInit() {
|
||||||
@ -108,4 +108,12 @@ void hmiExec() {
|
|||||||
debugWrite(intensity);
|
debugWrite(intensity);
|
||||||
engineSetPwmValue(intensity);
|
engineSetPwmValue(intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (onTimeSwitch.get()) {
|
||||||
|
engineIncOnTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offTimeSwitch.get()) {
|
||||||
|
engineIncOffTime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,8 @@ int main() {
|
|||||||
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
P1OUT &= ~BIT7;
|
//P1OUT &= ~BIT7;
|
||||||
P1OUT |= BIT7;
|
//P1OUT |= BIT7;
|
||||||
|
|
||||||
hmiExec();
|
hmiExec();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user