static uint16_t track_current_samples[16] = { 0 };
static uint8_t track_current_head = 0;
static volatile uint16_t track_current_sum = 0;
-static uint16_t overcurrent_limit = 8796;
+static uint16_t overcurrent_limit = 9707;
static uint8_t overcurrent_sent = 0;
static uint16_t input_voltage_samples[16] = { 0 };
void monitor_init(void)
{
+ DDRB |= 0x02;
adc_init();
}
if(track_current_sum>overcurrent_limit)
{
output_set_power(0);
+ PORTB |= 0x02;
if(!overcurrent_sent)
{
overcurrent_sent = 1;
interface_send1(OVERCURRENT);
}
}
- else
+ else if(overcurrent_sent && output_is_power_on())
+ {
+ PORTB &= ~0x02;
overcurrent_sent = 0;
+ }
}
else if(adc_state==4)
{
{
if(cmd_buf[0]==READ_TRACK_CURRENT)
{
- uint8_t reply[3];
-
if(cmd_length!=1)
return LENGTH_ERROR;
uint16_t value = track_current_milliamps();
+ uint8_t reply[3];
reply[0] = TRACK_CURRENT;
reply[1] = value>>8;
reply[2] = value;
}
else if(cmd_buf[0]==READ_INPUT_VOLTAGE)
{
- uint8_t reply[3];
-
if(cmd_length!=1)
return LENGTH_ERROR;
uint16_t value = input_voltage_millivolts();
+ uint8_t reply[3];
reply[0] = INPUT_VOLTAGE;
reply[1] = value>>8;
reply[2] = value;