Please share your suggestions, comments, and criticisms in the box below. Every message is read and receives a response. Thank you for taking time to improve the tool!
This example demonstrates how to use the computation features of the 12-bit ADC with Computation (ADCC), along with other intelligent peripherals on PIC16F18446, to create a core-independent solution to microwave-based motion sensing.
A combination of the peripherals on PIC16F18446 can provide a hardware-based solution with minimal software routines and CPU interference. Therefore, in a typical sensor node application like this, the CPU can be put into sleep mode for most of the time to reduce power consumption (especially for a battery-powered application), or take time to do other tasks to increase system functionality.
It uses the Microwave Click from Mikroelektronika, and a PIC16F18446 Xpress Board. The LED on the Xpress Board will be turned on, and a message will be sent through the serial port when there is a motion. Before using, press the pushbutton on the Xpress board to calibrate a reference first. The calibration takes around half a second.
Before we get started, let's take a moment and briefly look at how the motion sensing works with a Microwave Click.
The Microwave Click can detect movement or proximity by using the Doppler effect. The on-board microwave motions sensor transmits waves, and picks them back as they hit an object, with their frequency changed. For more information on the Click, please visit the Microwave Click webpage.
Basically, a motion can be detected by reading the analog signal coming from the Click. The frequency and amplitude will change when there is a motion:
A software-based solution has been introduced on the previous Click webpage. The topology is shown below: A calibration is needed at first to take dozens of samples when there is no motion, and average them to get a reference value. After the calibration is done, only the samples that are larger (you can also take smaller) than the reference will be saved. Then, take the average of a fixed amount of saved samples and compare it to a threshold. If the averaged result is bigger than the threshold, it is considered to be a motion.
Here is a typical software-based implementation when using a microcontroller without ADCC and other core-independent peripherals: To achieve all the tasks listed for the MCU, a basic ADC is only used to sample all the data, and the CPU is having a code-heavy routine in the main loop to process the data. Note the little clocks in the above diagram. It indicates that those routines in software are consuming most of the time. For example, a divide operation is going to take a lot of time for a MCU without a hardware divider.
Thanks to the ADCC with its powerful computation feature, a lot of the tasks can be done within the peripheral. Moreover, with a combination of ADCC, Timer2, Comparator, and DAC, most of the motion detection algorithm can be achieved in hardware: Note that with this implementation, the only task that the CPU needs to do is to issue the motion alert once there is an ADCC threshold interrupt.
The procedure to make this work is not as complex as it looks. In general, the ADCC is triggered by Timer2 to convert the samples, and its averaging with threshold comparison feature is going to take care of the computation tasks. The Hardware Limit Timer feature of Timer2 allows it to set the Comparator as an External Trigger Source, so it runs when Comparator's output is high. The combination of Comparator and DAC can output a high value when the waveform is higher than the reference value. Therefore, only when the waveform is higher than the reference value, Timer2 will start running, which triggers the ADCC conversion. With this setup, the ADCC converts sample automatically when the waveform is higher than the reference, and does the averaging and thresholding within the peripheral.
This example uses the PIC16F18446 Xpress Board as the main control board, and the Microwave Click as the sensing unit. The circuit can be easily set up by plugging the two boards and three wires on a breadboard.
Plug both the PIC16F18446 Xpress Board and the Noise Click into a breadboard.
Use a wire to connect ground, with the Ground symbol pins on both boards.
Use another wire to connect Vdd. Connect "3V3" pin on the Click to the pin just above RA5 on the Xpress Board (you can see it as VTG on the back of the board). Please note that according to the specifications of the Microwave Click, a 5V power supply is recommended. The PIC16F18446 is capable of running at a 5V Vdd. I used the 3.3V just because it's coming straight to the board, so I don't need an extra power supply.
Use a third wire to connect your AN pin on the Xpress Board (in my case, RA1) to the "OUT" pin on the Click.
In order to achieve the functionalities of all the peripherals above. MPLAB Code Configurator (MCC) is used to configure them.
Open MCC by clicking on the MCC symbol on top left of the IDE panel.
In "Device Resource", add ADCC to the project by double-clicking on it. We are using the Average Mode of the ADCC with a threshold triggering interrupt. So enable the ADCC Threshold interrupt by checking the corresponding boxes. Expand "Computation Feature", select "Filtered result vs setpoint" as the Error Calculation, and leave the Setpoint blank since we are going to set it in run-time. Select "ADERR > ADUTH" as the Threshold Interrupt, so that the threshold interrupt is triggered whenever the ADC result is above the upper threshold. You can set your Upper Threshold in the "Upper Threshold" box, or leave it blank for now and set it up later in your code. We are going to use a hardware timer to trigger the ADCC auto-conversion, so that no software routine are needed to do the ADC conversion. Under the "Auto-conversion Trigger" Tab, select a timer, such as Timer 2, to be the triggering source.
Add Timer 2 to the project, as we are using it as the ADCC auto-conversion triggering source. We want the conversion to be triggered every 5ms. Select "Fosc/4" or "LFINTOSC" as the Clock Source, then set up the Prescaler or Postscaler to make sure that 200ms is within the Timer Period range. Type in "5ms" in the Timer Period Box. Select the Comparator as the External Reset Source and select the Timer2 to be running when the External Reset Source is high, so that if the Comparator is triggered high, Timer 2 starts running.
Add Comparator to the project. Configure the Comparator to have the right output for TMR2 to be triggered. Since the DAC can only be the positive reference of the Comparator, we need to invert the output of the Comparator so that it will output a high when the waveform level is higher than the reference.
Add DAC to be the positive reference of the Comparator. The reference value should be fed into DAC after the Calibration.
Add EUSART peripheral to the project, since we are using the UART communication to send data to the computer terminal. Enable Transmit, and enable "Redirect STDIO to USART", to be able to use "printf" statement.
By checking the schematic of the Xpress Board, we know that RB6 and RB4 are the UART RX and TX pins. In "Pin Manager", set the RX and TX pin, and an AN pin as the ADCC input channel that connects to the Microwave Click AN pin (i.e., RA1). Then go to the Pin Module under System Tab, and customize the name of your AN input pin (i.e. Microwave_AN).
Everything should be set up. Generate Project.
Open a terminal on your computer by using terminals like TeraTerm, and connect the corresponding COM port of the Xpress Board. Note the settings of the serial port should be the same as the settings of the UART in MCC.
As a result, you will see the noise level displaying on the terminal window, and an alert appearing whenever the motion level is above the threshold you set. And the LED on the Xpress Board should be turned on. Press the button on the Xpress board to re-calibrate the reference.
MPLAB Xpress IDE shall mean the online integrated development environment (hereinafter “MPLAB Xpress”) operated by or on behalf of Microchip Technology Incorporated (hereinafter "Microchip") for your use, whether as a guest or a registered user. Microchip is a Delaware corporation with its principal office at 2355 W. Chandler Boulevard, Chandler, AZ 85224.
Access to MPLAB Xpress is permitted on a temporary basis, and Microchip reserves the right to withdraw or amend the information provided on MPLAB Xpress without notice. Microchip will not be liable if for any reason MPLAB Xpress is unavailable at any time or for any period. From time to time, Microchip may restrict access to some or all of MPLAB Xpress.
Material on MPLAB Xpress may be out of date or include omissions, inaccuracies or other errors at any given time, and Microchip is under no obligation to update such material. Commentary and other materials posted on MPLAB Xpress are not intended to amount to advice on which reliance should be placed. Microchip disclaims all liability and responsibility arising from any reliance placed on such materials by any user of MPLAB Xpress, or by anyone who may be informed of any of its contents. Microchip owns or has the rights to the materials and information it posts on MPBLAB Xpress, but does not and cannot warrant or guaranty any information or materials posted by others.
EXCEPT WHERE EXPRESSLY PROVIDED OTHERWISE IN AN AGREEMENT BETWEEN YOU AND MICROCHIP, ALL INFORMATION PROVIDED DIRECTLY ON MPLAB XPRESS OR INDIRECTLY THROUGH MPLAB XPRESS BY HYPERTEXT LINK OR OTHERWISE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROCHIP HEREBY DISCLAIMS ALL WARRANTIES WITH RESPECT TO THIS INFORMATION, WHETHER EXPRESS OR IMPLIED, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROCHIP BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES, OR DAMAGES FOR LOSS OF PROFITS, REVENUE, DATA OR USE, INCURRED BY YOU OR ANY THIRD PARTY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM YOUR ACCESS TO, USE OF, OR RELIANCE UPON INFORMATION OBTAINED FROM OR THROUGH MPLAB XPRESS. MICROCHIP RESERVES THE RIGHT TO MAKE CHANGES, UPDATES OR CORRECTIONS TO THE INFORMATION ON MPLAB XPRESS AT ANY TIME WITHOUT NOTICE.
Contracts for the supply of goods, services or information formed through the use of the MPLAB Xpress site or as a result of visits made by you to the MPLAB Xpress site are governed by these terms and conditions.
MPLAB Xpress may contain links to other sites and resources provided by third parties. Any such links are provided for your information only. Microchip has no control over the contents of those sites or resources, and accepts no responsibility for them or for any loss or damage that may arise from your use of them.
How is Customer Information Obtained by Microchip and How is it Used?
We receive and store information you give us, anonymously. Most of the information you give us is collected when you buy products on-line, request literature/ information, participate in a contest, fill out a questionnaire/survey, participate in an on-line discussion, or complete your Customer Profile. You may give us information such as your name, address, phone numbers, e-mail addresses, financial information, employment information, application information, ideas for new projects or applications, and your buying interests. The information that you provide us is used to respond to your requests, notify you of products being shipped to you, customize your interactions with us, improve our offerings, provide materials or offers to you, allow you to participate in contests, and communicate with you. It is your choice whether or not to provide us with certain information. However, you may be unable to take advantage of many of our offers and features if we do not receive your customer information.
We also receive and store certain types of information through use of “cookies.” Some examples of information gathered this way are the Internet Protocol (IP) address used to connect your computer to the Internet, log-in, e-mail address, computer and connection information such as browser type and version, operating system, platform, and the full Uniform Resource Locator (URL) used to, through, and from access of MPLAB Xpress. We use the information gathered by “cookies” to manage and customize your on-line experience and to improve our services.
You may also submit technical information to Microchip such as designs, ideas or data, that you transmit to or post on MPLAB Xpress example section (a "Submission") for purposes not limited to community development participation. By posting a Submission, you understand that you give Microchip and the community a nonexclusive, royalty-free, perpetual, irrevocable, sublicensable right to disseminate, display, use, modify, copy, adapt, and translate the Submission for any purpose whatsoever, whether commercial or noncommercial, throughout the world in any media. The Submission is not confidential or proprietary. Providing the Submission, grants the right to use the name you submit in connection with your Submission. You represent and warrant in making the Submission that you own or control all rights to the Submission, and that use of your Submission will not cause injury to any person or entity, including Microchip. You will indemnify Microchip for all claims resulting from your Submission.
How can I manage the information Microchip has about me?
You can always choose not to give Microchip information. However, certain information is necessary in order for you to take advantage of MPLAB Xpress, any change notifications, literature, updates, etc.
If you want to add/update your information or preferences, please modify your MPLAB Xpress account profile. When you update your information, we may keep a copy of your earlier information for our records.
You can avoid certain "cookies" by indicating in your account profile that you do not want us to remember you. Your browser may also have options to prevent acceptance of new “cookies.” There are also utilities available allowing you to visit MPLAB Xpress anonymously. Unfortunately, certain features and offerings available through MPLAB XPress may not be available to anonymous users.
Who does Microchip share Customer Information With?
Customer information is important for Microchip to be able to offer products and services to you. We are not in the business of selling customer information to others. We do share customer information with our subsidiaries and with others as described below. Such third parties may be based in the United States, Europe or Thailand. We are not responsible for the privacy practices of third parties to whom your information may be transferred. If you do not wish us to share your information as described below, you may opt out by not supplying information to us when entering information into your account profile, or by not placing orders through MPLAB Xpress.
Agents: We use other companies and persons to perform tasks on our behalf. Examples are not limited to web hosting of MPLAB Xpress, delivering packages, processing credit card payments, checking for export compliance, and providing customer service. They have access to customer information to perform their jobs, but may not use it for other purposes. Microchip may share your customer information with third parties and receive information from credit bureaus and other companies to help prevent and detect fraud, and to offer credit or financial services to some customers. Microchip cannot guaranty the security of such agent services provided on its behalf. As such, Microchip makes no representations or warranties regarding any third party services and has no responsibility or liability whatsoever for any such third party services and is not responsible for the content or privacy practices of such third parties
Third Parties: Except for information transmitted to Microchip through the on-line support system at http://support.microchip.com, any other Submission to Microchip such as designs, ideas or data that you transmit to or post on MPLAB Xpress by any means for any purpose including but not limited to contest participation is considered and treated by Microchip as nonconfidential and nonproprietary.
Conformance with the Law: We release account and other customer information when we believe it is appropriate to comply with the laws of Arizona.
Protection of Microchip and Others: Microchip will release customer information necessary to enforce or apply our MPLAB Xpress IDE Terms and Conditions, and other agreements. Microchip will, at its discretion, release customer information necessary to protect the rights, property and safety of Microchip or others in accordance with the laws of Arizona.
We use 256-bit encryption to secure the financial information you enter. Only the last five digits of your credit card number are listed in your Order Acknowledgement. However, your entire credit card number is transmitted to your credit card company during order processing, and your identifying and credit information is transmitted to companies that process your credit card transactions and review them for export control violations.
Law and Jurisdiction
If you have any concern about our treatment of your customer information, please send us an e-mail at email@example.com.