#include "timer_System.h"
#include "calib_manager.h"
#include "ac_adq.h"
#include "inps_manager.h"
#include "led_manager.h"
#include "pot_manager.h"
#include "adjust_manager.h"
#include "rele_manager.h"
#include "tc_manager.h"
#include "global.h"
/*#define POT1 0
#define POT2 1
#define POT3 2*/
uint8_t REDLED = 10;
uint8_t GREENLED = 9;
void SetTimer1()
{
cli(); //stop interrupts
//set timer1 interrupt at 120Hz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 60hz increments
OCR1A = 10000; // = (16*10^6) / (120 * 8) - 1 (must be <65536) //60Hz 16683
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler
//TCCR1B |= (1 << CS12) | (1 << CS10);
// Set CS11 bit for 8 prescaler
TCCR1B |= (1 << CS11);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei(); //allow interrupts
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
ISR(TIMER1_COMPA_vect)
{
flagTickBase = 1;
TimersSys_Tick();
inpManager_Refresh();
//Serial.println("Timer Test");
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(57200);
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
SetTimer1();
TimersSys_Init(); // Inicializa la estructuras de los 4 timers del sistema, en el header de la libreria
TimersSys_Start(0, 10); // Inicializa 0 de TimerSys, de calibración 100 ms
TimersSys_Start(1, 12); // Inicializa 1 de TimersSys: 120ms (12 * Tick de TMR2(10ms))
TimersSys_Start(2, 6); // Inicializa 2 de TimersSys: 60ms (6 * Tick de TMR2(10ms)) 16 por segundo
TimersSys_Start(3, 100); // Inicializa 3 de TimersSys: 2s (200 * Tick de TMR2(10ms))
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
relay_Init(RELAY_CNNDLY_DISABLE & RELAY_DCNNDLY_DISABLE & RELAY_POL_DIRECT & (RELAY_GPIO_MASK_PIN | 4),0,0);
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// put your setup code here, to run once:
//pinMode(PINLED, OUTPUT);
inpsManager_Init();
inpsManager_Cfg(0, 5, INPUT_PULLUP);
inpsManager_Cfg(1, 3, INPUT_PULLUP);
inpsManager_Cfg(2, 2, INPUT_PULLUP);
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
potManager_Init(); //inicializa las estructuras de potenciometro
potManager_CfgPot(POT1, A1); //
potManager_CfgPot(POT2, A2); //
potManager_CfgPot(POT3, A3); //
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
ledManager_CfgLed(0, REDLED);
ledManager_CfgLed(1, GREENLED);
ledManager_DefSecOut(LED_BLINK1, 0b11000000); //define la secuencias del estado BLINK1
ledManager_DefSecOut(LED_BLINK2, 0b11001100); //define la secuencias del estado BLINK1
ledManager_Update(0, LED_BLINK2);
ledManager_Update(1, LED_BLINK1);
}
void loop()
{
//////////////////////////////////////////////
if(flagTickBase == 1)
{
flagTickBase = 0;
if(infoGTC.b.flagInit == 0)
{
initGTC();
}
if(pot2 < 4)
{
processTimerGTC();
}
}
//////////////////////////////////////////////
if (TIMERSYS_CHECK_EVENT(2)) // 120 ms
{
TIMERSYS_CLEAR_EVENT(2);
}
//llevar esta a 50 ms
if (TIMERSYS_CHECK_EVENT(1)) // 60 ms
{
TIMERSYS_CLEAR_EVENT(1);
}
if (TIMERSYS_CHECK_EVENT(3)) //1s
{
TIMERSYS_CLEAR_EVENT(3);
if(pot2 == 4)
{
processTimerGTC();
}
}
/*if(inpsInfo[0].b.change == 1)
{
inpsInfo[0].b.change = 0;
if(GET_INP_STATE(0))
{
Serial.println("Pin0, Alto");
}
else
{
Serial.println("Pin0, Bajo");
}
}*/
}