Commit c87c32a2 authored by Martin Vítek's avatar Martin Vítek

Lot of fixes, buttons are dioing something now

parent 7241447c
......@@ -42,7 +42,7 @@ class adc_class
const uint8_t input[number_of_inputs];
volatile uint8_t current_pass;
const static uint8_t number_of_passes = 3;
const static uint8_t number_of_passes = 4;
volatile uint8_t current_input;
volatile uint16_t result[number_of_inputs*number_of_passes];
......@@ -84,7 +84,7 @@ class adc_class
//2,93kHz
TC4->COUNT8.CTRLA.reg = TC_CTRLA_MODE_COUNT8 | TC_CTRLA_PRESCALER_DIV256 | TC_CTRLA_PRESCSYNC_PRESC;
// -> 15kHz
// -> ~1.25kHz
TC4->COUNT8.PER.reg = 150;
while (TC4->COUNT8.STATUS.bit.SYNCBUSY) ;;
......@@ -133,7 +133,7 @@ class adc_class
ADC->CALIB.reg = ADC_CALIB_BIAS_CAL((*(uint32_t *) ADC_FUSES_BIASCAL_ADDR >> ADC_FUSES_BIASCAL_Pos)) |
ADC_CALIB_LINEARITY_CAL((*(uint64_t *) ADC_FUSES_LINEARITY_0_ADDR >> ADC_FUSES_LINEARITY_0_Pos));
ADC->SAMPCTRL.reg = 0;
ADC->SAMPCTRL.reg = 3;
//Enable start conversion by event
ADC->EVCTRL.bit.STARTEI = 1;
......@@ -230,8 +230,8 @@ class adc_class
value[CURRENT_12V] = get_voltage(value[CURRENT_12V]) * 100 / current(200, 22'000); //1,56A -> 1 560 000
value[CURRENT_180V] = get_voltage(value[CURRENT_180V]) * 100 / current(4'700, 33'000); //5,556mA -> 5 556
value[TEMPERATURE_BOOST] = get_voltage(value[TEMPERATURE_BOOST]) / 100 - 5'000; //20,25C -> 2025
value[TEMPERATURE_AMBIENT] = get_voltage(value[TEMPERATURE_AMBIENT]) / 100 - 5'000; //20,25C -> 2025
value[TEMPERATURE_BOOST] = (get_voltage(value[TEMPERATURE_BOOST]) - 500'000) / 100; //20,25C -> 2025
value[TEMPERATURE_AMBIENT] = (get_voltage(value[TEMPERATURE_AMBIENT]) - 500'000) / 100 - 650; //20,25C -> 2025
value[AMBIENT_LIGHT] = get_voltage(value[AMBIENT_LIGHT]) / 1000; //1000lx -> 1000
......
......@@ -28,7 +28,7 @@ class BCD4028
port.DIRSET.reg = A0 | A1 | A2 | A3;
}
void set(uint8_t number)
void set(const uint8_t number)
{
if (number > SET_BLANK) return;
......
......@@ -27,7 +27,8 @@ class BoostConverter
HYSTERESIS = 500, //0,5V
MAXIMUM_VOLTAGE_180V = 199'000, //199V
MAXIMUM_CURRENT_180V = 30'000, //30mA
MAXIMUM_CURRENT_12V = 1'000'000 //1A
MAXIMUM_CURRENT_12V = 1'000'000, //1A
MAXIMUM_TEMPERATURE = 49000 //48C
};
private:
......@@ -44,8 +45,8 @@ class BoostConverter
int32_t pozadavek;
int64_t integrator_ureg;
uint32_t U_regu;
const int32_t K = 500;
const int32_t I = 9;
const int32_t K = 100;
const int32_t I = 10;
public:
......@@ -91,7 +92,7 @@ class BoostConverter
/*
Init timer for regulator
*/
/* Not needed, regulator is called when ADC conversion is done
//48MHz, -> 5kHz
TC3->COUNT8.CTRLA.reg = TC_CTRLA_MODE_COUNT8 | TC_CTRLA_PRESCALER_DIV256 | TC_CTRLA_PRESCSYNC_PRESC;
TC3->COUNT8.INTENSET.reg = TC_INTENSET_ERR | TC_INTENSET_OVF;
......@@ -102,6 +103,7 @@ class BoostConverter
TC3->COUNT8.CTRLA.bit.ENABLE = 1;
while (TC3->COUNT8.STATUS.bit.SYNCBUSY) ;;
*/
}
void enable()
......@@ -137,7 +139,7 @@ class BoostConverter
{
duty++;
if (duty == 255) duty = 254;
if (duty == 251) duty = 250;
timer.CC[0].reg = duty;
......@@ -160,7 +162,7 @@ class BoostConverter
{
pozadavek = (requested_voltage - adc.value[adc.VOLTAGE_180V]);
U_regu = pi_reg(pozadavek, K, I, 10, 10, (238<<6)/*16256*/, 1, &integrator_ureg);
U_regu = pi_reg(pozadavek, K, I, 10, 10, (245<<6)/*16256*/, 1, &integrator_ureg);
duty = U_regu>>6;
timer.CC[0].reg = duty;
......@@ -199,14 +201,26 @@ class BoostConverter
void protections_handler()
{
if ( (adc.value[adc.VOLTAGE_180V] > MAXIMUM_VOLTAGE_180V) |
(adc.value[adc.CURRENT_180V] > MAXIMUM_CURRENT_180V) /*|
(adc.value[adc.CURRENT_12V] > MAXIMUM_CURRENT_12V) */)
if (adc.value[adc.VOLTAGE_180V] > MAXIMUM_VOLTAGE_180V)
{
disable();
if (duty > 50) duty -= 50;
else disable();
uart.send("Overvoltage: ");uart.send_dec(adc.value[adc.VOLTAGE_180V]);uart.send("\n\r");
}
if (adc.value[adc.CURRENT_180V] > MAXIMUM_CURRENT_180V)
{
disable();
uart.send("Overcurrent: ");uart.send_dec(adc.value[adc.CURRENT_180V]);uart.send("\n\r");
uart.send("Duty: ");uart.send_dec(duty);uart.send("\n\r\n\r");
}
if (adc.value[adc.TEMPERATURE_BOOST] > MAXIMUM_TEMPERATURE)
{
disable();
uart.send("Overtemperature: ");uart.send_dec(adc.value[adc.TEMPERATURE_BOOST]);uart.send("\n\r");
}
}
......@@ -215,7 +229,7 @@ class BoostConverter
if (TC3->COUNT8.INTFLAG.bit.OVF)
{
//regulator_handler();
PID_regulator();
//PID_regulator();
TC3->COUNT8.INTFLAG.reg = TC_INTFLAG_OVF;
}
......
......@@ -18,10 +18,15 @@ class Button
private:
Input button;
const uint8_t extint;
volatile bool status;
volatile bool was_serviced;
public:
Button(volatile PortGroup& port, uint8_t bit, uint8_t extint): button(port, bit, true),
extint(extint)
extint(extint),
status(false),
was_serviced(false)
{
}
......@@ -34,7 +39,24 @@ class Button
void interrupt_handler()
{
if (button.is_set()) { }
else { }
if (button.is_set()) status = true;
else status = false;
was_serviced = false;
}
bool is_set()
{
return status;
}
bool is_serviced()
{
return was_serviced;
}
void serviced()
{
was_serviced = true;
}
};
......@@ -123,6 +123,32 @@ void NixieClock::sntp_handler()
}
}
void NixieClock::buttons_handler()
{
if (!button_hour.is_serviced())
{
if(button_hour.is_set())
{
//Add hour
seconds += 60*60;
}
button_hour.serviced();
}
if (!button_min.is_serviced())
{
if(button_min.is_set())
{
//Add minute, reset seconds
localtime_r(&old_time, &time_date);
seconds += 60 - time_date.tm_sec;
}
button_min.serviced();
}
}
void NixieClock::get_mac()
{
eeprom.read_EUI(mac);
......
......@@ -47,7 +47,7 @@ class NixieClock
display_states state;
IP sntp_server_ip;
IP sntp_server_ip;
public:
NixieClock();
......@@ -58,6 +58,7 @@ class NixieClock
void display_handler();
void sntp_handler();
void buttons_handler();
void get_mac();
void print_eeprom();
......
......@@ -42,11 +42,11 @@ void NixieDisplay::init()
Init TC1
*/
//Normal mode, 732Hz
//Normal mode, 938Hz
TC1->COUNT8.CTRLA.reg = TC_CTRLA_PRESCSYNC_GCLK | TC_CTRLA_PRESCALER_DIV1 | TC_CTRLA_MODE_COUNT8;
//Set period, ~8kHz (0.12ms)
TC1->COUNT8.PER.reg = 32;
//Set period, 20kHz (0.05ms)
TC1->COUNT8.PER.reg = 12-1;
//Enable OVF interrupt
TC1->COUNT8.INTENSET.reg = TC_INTENSET_OVF;
......
......@@ -50,7 +50,7 @@ class NixieDisplay
enum multiplex_times
{
DISPLAYING_TIME = 14, //3.3ms
BLANKING_TIME = 2 //0.36ms
BLANKING_TIME = 3 //0.36ms
};
private:
......@@ -73,5 +73,4 @@ class NixieDisplay
void set(const uint8_t hod, const uint8_t min, const uint8_t sec);
void set(const uint8_t temperature);
void multiplex_handler();
};
......@@ -64,7 +64,7 @@ class SPI
spi.BAUD.reg = SystemCoreClock/this->baudrate;
}
uint32_t get_baudrate()
uint32_t get_baudrate() const
{
return SystemCoreClock/spi.BAUD.reg;
}
......
......@@ -37,7 +37,7 @@ class USART
}
//Initialize SERCOM0 in UART mode
//Initialize SERCOMx in UART mode
void init()
{
//Enable peripheral multiplexer and select peripheral function C
......@@ -68,7 +68,7 @@ class USART
//Enable Data Register Empty interrupt
//usart.INTENSET.reg = SERCOM_USART_INTENSET_DRE;
//Enable SERCOM0, wait for synchronization
//Enable USART, wait for synchronization
usart.CTRLA.bit.ENABLE = 1;
while (usart.STATUS.bit.SYNCBUSY) ;;
......
......@@ -35,19 +35,6 @@
using namespace ENC28J60_namespace;
static const ethernet_frame packet = {
{ 0x00, 0x30, 0x4F, 0x08, 0x35, 0x9C },
{ 0x54, 0x10, 0xEC, 0x20, 0xE5, 0xBD },
__htons(IPV4),
{{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, 200},
0
};
static const char packet_ip_icmp[] = {
0x45, 0x00, 0x00, 0x3c, 0x2d, 0x69, 0x00, 0x00,
0x80, 0x01, 0x8a, 0x04, 0xc0, 0xa8, 0x01, 0x01,
0xc0, 0xa8, 0x01, 0x02
};
int main(void)
{
......@@ -76,7 +63,7 @@ int main(void)
//Init SPI
spi.init();
//Init UART - 500 000baud, 8N1
//Init UART - 1 000 000baud, 8N1
uart.init();
nixie.display.init();
......@@ -122,6 +109,7 @@ int main(void)
nixie.display_handler();
nixie.separator.pulsing_handler();
nixie.sntp_handler();
nixie.buttons_handler();
eth.get_interrupt_source();
stack.check_link();
......@@ -134,15 +122,15 @@ int main(void)
{
adc.convert_values();
boost.protections_handler();
boost.regulator_handler();
adc.done = false;
}
if (time(NULL) >= old)
{
old = time(NULL) + 10;
nixie.display_time();
/*
switch (nixie.state)
{
case NixieClock::DISPLAYING_TIME: nixie.display_date();
......@@ -154,12 +142,11 @@ int main(void)
case NixieClock::DISPLAYING_TEMPERATURE: nixie.display_time();
break;
}
*/
}
if ((clock() % 1000) == 0 )
{
/*
//Send ADC values
uart.send("Voltage 12V:\t");
uart.send_dec(adc.value[adc.VOLTAGE_12V]/1000);uart.send('.');uart.send_dec(adc.value[adc.VOLTAGE_12V]%1000);
uart.send_new_line();
......@@ -193,7 +180,6 @@ int main(void)
uart.send_new_line();
uart.send_new_line();
*/
}
}
}
......@@ -121,75 +121,75 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings>
<ArmGccCpp>
<armgcc.common.outputfiles.hex>True</armgcc.common.outputfiles.hex>
<armgcc.common.outputfiles.lss>True</armgcc.common.outputfiles.lss>
<armgcc.common.outputfiles.eep>True</armgcc.common.outputfiles.eep>
<armgcc.common.outputfiles.bin>True</armgcc.common.outputfiles.bin>
<armgcc.common.outputfiles.srec>True</armgcc.common.outputfiles.srec>
<armgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</armgcc.compiler.symbols.DefSymbols>
<armgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcc.compiler.directories.IncludePaths>
<armgcc.compiler.optimization.level>Optimize for size (-Os)</armgcc.compiler.optimization.level>
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcc.compiler.optimization.PrepareDataForGarbageCollection>True</armgcc.compiler.optimization.PrepareDataForGarbageCollection>
<armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel>
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>
<armgcc.compiler.warnings.ExtraWarnings>True</armgcc.compiler.warnings.ExtraWarnings>
<armgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</armgcccpp.compiler.symbols.DefSymbols>
<armgcccpp.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.compiler.directories.IncludePaths>
<armgcccpp.compiler.optimization.level>Optimize for size (-Os)</armgcccpp.compiler.optimization.level>
<armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>
<armgcccpp.compiler.optimization.DebugLevel>Maximum (-g3)</armgcccpp.compiler.optimization.DebugLevel>
<armgcccpp.compiler.warnings.AllWarnings>True</armgcccpp.compiler.warnings.AllWarnings>
<armgcccpp.compiler.warnings.ExtraWarnings>True</armgcccpp.compiler.warnings.ExtraWarnings>
<armgcccpp.compiler.miscellaneous.OtherFlags>-std=gnu++14</armgcccpp.compiler.miscellaneous.OtherFlags>
<armgcccpp.linker.general.AdditionalSpecs>Use syscall stubs (--specs=nosys.specs)</armgcccpp.linker.general.AdditionalSpecs>
<armgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</armgcccpp.linker.libraries.Libraries>
<armgcccpp.linker.libraries.LibrarySearchPaths>
<ListValues>
<Value>%24(ProjectDir)\Device_Startup</Value>
</ListValues>
</armgcccpp.linker.libraries.LibrarySearchPaths>
<armgcccpp.linker.optimization.GarbageCollectUnusedSections>True</armgcccpp.linker.optimization.GarbageCollectUnusedSections>
<armgcccpp.linker.memorysettings.ExternalRAM />
<armgcccpp.linker.miscellaneous.LinkerFlags>-Tsamd20g18_flash.ld</armgcccpp.linker.miscellaneous.LinkerFlags>
<armgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.assembler.general.IncludePaths>
<armgcccpp.assembler.debugging.DebugLevel>Default (-g)</armgcccpp.assembler.debugging.DebugLevel>
<armgcccpp.preprocessingassembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.preprocessingassembler.general.IncludePaths>
<armgcccpp.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcccpp.preprocessingassembler.debugging.DebugLevel>
</ArmGccCpp>
<armgcc.common.outputfiles.hex>True</armgcc.common.outputfiles.hex>
<armgcc.common.outputfiles.lss>True</armgcc.common.outputfiles.lss>
<armgcc.common.outputfiles.eep>True</armgcc.common.outputfiles.eep>
<armgcc.common.outputfiles.bin>True</armgcc.common.outputfiles.bin>
<armgcc.common.outputfiles.srec>True</armgcc.common.outputfiles.srec>
<armgcc.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</armgcc.compiler.symbols.DefSymbols>
<armgcc.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcc.compiler.directories.IncludePaths>
<armgcc.compiler.optimization.level>Optimize for size (-Os)</armgcc.compiler.optimization.level>
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcc.compiler.optimization.PrepareDataForGarbageCollection>True</armgcc.compiler.optimization.PrepareDataForGarbageCollection>
<armgcc.compiler.optimization.DebugLevel>Maximum (-g3)</armgcc.compiler.optimization.DebugLevel>
<armgcc.compiler.warnings.AllWarnings>True</armgcc.compiler.warnings.AllWarnings>
<armgcc.compiler.warnings.ExtraWarnings>True</armgcc.compiler.warnings.ExtraWarnings>
<armgcccpp.compiler.symbols.DefSymbols>
<ListValues>
<Value>DEBUG</Value>
</ListValues>
</armgcccpp.compiler.symbols.DefSymbols>
<armgcccpp.compiler.directories.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.compiler.directories.IncludePaths>
<armgcccpp.compiler.optimization.level>Optimize for size (-Os)</armgcccpp.compiler.optimization.level>
<armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>True</armgcccpp.compiler.optimization.PrepareDataForGarbageCollection>
<armgcccpp.compiler.optimization.DebugLevel>Maximum (-g3)</armgcccpp.compiler.optimization.DebugLevel>
<armgcccpp.compiler.warnings.AllWarnings>True</armgcccpp.compiler.warnings.AllWarnings>
<armgcccpp.compiler.warnings.ExtraWarnings>True</armgcccpp.compiler.warnings.ExtraWarnings>
<armgcccpp.compiler.miscellaneous.OtherFlags>-std=gnu++14</armgcccpp.compiler.miscellaneous.OtherFlags>
<armgcccpp.linker.general.AdditionalSpecs>Use syscall stubs (--specs=nosys.specs)</armgcccpp.linker.general.AdditionalSpecs>
<armgcccpp.linker.libraries.Libraries>
<ListValues>
<Value>libm</Value>
</ListValues>
</armgcccpp.linker.libraries.Libraries>
<armgcccpp.linker.libraries.LibrarySearchPaths>
<ListValues>
<Value>%24(ProjectDir)\Device_Startup</Value>
</ListValues>
</armgcccpp.linker.libraries.LibrarySearchPaths>
<armgcccpp.linker.optimization.GarbageCollectUnusedSections>True</armgcccpp.linker.optimization.GarbageCollectUnusedSections>
<armgcccpp.linker.memorysettings.ExternalRAM />
<armgcccpp.linker.miscellaneous.LinkerFlags>-Tsamd20g18_flash.ld</armgcccpp.linker.miscellaneous.LinkerFlags>
<armgcccpp.assembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.assembler.general.IncludePaths>
<armgcccpp.assembler.debugging.DebugLevel>Default (-g)</armgcccpp.assembler.debugging.DebugLevel>
<armgcccpp.preprocessingassembler.general.IncludePaths>
<ListValues>
<Value>%24(PackRepoDir)\atmel\SAMD20_DFP\1.1.84\samd20\include</Value>
<Value>%24(PackRepoDir)\arm\CMSIS\4.2.0\CMSIS\Include\</Value>
</ListValues>
</armgcccpp.preprocessingassembler.general.IncludePaths>
<armgcccpp.preprocessingassembler.debugging.DebugLevel>Default (-Wa,-g)</armgcccpp.preprocessingassembler.debugging.DebugLevel>
</ArmGccCpp>
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
......@@ -277,6 +277,9 @@
<Compile Include="main.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="NetworkTypes.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="NixieClock.cpp">
<SubType>compile</SubType>
</Compile>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment