Changed INT0 to any edge
Added execution for highVoltage and signalOutput Added highVoltage boosting Added signal output
This commit is contained in:
parent
4e1ede21ff
commit
c720cc76e2
@ -1,8 +1,6 @@
|
||||
/*
|
||||
* geigerzaehler.c
|
||||
*
|
||||
=======
|
||||
>>>>>>> f39ee6c90de22ce1514bb4f9e7e3e3116efac22f
|
||||
* Created : 28.02.2019 09:07:22
|
||||
* Author : John Ditgens, Alexander Brandscheidt
|
||||
* Git-Repository : https://gitea.Railduction.eu/JohnD/Geigerzaehler.git
|
||||
@ -12,13 +10,30 @@
|
||||
*/
|
||||
#define F_CPU 20000000UL // Clock speed: 20 MHz - Maximum of AtMega328P
|
||||
|
||||
// Macros
|
||||
#define bit_get(p,m) ((p) & (m))
|
||||
#define bit_set(p,m) ((p) |= (m))
|
||||
#define bit_clear(p,m) ((p) &= ~(m))
|
||||
#define bit_flip(p,m) ((p) ^= (m))
|
||||
#define bit_write(c,p,m) (c ? bit_set(p,m) : bit_clear(p,m))
|
||||
#define BIT(x) (0x01 << (x))
|
||||
#define LONGBIT(x) ((unsigned long)0x00000001 << (x))
|
||||
|
||||
// Imports
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Global variable declaration
|
||||
uint8_t test = 0;
|
||||
uint32_t currTick = 0;
|
||||
|
||||
bool enable_boost = false;
|
||||
bool boost_highVoltage_nextHigh = true;
|
||||
uint32_t boost_highVoltage_nextTick = 0;
|
||||
|
||||
bool enable_signalOutput = false;
|
||||
bool signal_Output_nextHigh = true;
|
||||
uint32_t signal_Output_nextTick = 0;
|
||||
|
||||
|
||||
int main()
|
||||
@ -26,16 +41,11 @@ int main()
|
||||
DDRD &= ~(1<<2); // Activate PD2
|
||||
DDRD &= ~(1<<3); // Activate PD3
|
||||
|
||||
PORTD |= (1<<2); // Enable Pull Up Resistor Pin D2
|
||||
PORTD |= (1<<3); // Enable Pull Up Resistor Pin D3
|
||||
PORTD |= (1<<2); // Enable pull-up-resistor Pin-D2
|
||||
PORTD |= (1<<3); // Enable pull-up-resistor Pin-D3
|
||||
|
||||
EICRA |= (1 << ISC11)|(1 << ISC10); // Only at raising edge
|
||||
EIMSK |= (1 << INT1); // Activate Interrupt INT0
|
||||
|
||||
EICRA |= (1 << ISC00); // Only at falling edge
|
||||
EIMSK |= (1 << INT0); // Activate Interrupt INT1
|
||||
// Interrupt for INT0 Pin-D2 High-voltage check
|
||||
EICRA |= (1 << ISC01)|(0 << ISC00); // Only at falling edge [1|0]
|
||||
EICRA |= (0 << ISC01)|(1 << ISC00); // Only at any edge [0|1]
|
||||
EIMSK |= (1 << INT0); // Activate Interrupt INT0
|
||||
|
||||
// Interrupt for INT1 Pin-D3 Counter-click
|
||||
@ -47,6 +57,61 @@ int main()
|
||||
// Endless loop
|
||||
while (1)
|
||||
{
|
||||
// HighVoltage boosting
|
||||
if(enable_boost)
|
||||
{
|
||||
if(currTick >= boost_highVoltage_nextTick) // If we are on or after the tick it should be executed
|
||||
{
|
||||
// Set pin according to next exec
|
||||
if(boost_highVoltage_nextHigh) // Set it high
|
||||
{
|
||||
bit_set(PD4, 1);
|
||||
boost_highVoltage_nextHigh = false; // Next is low
|
||||
}
|
||||
else // Set it low
|
||||
{
|
||||
bit_set(PD4, 0);
|
||||
boost_highVoltage_nextHigh = true; // Next is high
|
||||
}
|
||||
|
||||
// Calculate when next high/low should be set
|
||||
boost_highVoltage_nextTick = currTick + 101 // Todo: Add calculation for pin high/low time
|
||||
}
|
||||
}else
|
||||
{
|
||||
if(boost_highVoltage_nextTick > 0) // If boosting is deactivated, but the nextTick was not reset yet
|
||||
{
|
||||
// Reset boost-state
|
||||
bit_set(PD4, 0);
|
||||
boost_highVoltage_nextHigh = true;
|
||||
boost_highVoltage_nextTick = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Signal output
|
||||
if(enable_signalOutput)
|
||||
{
|
||||
if(currTick >= signal_Output_nextTick) // If we are on or after the tick it should be executed
|
||||
{
|
||||
// Set pin according to next exec
|
||||
if(boost_highVoltage_nextHigh) // Set it high
|
||||
{
|
||||
bit_set(PD5, 1);
|
||||
bit_set(PD6, 1);
|
||||
boost_highVoltage_nextHigh = false; // Next is low
|
||||
}
|
||||
else // Set it low
|
||||
{
|
||||
bit_set(PD5, 0);
|
||||
bit_set(PD6, 0);
|
||||
boost_highVoltage_nextHigh = true; // Next is high
|
||||
}
|
||||
|
||||
// When the signal should stop
|
||||
boost_highVoltage_nextTick = currTick + 101 // Todo: Add calculation for pin high/low time
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,13 +122,25 @@ int main()
|
||||
// Address: 0x001 INT0
|
||||
ISR(INT0_vect)
|
||||
{
|
||||
|
||||
if(PIND&0x20 == 0x00) // Falling edge
|
||||
{
|
||||
// Below ~400V, activate booster
|
||||
enable_boost = true;
|
||||
}
|
||||
else // Rising edge
|
||||
{
|
||||
// Reached ~400V, deactivate booster
|
||||
enable_boost = false;
|
||||
}
|
||||
|
||||
reti(); // Exit interrupt-handler
|
||||
}
|
||||
|
||||
|
||||
ISR(INT1_vect)
|
||||
{
|
||||
// Tick detected, signalOutput
|
||||
enable_signalOutput = true;
|
||||
|
||||
reti(); // Exit interrupt-handler
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user