2024-07-02 15:45:19 +00:00
|
|
|
/**
|
|
|
|
* @file main.c
|
|
|
|
* @author Jake G
|
|
|
|
* @date 15 June 2024
|
|
|
|
* @brief File contains the main function.
|
|
|
|
*
|
|
|
|
* This file contains the main logic loop and exists to setup the values
|
|
|
|
* specific to the micro-controller. All other functions and configuration are
|
|
|
|
* extracted into separate source files and headers for configuration.
|
|
|
|
*/
|
|
|
|
|
2024-07-15 19:13:28 +00:00
|
|
|
//#define F_CPU 2000000UL
|
|
|
|
#define F_CPU 3333333UL
|
2024-07-02 15:45:19 +00:00
|
|
|
|
|
|
|
//These defines are mostly useful for when you want you editors LSP server to
|
|
|
|
//function correctly.
|
|
|
|
//#ifndef __AVR_ATtiny404__
|
|
|
|
//#define __AVR_ATtiny404__
|
|
|
|
//#endif
|
|
|
|
|
2024-07-15 00:25:44 +00:00
|
|
|
//This can prevent issues with util/delay.h library with the gcc toolchain
|
2024-07-02 15:45:19 +00:00
|
|
|
#define __DELAY_BACKWARD_COMPATIBLE__
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "RegEdit.h"
|
|
|
|
#include "zero_cross_detection.h"
|
|
|
|
#include "ADC.h"
|
|
|
|
#include "TriacOut.h"
|
2024-07-02 22:27:57 +00:00
|
|
|
#include "load.h"
|
2024-07-10 01:47:16 +00:00
|
|
|
#include <avr/cpufunc.h> /* Required header file */
|
2024-07-02 15:45:19 +00:00
|
|
|
#include <avr/io.h>
|
|
|
|
#include <util/delay.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Set the function pointer for the delay func
|
|
|
|
void (*Delay_MicroSeconds)(double us) = _delay_us;
|
|
|
|
//void (*Delay_MicroSeconds)(double us) = _delay_ms;
|
|
|
|
|
2024-07-10 01:47:16 +00:00
|
|
|
static void CLK_DisablePrescaler(void)
|
|
|
|
{
|
|
|
|
//CCP = CCP_IOREG_gc; /* Write the needed signature to CCP*/
|
|
|
|
ccp_write_io((void *) & (CLKCTRL.MCLKCTRLA), 0x00); //select internal 20MHz clock.
|
|
|
|
ccp_write_io((void *) & (CLKCTRL.MCLKCTRLB), 0x00); //Disable the pre-scaler.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-02 15:45:19 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2024-07-15 19:13:28 +00:00
|
|
|
//CLK_DisablePrescaler();
|
2024-07-02 15:45:19 +00:00
|
|
|
while(true){
|
|
|
|
for(int i = 0; i < GatePulsesQty; i++){
|
|
|
|
ZCD_Poll();
|
|
|
|
_delay_us(Tau);
|
|
|
|
TriacOut_SetupPins();
|
|
|
|
TriacOut_SetAllHigh();
|
|
|
|
TriacOut_PulsePins(GatePulses[i]);
|
|
|
|
}
|
2024-07-02 18:04:06 +00:00
|
|
|
|
2024-07-02 22:35:10 +00:00
|
|
|
//The G1-G3 pins are low at this point.
|
2024-07-02 18:04:06 +00:00
|
|
|
_delay_ms(2500);
|
|
|
|
ZCD_Poll();
|
|
|
|
TriacOut_SetupPins();
|
|
|
|
TriacOut_SetAllHigh();
|
2024-07-03 00:16:53 +00:00
|
|
|
|
|
|
|
Load_HandleLoadPortA(ADC_LOAD1, 1);
|
|
|
|
Load_HandleLoadPortB(ADC_LOAD2, 3);
|
|
|
|
Load_HandleLoadPortB(ADC_LOAD3, 2);
|
|
|
|
|
2024-07-02 18:04:06 +00:00
|
|
|
while(true){
|
2024-07-02 22:35:10 +00:00
|
|
|
; //Do nothing until new Power cycle/reset occurs
|
2024-07-02 18:04:06 +00:00
|
|
|
}
|
2024-07-02 15:45:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|