|
@@ -1,12 +1,14 @@
|
|
#include <avr/io.h>
|
|
#include <avr/io.h>
|
|
#include <util/delay.h>
|
|
#include <util/delay.h>
|
|
#include <avr/pgmspace.h>
|
|
#include <avr/pgmspace.h>
|
|
|
|
+#include <avr/eeprom.h>
|
|
#include "main.h"
|
|
#include "main.h"
|
|
#include "1wire.h"
|
|
#include "1wire.h"
|
|
#include "gtext.h"
|
|
#include "gtext.h"
|
|
#include "sed1335.h"
|
|
#include "sed1335.h"
|
|
#include "ds18b20.h"
|
|
#include "ds18b20.h"
|
|
#include "dac8571.h"
|
|
#include "dac8571.h"
|
|
|
|
+#include "ads1224.h"
|
|
|
|
|
|
#include "display.h"
|
|
#include "display.h"
|
|
|
|
|
|
@@ -28,12 +30,97 @@ unsigned char getkey(void){
|
|
return key;
|
|
return key;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+struct settings {
|
|
|
|
+ float coeff_generator_volt_A;
|
|
|
|
+ float coeff_generator_volt_B;
|
|
|
|
+ float coeff_generator_curr_A;
|
|
|
|
+ float coeff_generator_curr_B;
|
|
|
|
+ float coeff_disch_curr_A;
|
|
|
|
+ float coeff_disch_curr_B;
|
|
|
|
+ float coeff_volt_A;
|
|
|
|
+ float coeff_volt_B;
|
|
|
|
+ float coeff_curr_A;
|
|
|
|
+ float coeff_curr_B;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+struct settings settings;
|
|
|
|
+EEMEM struct settings eep_settings = {
|
|
|
|
+ .coeff_generator_volt_A = 1597.035901,
|
|
|
|
+ .coeff_generator_volt_B = 1317.235211,
|
|
|
|
+ .coeff_generator_curr_A = 65535.0/20,
|
|
|
|
+ .coeff_generator_curr_B = 1310,
|
|
|
|
+ .coeff_disch_curr_A = 65535.0/20,
|
|
|
|
+ .coeff_disch_curr_B = 1000,
|
|
|
|
+ .coeff_volt_A = 1,
|
|
|
|
+ .coeff_volt_B = 0,
|
|
|
|
+ .coeff_curr_A = 1,
|
|
|
|
+ .coeff_curr_B = 0,
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+unsigned int vdac = 0;
|
|
|
|
+unsigned int cdac = 0;
|
|
|
|
+
|
|
|
|
+void dac_update(void){
|
|
|
|
+ dac8571_set(cdac, CURR_DAC);
|
|
|
|
+ dac8571_set(vdac, VOLT_DAC);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void set_voltage(float u){
|
|
|
|
+ vdac = u * settings.coeff_generator_volt_A + settings.coeff_generator_volt_B;
|
|
|
|
+ dac_update();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void set_charge_curr(float i){
|
|
|
|
+ cdac = i * settings.coeff_generator_curr_A + settings.coeff_generator_curr_B;
|
|
|
|
+ dac_update();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void set_discharge_curr(float i){
|
|
|
|
+ cdac = i * settings.coeff_disch_curr_A + settings.coeff_disch_curr_B;
|
|
|
|
+ dac_update();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#define CONV_ENABLE _BV(PD5)
|
|
|
|
+#define DISCH_ENABLE _BV(PD1)
|
|
|
|
+#define REL_K1 _BV(PD6)
|
|
|
|
+#define REL_K2 _BV(PD7)
|
|
|
|
+
|
|
|
|
+#define K1_ON() {PORTD |= REL_K1;}
|
|
|
|
+#define K1_OFF() {PORTD &= ~REL_K1;}
|
|
|
|
+#define K2_ON() {PORTD |= REL_K2;}
|
|
|
|
+#define K2_OFF() {PORTD &= ~REL_K2;}
|
|
|
|
+#define POWER_OFF() {PORTD &= ~(CONV_ENABLE | DISCH_ENABLE);}
|
|
|
|
+#define CONV_ON() {PORTD |= CONV_ENABLE;}
|
|
|
|
+#define DISCH_ON() {PORTD |= DISCH_ENABLE;}
|
|
|
|
+
|
|
|
|
+void output_off(void){
|
|
|
|
+ cdac = 0;
|
|
|
|
+ vdac = 0;
|
|
|
|
+ POWER_OFF();
|
|
|
|
+ dac_update();
|
|
|
|
+ K1_OFF();
|
|
|
|
+ K2_OFF();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void charge_on(void){
|
|
|
|
+ output_off();
|
|
|
|
+ K1_ON();
|
|
|
|
+ CONV_ON();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void discharge_on(void){
|
|
|
|
+ output_off();
|
|
|
|
+ K2_ON();
|
|
|
|
+ DISCH_ON();
|
|
|
|
+}
|
|
|
|
+
|
|
void main(void){
|
|
void main(void){
|
|
unsigned char i=0;
|
|
unsigned char i=0;
|
|
|
|
+ static signed long int adc;
|
|
/* unsigned char state = STATE_DEFAULT;
|
|
/* unsigned char state = STATE_DEFAULT;
|
|
unsigned char oldstate = state;*/
|
|
unsigned char oldstate = state;*/
|
|
- unsigned int dac1 = 0, dac2 = 32768;
|
|
|
|
|
|
|
|
|
|
+ eeprom_read_block(&settings, &eep_settings, sizeof(struct settings));
|
|
|
|
|
|
OCR2A = 250; // 16ms
|
|
OCR2A = 250; // 16ms
|
|
TCCR2A = _BV(WGM21);
|
|
TCCR2A = _BV(WGM21);
|
|
@@ -41,20 +128,39 @@ void main(void){
|
|
TIMSK2 = _BV(OCIE2A);
|
|
TIMSK2 = _BV(OCIE2A);
|
|
sei();
|
|
sei();
|
|
|
|
|
|
- PORTC &= _BV(PC7);
|
|
|
|
- DDRB |= _BV(PB2);
|
|
|
|
|
|
+ PORTC &= _BV(PC7); // KEY
|
|
|
|
+ DDRB |= _BV(PB2); // TESTPOINT
|
|
|
|
+
|
|
|
|
+ DDRD |= REL_K1 | REL_K2 | DISCH_ENABLE | CONV_ENABLE;
|
|
|
|
|
|
GLCD_Initialize();
|
|
GLCD_Initialize();
|
|
GLCD_Clear();
|
|
GLCD_Clear();
|
|
|
|
+
|
|
|
|
+ ads1224_init();
|
|
|
|
+ ads1224_mux(AIN1);
|
|
|
|
+
|
|
|
|
+ charge_on();
|
|
|
|
+ set_voltage(12.6);
|
|
|
|
+ set_charge_curr(1.0);
|
|
|
|
+
|
|
for(;;){
|
|
for(;;){
|
|
_delay_ms(1);
|
|
_delay_ms(1);
|
|
- if(i = getkey()){
|
|
|
|
|
|
+ if((i = getkey())){
|
|
cursor(0,0);
|
|
cursor(0,0);
|
|
- disp_num(i);
|
|
|
|
|
|
+ disp_num(i, 0);
|
|
|
|
+ clearline();
|
|
|
|
+ }
|
|
|
|
+ dac_update();
|
|
|
|
+
|
|
|
|
+ if(adc_data_ready){
|
|
|
|
+ adc_data_ready = 0;
|
|
|
|
+ atomic_set_slint(&adc, adc_val);
|
|
|
|
+ cursor(0,1);
|
|
|
|
+ disp_num((adc * 1.55337778893448E-07 + -0.092784032021951) * 1000, 3);
|
|
clearline();
|
|
clearline();
|
|
}
|
|
}
|
|
- dac8571_set(++dac1, VOLT_DAC);
|
|
|
|
- dac8571_set(++dac2, CURR_DAC);
|
|
|
|
|
|
+// dac8571_set(++dac1, VOLT_DAC);
|
|
|
|
+// dac8571_set(++dac2, CURR_DAC);
|
|
/* gettemp();
|
|
/* gettemp();
|
|
control();
|
|
control();
|
|
state = state_processors[state](state);
|
|
state = state_processors[state](state);
|