Hi all,
I am currently working in a microwave sensor with the main control unit being a SAMD21 MCU. The system works by amplifying a signal received from a a microwave sensor on board. The signal is then transformed into a PWM through the use of a comparator and then fed into a pin of the mcu.
Due to the nature of the sensor and the presence of a relay on the board, there are random bursts than can make the MCU think there might be ome detection which leads to the MCU to close the relay.
My solution to this is to filter these bursts by ignoring a small # of consecutive bursts (around 3 or 5). This is assuming that anything above that will be treated as motion and the relay will close. This being said, I am struggling to figure out how I am going to ignore these pulses. I tried counting the pulses through code but due to my lack of experience in programming, I cannot seem to come up with a working solution. Would anyone know how to implement this?
Attached is my code, I am not sure how to attach MPLAB projects, let alone for those who do not use MPLAB Harmony:
/*******************************************************************************
Main Source File
Company:
Microchip Technology Inc.
File Name:
main.c
Summary:
This file contains the "main" function for a project.
Description:
This file contains the "main" function for a project. The
"main" function calls the "SYS_Initialize" function to initialize the state
machines of all modules in the system
*******************************************************************************/
// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************
#include <stddef.h> // Defines NULL
#include <stdbool.h> // Defines true
#include <stdlib.h> // Defines EXIT_FAILURE
#include "definitions.h" // SYS function prototypes
// *****************************************************************************
// *****************************************************************************
// Section: Main Entry Point
// *****************************************************************************
// *****************************************************************************
int c=0;
int flag;
uint16_t count = 0;
//int wait = 0;
bool buff=false;
void TC3_Handler(){
if(Pulse_In_Get()==0){
flag=1;
}
if(count>=10){
Pulse_Out_Clear();
c=0;
buff = true;
}
if(buff == true) c++;
if(c>=3000){
Pulse_Out_Set();
c=0;
buff = false;
count=0;
}
TC3_REGS->COUNT16.TC_INTFLAG=255; //clear all TC3_REGS interrupts
}
int main ( void )
{
/* Initialize all modules */
SYS_Initialize ( NULL );
TC3_TimerStart();
while(flag == 1){
count = count+1;
flag =0;
}
//Pulse_Out_Set();
while ( 1 )
{
/* Maintain state machines of all polled MPLAB Harmony modules. */
SYS_Tasks ( );
}
return ( EXIT_FAILURE );
}
/* Execution should not come here during normal operation */
/*******************************************************************************
End of File
*/
I am currently working in a microwave sensor with the main control unit being a SAMD21 MCU. The system works by amplifying a signal received from a a microwave sensor on board. The signal is then transformed into a PWM through the use of a comparator and then fed into a pin of the mcu.
Due to the nature of the sensor and the presence of a relay on the board, there are random bursts than can make the MCU think there might be ome detection which leads to the MCU to close the relay.
My solution to this is to filter these bursts by ignoring a small # of consecutive bursts (around 3 or 5). This is assuming that anything above that will be treated as motion and the relay will close. This being said, I am struggling to figure out how I am going to ignore these pulses. I tried counting the pulses through code but due to my lack of experience in programming, I cannot seem to come up with a working solution. Would anyone know how to implement this?
Attached is my code, I am not sure how to attach MPLAB projects, let alone for those who do not use MPLAB Harmony:
/*******************************************************************************
Main Source File
Company:
Microchip Technology Inc.
File Name:
main.c
Summary:
This file contains the "main" function for a project.
Description:
This file contains the "main" function for a project. The
"main" function calls the "SYS_Initialize" function to initialize the state
machines of all modules in the system
*******************************************************************************/
// *****************************************************************************
// *****************************************************************************
// Section: Included Files
// *****************************************************************************
// *****************************************************************************
#include <stddef.h> // Defines NULL
#include <stdbool.h> // Defines true
#include <stdlib.h> // Defines EXIT_FAILURE
#include "definitions.h" // SYS function prototypes
// *****************************************************************************
// *****************************************************************************
// Section: Main Entry Point
// *****************************************************************************
// *****************************************************************************
int c=0;
int flag;
uint16_t count = 0;
//int wait = 0;
bool buff=false;
void TC3_Handler(){
if(Pulse_In_Get()==0){
flag=1;
}
if(count>=10){
Pulse_Out_Clear();
c=0;
buff = true;
}
if(buff == true) c++;
if(c>=3000){
Pulse_Out_Set();
c=0;
buff = false;
count=0;
}
TC3_REGS->COUNT16.TC_INTFLAG=255; //clear all TC3_REGS interrupts
}
int main ( void )
{
/* Initialize all modules */
SYS_Initialize ( NULL );
TC3_TimerStart();
while(flag == 1){
count = count+1;
flag =0;
}
//Pulse_Out_Set();
while ( 1 )
{
/* Maintain state machines of all polled MPLAB Harmony modules. */
SYS_Tasks ( );
}
return ( EXIT_FAILURE );
}
/* Execution should not come here during normal operation */
/*******************************************************************************
End of File
*/