Microwave sensor light control with SAMD21 microcontroller

Thread Starter

Carloco0306

Joined Nov 13, 2018
42
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
*/
 

m_alizd

Joined Oct 1, 2019
21
I have a little bit pf difficulty understanding the problem in terms of input and output to your MCU hardware/firmware.
It would help if you attach a snapshot of current input output waveform or oscilloscope capture also a sketch of the desired one. Would be good to see what the bursts look like.
What is the value that sensor is reading?
Is PWM the ultimate input to your MCU? because usually PWM would be the output control signal not the input. If it is input what is MCU measuring? Do you have a sample timing/waveform?
The output looks like to be a relay, when do you want it to be closed and when to open?

Based on your description of getting some unwanted bursts, I think your problem is similar to another problem called Key bounce.
If so, the solution for that, i.e. key debounce, methods might be adapted to solve your problem, too.

In terms of your program didn't get too much into detail as yet, but the comment of "main entry point" looks like to be misplaced. The main entry point is where "int main(" line is.
 

Thread Starter

Carloco0306

Joined Nov 13, 2018
42
I have a little bit pf difficulty understanding the problem in terms of input and output to your MCU hardware/firmware.
It would help if you attach a snapshot of current input output waveform or oscilloscope capture also a sketch of the desired one. Would be good to see what the bursts look like.
What is the value that sensor is reading?
Is PWM the ultimate input to your MCU? because usually PWM would be the output control signal not the input. If it is input what is MCU measuring? Do you have a sample timing/waveform?
The output looks like to be a relay, when do you want it to be closed and when to open?

Based on your description of getting some unwanted bursts, I think your problem is similar to another problem called Key bounce.
If so, the solution for that, i.e. key debounce, methods might be adapted to solve your problem, too.

In terms of your program didn't get too much into detail as yet, but the comment of "main entry point" looks like to be misplaced. The main entry point is where "int main(" line is.
upload_2019-10-15_9-16-48.png

The output is on the far right, as you can see, it is a square wave which stays HIGH at 3.3 V when there is no movement by goes down to 0 when it detects movement. This means that whenever the signal goes to 0, the relay will close. What I am trying to do is add a delay, not just to counter the surge due to the relay, but to also tune my amplifier to a desirable amplitude without having any random disturbances due to noise.
 
Top