added first draft of overvoltage protection by using dump load
This commit is contained in:
parent
b56710f04b
commit
c9bc24d8a7
|
@ -2,12 +2,14 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="9fad4545-a424-4a82-86dc-76602cf3eef3" name="Default" comment="">
|
<list default="true" id="9fad4545-a424-4a82-86dc-76602cf3eef3" name="Default" comment="">
|
||||||
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/powerboard/src/main.c" afterPath="$PROJECT_DIR$/powerboard/src/main.c" />
|
||||||
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
||||||
</list>
|
</list>
|
||||||
<ignored path="bikegenerator.iws" />
|
<ignored path="bikegenerator.iws" />
|
||||||
<ignored path=".idea/workspace.xml" />
|
<ignored path=".idea/workspace.xml" />
|
||||||
<file path="/Makefile" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1370979337668" ignored="false" />
|
<file path="/Makefile" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1370979337668" ignored="false" />
|
||||||
<file path="/Dummy.txt" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1370989840314" ignored="false" />
|
<file path="/Dummy.txt" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1370989840314" ignored="false" />
|
||||||
|
<file path="/main.c" changelist="9fad4545-a424-4a82-86dc-76602cf3eef3" time="1370991964646" ignored="false" />
|
||||||
<option name="TRACKING_ENABLED" value="true" />
|
<option name="TRACKING_ENABLED" value="true" />
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
@ -80,7 +82,7 @@
|
||||||
<file leaf-file-name="main.c" pinned="false" current="true" current-in-tab="true">
|
<file leaf-file-name="main.c" pinned="false" current="true" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/powerboard/src/main.c">
|
<entry file="file://$PROJECT_DIR$/powerboard/src/main.c">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state line="14" column="53" selection-start="265" selection-end="265" vertical-scroll-proportion="-1.0426009">
|
<state line="122" column="12" selection-start="2842" selection-end="2842" vertical-scroll-proportion="1.8497758">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -519,7 +521,7 @@
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/powerboard/src/main.c">
|
<entry file="file://$PROJECT_DIR$/powerboard/src/main.c">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state line="14" column="53" selection-start="265" selection-end="265" vertical-scroll-proportion="-1.0426009">
|
<state line="122" column="12" selection-start="2842" selection-end="2842" vertical-scroll-proportion="1.8497758">
|
||||||
<folding />
|
<folding />
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
|
@ -22,10 +22,15 @@
|
||||||
#define DUMP_ON PORT_SW |= _BV(DUMPSW)
|
#define DUMP_ON PORT_SW |= _BV(DUMPSW)
|
||||||
#define DUMP_OFF PORT_SW &= ~_BV(DUMPSW)
|
#define DUMP_OFF PORT_SW &= ~_BV(DUMPSW)
|
||||||
|
|
||||||
typedef enum {
|
#define OVERVOLTAGE1 144
|
||||||
generated,
|
#define OVERVOLTAGE2 150
|
||||||
consumed
|
#define OVERVOLTAGE_TIMEOUT1 20
|
||||||
} power_source;
|
#define OVERVOLTAGE_TIMEOUT2 20
|
||||||
|
|
||||||
|
#define CURRENT_OFFSET 511
|
||||||
|
#define CURRENT_PER_TICK 72
|
||||||
|
#define TICKS_PER_VOLTAGE 6.6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
volatile uint16_t syscounter = 0;
|
volatile uint16_t syscounter = 0;
|
||||||
|
@ -33,6 +38,10 @@ uint16_t voltage = 0;
|
||||||
int16_t current_in = 0;
|
int16_t current_in = 0;
|
||||||
int16_t current_out = 0;
|
int16_t current_out = 0;
|
||||||
|
|
||||||
|
uint16_t overvoltage_counter = 0;
|
||||||
|
uint16_t overvoltage_off_counter = 0;
|
||||||
|
|
||||||
|
|
||||||
void timer_init(void) {
|
void timer_init(void) {
|
||||||
// clock is 8MHz
|
// clock is 8MHz
|
||||||
TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64
|
TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // CTC Mode for Timer 1 (16Bit) with prescale of 64
|
||||||
|
@ -47,15 +56,15 @@ void ports_init(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void measure(void) {
|
void measure(void) {
|
||||||
voltage = adc_read_avg(AD_V, 4) / 6.6;
|
voltage = adc_read_avg(AD_V, 4) / TICKS_PER_VOLTAGE;
|
||||||
|
|
||||||
current_in = adc_read_avg(AD_I_GEN, 4);
|
current_in = adc_read_avg(AD_I_GEN, 4);
|
||||||
current_in -= 510;
|
current_in -= VOLTAGE_OFFSET;
|
||||||
current_in *= 72;
|
current_in *= CURRENT_PER_TICK;
|
||||||
|
|
||||||
current_out = adc_read_avg(AD_I_LOAD, 4);
|
current_out = adc_read_avg(AD_I_LOAD, 4);
|
||||||
current_out -= 511;
|
current_out -= VOLTAGE_OFFSET;
|
||||||
current_out *= 72;
|
current_out *= CURRENT_PER_TICK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t get_power(uint16_t voltage, int16_t currents) {
|
uint8_t get_power(uint16_t voltage, int16_t currents) {
|
||||||
|
@ -79,6 +88,8 @@ int main(void) {
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
|
|
||||||
|
if((syscounter % 100) == 0) {
|
||||||
|
|
||||||
measure();
|
measure();
|
||||||
|
|
||||||
uart_puts_P("Voltage: ");
|
uart_puts_P("Voltage: ");
|
||||||
|
@ -101,19 +112,31 @@ int main(void) {
|
||||||
uart_puts_P("W\r\n");
|
uart_puts_P("W\r\n");
|
||||||
|
|
||||||
|
|
||||||
|
if(voltage > OVERVOLTAGE1) {
|
||||||
|
overvoltage_off_counter = 0;
|
||||||
|
overvoltage_counter++;
|
||||||
|
} else {
|
||||||
|
overvoltage_counter = 0;
|
||||||
|
overvoltage_off_counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uart_puts_P("overvoltage_counter=");
|
||||||
|
uart_puts ( itoa ( overvoltage_counter, s, 10 ) );
|
||||||
|
uart_puts_P(" overvoltage_off_counter=");
|
||||||
|
uart_puts ( itoa ( overvoltage_off_counter , s, 10 ) );
|
||||||
|
|
||||||
|
if(overvoltage_counter >= OVERVOLTAGE_TIMEOUT1) {
|
||||||
|
overvoltage_off_counter = 0;
|
||||||
|
DUMP_ON;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(overvoltage_off_counter >= OVERVOLTAGE_TIMEOUT1/2) {
|
||||||
|
overvoltage_counter = 0;
|
||||||
|
DUMP_OFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
wait(100);
|
|
||||||
wait(100);
|
|
||||||
wait(100);
|
|
||||||
wait(100);
|
|
||||||
//wait(100);
|
|
||||||
//wait(100);
|
|
||||||
wait(100);
|
|
||||||
wait(100);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
|
@ -122,6 +145,7 @@ int main(void) {
|
||||||
// system timer
|
// system timer
|
||||||
SIGNAL(TIMER1_COMPA_vect) {
|
SIGNAL(TIMER1_COMPA_vect) {
|
||||||
syscounter++;
|
syscounter++;
|
||||||
|
syscounter %= 60000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue