- adaptions to PCB Hend-Control, Rev.0
git-svn-id: http://moon:8086/svn/projects/HendiControl@152 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
@@ -30,15 +30,15 @@
|
|||||||
<EraseKey />
|
<EraseKey />
|
||||||
<AsfFrameworkConfig>
|
<AsfFrameworkConfig>
|
||||||
<framework-data>
|
<framework-data>
|
||||||
<options />
|
<options />
|
||||||
<configurations />
|
<configurations />
|
||||||
<files />
|
<files />
|
||||||
<documentation help="" />
|
<documentation help="" />
|
||||||
<offline-documentation help="" />
|
<offline-documentation help="" />
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />
|
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</framework-data>
|
</framework-data>
|
||||||
</AsfFrameworkConfig>
|
</AsfFrameworkConfig>
|
||||||
<avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
|
<avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
|
||||||
<avrtoolserialnumber>J41800089261</avrtoolserialnumber>
|
<avrtoolserialnumber>J41800089261</avrtoolserialnumber>
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
<avrgcc.compiler.symbols.DefSymbols>
|
<avrgcc.compiler.symbols.DefSymbols>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>NDEBUG</Value>
|
<Value>NDEBUG</Value>
|
||||||
<Value>ARDUINO_NANO=1</Value>
|
<Value>ARDUINO_NANO=0</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.compiler.symbols.DefSymbols>
|
</avrgcc.compiler.symbols.DefSymbols>
|
||||||
<avrgcc.compiler.directories.IncludePaths>
|
<avrgcc.compiler.directories.IncludePaths>
|
||||||
@@ -113,7 +113,7 @@
|
|||||||
<avrgcc.compiler.symbols.DefSymbols>
|
<avrgcc.compiler.symbols.DefSymbols>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>DEBUG</Value>
|
<Value>DEBUG</Value>
|
||||||
<Value>ARDUINO_NANO=1</Value>
|
<Value>ARDUINO_NANO=0</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.compiler.symbols.DefSymbols>
|
</avrgcc.compiler.symbols.DefSymbols>
|
||||||
<avrgcc.compiler.directories.IncludePaths>
|
<avrgcc.compiler.directories.IncludePaths>
|
||||||
|
|||||||
@@ -11,48 +11,58 @@
|
|||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
|
||||||
static volatile int16_t adc_value[16];
|
static volatile uint8_t adc_ch = 0;
|
||||||
static volatile size_t adc_ch = 0;
|
|
||||||
static Fifo *g_pFifo = NULL;
|
static Fifo *g_pFifo = NULL;
|
||||||
|
static Fifo g_conversionFifo;
|
||||||
|
static int conversionBusy = 0;
|
||||||
|
|
||||||
ISR(ADC_vect)
|
ISR(ADC_vect)
|
||||||
{
|
{
|
||||||
|
conversionBusy = 0;
|
||||||
int16_t value_low = (int16_t)ADCL;
|
int16_t value_low = (int16_t)ADCL;
|
||||||
int16_t value_high = (int16_t)ADCH;
|
int16_t value_high = (int16_t)ADCH;
|
||||||
ADCSRA |= (1<<ADIF);
|
ADCSRA |= (1<<ADIF);
|
||||||
int16_t value = value_high << 8 | value_low;
|
int16_t value = value_high << 8 | value_low;
|
||||||
adc_value[adc_ch] = value;
|
|
||||||
|
|
||||||
Msg_t msg = {AdcComplete, adc_getChannel()};
|
Msg_t msg =
|
||||||
|
{
|
||||||
|
.code = AdcComplete,
|
||||||
|
.m.adc.ch = adc_ch,
|
||||||
|
.m.adc.data = value,
|
||||||
|
};
|
||||||
fifo_push(g_pFifo, &msg);
|
fifo_push(g_pFifo, &msg);
|
||||||
|
if (!fifo_isEmpty(&g_conversionFifo))
|
||||||
|
{
|
||||||
|
uint8_t ch;
|
||||||
|
fifo_pop(&g_conversionFifo, &ch);
|
||||||
|
adc_start_conversion(ch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void adc_init(Fifo *pFifo)
|
void adc_init(Fifo *pFifo)
|
||||||
{
|
{
|
||||||
g_pFifo = pFifo;
|
g_pFifo = pFifo;
|
||||||
|
fifo_init(&g_conversionFifo, 16, sizeof(uint8_t), "ConvFifo");
|
||||||
PRR &= ~(1 << PRADC);
|
PRR &= ~(1 << PRADC);
|
||||||
ADCSRA |= (1 << ADEN) | 7;
|
ADCSRA |= (1 << ADEN) | 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
void adc_start_conversion(size_t ch)
|
void adc_start_conversion(uint8_t ch)
|
||||||
{
|
{
|
||||||
ADMUX = (ADMUX & 0xF0) | (ch & 0x0F) | (1 << REFS0);
|
ADMUX = (ADMUX & 0xF0) | (ch & 0x0F) | (1 << REFS0);
|
||||||
ADCSRA |= (1 << ADSC) | (1 << ADIE);
|
ADCSRA |= (1 << ADSC) | (1 << ADIE);
|
||||||
adc_ch = ch & 0x0F;
|
adc_ch = ch & 0x0F;
|
||||||
|
conversionBusy = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int adc_is_fininshed()
|
void adc_enqueue_conversion(uint8_t ch)
|
||||||
{
|
{
|
||||||
return (int)(0 == (ADCSRA & (1 << ADSC)));
|
if (!conversionBusy)
|
||||||
|
{
|
||||||
|
adc_start_conversion(ch);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fifo_push(&g_conversionFifo, &ch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t adc_getChannel()
|
|
||||||
{
|
|
||||||
return adc_ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
int16_t adc_getData()
|
|
||||||
{
|
|
||||||
return adc_value[adc_ch];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,7 @@
|
|||||||
#include "fifo.h"
|
#include "fifo.h"
|
||||||
|
|
||||||
void adc_init(Fifo *pFifo);
|
void adc_init(Fifo *pFifo);
|
||||||
void adc_start_conversion(size_t ch);
|
void adc_start_conversion(uint8_t ch);
|
||||||
int adc_is_fininshed();
|
void adc_enqueue_conversion(uint8_t ch);
|
||||||
size_t adc_getChannel();
|
|
||||||
int16_t adc_getData();
|
|
||||||
|
|
||||||
#endif /* ADC_H_ */
|
#endif /* ADC_H_ */
|
||||||
@@ -32,8 +32,8 @@
|
|||||||
|
|
||||||
#define TIMER_SW_DELAY_MS(dly) ((dly*TIMER_IRQ_CLOCK)/1000UL)
|
#define TIMER_SW_DELAY_MS(dly) ((dly*TIMER_IRQ_CLOCK)/1000UL)
|
||||||
|
|
||||||
uint8_t ledState = 0;
|
int16_t adc_poti = 0;
|
||||||
int16_t adc_last = 0;
|
int16_t adc_swin = 0;
|
||||||
int sw_in_last = 0;
|
int sw_in_last = 0;
|
||||||
size_t cmdStrSize = 0;
|
size_t cmdStrSize = 0;
|
||||||
Fifo messageFifo;
|
Fifo messageFifo;
|
||||||
@@ -77,6 +77,7 @@ typedef enum _eState_t
|
|||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
int hb_state = 0;
|
||||||
cli();
|
cli();
|
||||||
wdt_reset();
|
wdt_reset();
|
||||||
wdt_disable();
|
wdt_disable();
|
||||||
@@ -124,7 +125,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// Process Uart message
|
// Process Uart message
|
||||||
cmdStr[cmdStrSize] = 0;
|
cmdStr[cmdStrSize] = 0;
|
||||||
char c = msg.data;
|
char c = (char)msg.m.uart.data;
|
||||||
|
|
||||||
// Command finished with CR/LF
|
// Command finished with CR/LF
|
||||||
if (c == 0x0A || c == 0x0D)
|
if (c == 0x0A || c == 0x0D)
|
||||||
@@ -178,57 +179,42 @@ int main(void)
|
|||||||
|
|
||||||
case AdcComplete:
|
case AdcComplete:
|
||||||
{
|
{
|
||||||
int16_t adc_curr = adc_getData();
|
uint8_t adc_ch = msg.m.adc.ch;
|
||||||
if (adc_getChannel() == 6)
|
int16_t adc_curr = (int16_t)msg.m.adc.data;
|
||||||
|
if (adc_ch == 0)
|
||||||
{
|
{
|
||||||
if (((adc_curr - adc_last) < -1) || ((adc_curr - adc_last) > 1))
|
if (((adc_curr - adc_poti) < -1) || ((adc_curr - adc_poti) > 1))
|
||||||
{
|
{
|
||||||
if (state == StateNormal)
|
if (state == StateNormal)
|
||||||
{
|
{
|
||||||
setPower(adc_curr << 2);
|
setPower(adc_curr << 2);
|
||||||
}
|
}
|
||||||
|
adc_poti = adc_curr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
adc_last = adc_curr;
|
if (adc_ch == 2)
|
||||||
|
{
|
||||||
|
adc_swin = adc_curr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Timer:
|
case Timer:
|
||||||
{
|
{
|
||||||
int timer_id = msg.data;
|
int timer_id = msg.m.timer.ch;
|
||||||
switch(timer_id)
|
switch(timer_id)
|
||||||
{
|
{
|
||||||
case TIMER_GENERAL:
|
case TIMER_GENERAL:
|
||||||
{
|
{
|
||||||
timer_start(timer_id, TIMER_SW_DELAY_MS(500));
|
timer_start(timer_id, TIMER_SW_DELAY_MS(500));
|
||||||
switch(ledState)
|
hb_state = !hb_state;
|
||||||
{
|
portSet(Led_HB, hb_state);
|
||||||
case 0:
|
|
||||||
PORTB = (PORTB & 0xFC) | 0x00;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
PORTB = (PORTB & 0xFC) | 0x01;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
PORTB = (PORTB & 0xFC) | 0x03;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
PORTB = (PORTB & 0xFC) | 0x02;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ledState++;
|
|
||||||
if (ledState == 4)
|
|
||||||
{
|
|
||||||
ledState = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TIMER_TIMEOUT:
|
case TIMER_TIMEOUT:
|
||||||
{
|
{
|
||||||
PRINT("Timeout!\n");
|
PRINT("Timeout!\n");
|
||||||
setPower(PowerLow);
|
|
||||||
setSwitch(SwitchOff);
|
|
||||||
state_next = StateError;
|
state_next = StateError;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -236,10 +222,10 @@ int main(void)
|
|||||||
case TIMER_ADC:
|
case TIMER_ADC:
|
||||||
{
|
{
|
||||||
timer_start(timer_id, TIMER_SW_DELAY_MS(50));
|
timer_start(timer_id, TIMER_SW_DELAY_MS(50));
|
||||||
int sw_in = portGet(PwrSwitch_in);
|
int sw_in = adc_swin > 512;
|
||||||
if (sw_in != sw_in_last)
|
if (sw_in != sw_in_last)
|
||||||
{
|
{
|
||||||
PRINT ("PwrSwitch_in = %d\n", portGet(PwrSwitch_in));
|
PRINT ("PwrSwitch_in = %d\n", sw_in);
|
||||||
if (sw_in == 0)
|
if (sw_in == 0)
|
||||||
{
|
{
|
||||||
if (state == StateError || state == StateRemote)
|
if (state == StateError || state == StateRemote)
|
||||||
@@ -250,7 +236,8 @@ int main(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sw_in_last = sw_in;
|
sw_in_last = sw_in;
|
||||||
adc_start_conversion(0x06);
|
adc_enqueue_conversion(0);
|
||||||
|
adc_enqueue_conversion(2);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -264,6 +251,16 @@ int main(void)
|
|||||||
if (state != state_next)
|
if (state != state_next)
|
||||||
{
|
{
|
||||||
PRINT("State change \"%s\" => \"%s\"\n", state_str[state], state_str[state_next]);
|
PRINT("State change \"%s\" => \"%s\"\n", state_str[state], state_str[state_next]);
|
||||||
|
if (state_next == StateError)
|
||||||
|
{
|
||||||
|
setPower(PowerLow);
|
||||||
|
setSwitch(SwitchOff);
|
||||||
|
portSet(Led_ERR, 1);
|
||||||
|
}
|
||||||
|
if (state_next == StateNormal)
|
||||||
|
{
|
||||||
|
portSet(Led_ERR, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
state = state_next;
|
state = state_next;
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,22 @@ typedef enum _eMsgCode
|
|||||||
typedef struct _sMsg_t
|
typedef struct _sMsg_t
|
||||||
{
|
{
|
||||||
MsgCode code;
|
MsgCode code;
|
||||||
uint8_t data;
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint8_t data;
|
||||||
|
} uart;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint8_t ch;
|
||||||
|
uint16_t data;
|
||||||
|
} adc;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint8_t ch;
|
||||||
|
} timer;
|
||||||
|
} m;
|
||||||
} Msg_t;
|
} Msg_t;
|
||||||
|
|
||||||
#endif /* MESSAGE_H_ */
|
#endif /* MESSAGE_H_ */
|
||||||
@@ -10,11 +10,10 @@
|
|||||||
|
|
||||||
void port_init()
|
void port_init()
|
||||||
{
|
{
|
||||||
DDRB = 0x03;
|
DDRD = 0xFC;
|
||||||
DDRC = 0x01;
|
DDRB = 0x06;
|
||||||
PORTB = 0x03;
|
PORTD = 0xC0;
|
||||||
PORTC = 0x01;
|
PORTB = 0x04;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct _sPort_t
|
typedef struct _sPort_t
|
||||||
@@ -26,11 +25,14 @@ typedef struct _sPort_t
|
|||||||
|
|
||||||
const Port_t portItems[NUM_ITEMS] =
|
const Port_t portItems[NUM_ITEMS] =
|
||||||
{
|
{
|
||||||
{0x05, 0, 1},
|
|
||||||
{0x05, 1, 1},
|
|
||||||
{0x05, 2, 1},
|
{0x05, 2, 1},
|
||||||
{0x08, 0, 1},
|
{0x0B, 6, 1},
|
||||||
{0x06, 1, 1},
|
{0x0B, 7, 1},
|
||||||
|
{0x0B, 2, 1},
|
||||||
|
{0x0B, 3, 1},
|
||||||
|
{0x0B, 4, 1},
|
||||||
|
{0x0B, 5, 1},
|
||||||
|
{0x05, 1, 1},
|
||||||
};
|
};
|
||||||
|
|
||||||
void portSet(int portItem, int enable)
|
void portSet(int portItem, int enable)
|
||||||
|
|||||||
@@ -11,11 +11,14 @@
|
|||||||
|
|
||||||
enum PortItem
|
enum PortItem
|
||||||
{
|
{
|
||||||
Led0 = 0,
|
Led_HB = 0,
|
||||||
Led1 = 1,
|
Led_MODE = 1,
|
||||||
Led2 = 2,
|
Led_ERR = 2,
|
||||||
PwrSwitch_out = 3,
|
Led_0 = 3,
|
||||||
PwrSwitch_in = 4,
|
Led_1 = 4,
|
||||||
|
Led_2 = 5,
|
||||||
|
Led_3 = 6,
|
||||||
|
PwrSwitch_out = 7,
|
||||||
NUM_ITEMS
|
NUM_ITEMS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,11 @@ ISR (TIMER1_OVF_vect) // Timer1 ISR
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Msg_t msg = {Timer, i};
|
Msg_t msg =
|
||||||
|
{
|
||||||
|
.code = Timer,
|
||||||
|
.m.timer.ch = i
|
||||||
|
};
|
||||||
if (fifo_push(g_pFifo, &msg))
|
if (fifo_push(g_pFifo, &msg))
|
||||||
{
|
{
|
||||||
user_timer[i].isRunning = 0;
|
user_timer[i].isRunning = 0;
|
||||||
|
|||||||
@@ -28,7 +28,11 @@ ISR(USART_RX_vect)
|
|||||||
if (status & (1 << RXC0))
|
if (status & (1 << RXC0))
|
||||||
{
|
{
|
||||||
uint8_t rx_data = UDR0;
|
uint8_t rx_data = UDR0;
|
||||||
Msg_t msg = {Uart, rx_data};
|
Msg_t msg =
|
||||||
|
{
|
||||||
|
.code = Uart,
|
||||||
|
.m.uart.data = rx_data
|
||||||
|
};
|
||||||
fifo_push(g_pFifo, &msg);
|
fifo_push(g_pFifo, &msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@
|
|||||||
<avrgcc.compiler.symbols.DefSymbols>
|
<avrgcc.compiler.symbols.DefSymbols>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>NDEBUG</Value>
|
<Value>NDEBUG</Value>
|
||||||
<Value>ARDUINO_NANO=1</Value>
|
<Value>ARDUINO_NANO=0</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.compiler.symbols.DefSymbols>
|
</avrgcc.compiler.symbols.DefSymbols>
|
||||||
<avrgcc.compiler.directories.IncludePaths>
|
<avrgcc.compiler.directories.IncludePaths>
|
||||||
@@ -135,7 +135,7 @@
|
|||||||
<avrgcc.compiler.symbols.DefSymbols>
|
<avrgcc.compiler.symbols.DefSymbols>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>DEBUG</Value>
|
<Value>DEBUG</Value>
|
||||||
<Value>ARDUINO_NANO=1</Value>
|
<Value>ARDUINO_NANO=0</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.compiler.symbols.DefSymbols>
|
</avrgcc.compiler.symbols.DefSymbols>
|
||||||
<avrgcc.compiler.directories.IncludePaths>
|
<avrgcc.compiler.directories.IncludePaths>
|
||||||
|
|||||||
Reference in New Issue
Block a user