52 lines
726 B
C
52 lines
726 B
C
|
/*
|
||
|
* Author: Jake G
|
||
|
* Date: 2024
|
||
|
* filename: zero_cross_detection.c
|
||
|
* description:
|
||
|
*/
|
||
|
|
||
|
#include "zero_cross_detection.h"
|
||
|
|
||
|
#define TRIGGERVAL 512
|
||
|
|
||
|
#ifndef UNIT_TESTING
|
||
|
#include "ADC.h"
|
||
|
#else
|
||
|
#include "MockADC/MockADC.h"
|
||
|
#endif
|
||
|
|
||
|
void ZCD_Setup(void)
|
||
|
{
|
||
|
ADC_Init(7);
|
||
|
ADC_Enable(7);
|
||
|
}
|
||
|
|
||
|
bool ZCD_IsTriggered()
|
||
|
{
|
||
|
uint16_t first, second;
|
||
|
ZCD_Setup();
|
||
|
first = ADC_ReadValue(7);
|
||
|
ADC_Disable();
|
||
|
|
||
|
ZCD_Setup();
|
||
|
second = ADC_ReadValue(7);
|
||
|
ADC_Disable();
|
||
|
|
||
|
if(second < TRIGGERVAL){
|
||
|
return false;
|
||
|
}
|
||
|
if(second < first){
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void ZCD_Poll(void)
|
||
|
{
|
||
|
while(true){
|
||
|
if(ZCD_IsTriggered()){
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|