fg004_a1/main.c

69 lines
1.8 KiB
C
Raw Permalink Normal View History

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.
*/
#define F_CPU 3333333UL
2024-07-02 15:45:19 +00:00
//These defines are mostly useful for when you want your editors LSP server to
2024-07-02 15:45:19 +00:00
//function correctly.
//#ifndef __AVR_ATtiny404__
//#define __AVR_ATtiny404__
//#endif
//This can prevent issues with utils/delay.h library with the gcc toolchain
#define __DELAY_BACKWARD_COMPATIBLE__
#include "config.h"
#include "RegEdit.h"
#include "zero_cross_detection.h"
#include "ADC.h"
#include "TriacOut.h"
#include "load.h"
#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;
static void setEnablePinsHigh(void)
{
//Pins 12, 6 and 7 are all set high.
PORTA.DIR |= (1<<2); //PA2= pin 12
PORTB.DIR |= (1<<2)|(1<<3); //PB2 = pin 7, PB3 = pin 6
PORTA.OUT |= (1<<2);
PORTB.OUT |= (1<<2)|(1<<3);
}
2024-07-02 15:45:19 +00:00
int main(int argc, char **argv)
{
while(true){
for(int i = 0; i < GatePulsesQty; i++){
ZCD_Poll();
_delay_us(Tau);
TriacOut_SetupPins();
TriacOut_SetAllHigh(); //Only G1 exists in High power mode
2024-07-02 15:45:19 +00:00
TriacOut_PulsePins(GatePulses[i]);
}
//The G1 pin is low at this point.
_delay_ms(2500);
ZCD_Poll();
setEnablePinsHigh();
while(true){
; //Do nothing until new Power cycle/reset occurs
}
2024-07-02 15:45:19 +00:00
}
}