ClearCore Library
Loading...
Searching...
No Matches
WriteAnalogCurrentOutput.cpp

Return to SDK Examples for Microchip Studio

1/*
2 * Title: WriteAnalogCurrentOutput
3 *
4 * Objective:
5 * This example demonstrates how to write analog current values to an analog
6 * current output connector.
7 *
8 * Description:
9 * This example configures pin IO-0 as an analog current output. It outputs
10 * a repeating analog signal, starting at 0mA, increasing to 20mA, and
11 * decreasing back to 0mA.
12 *
13 * Requirements:
14 * ** Connect a device to IO-0 which takes in analog current.
15 *
16 * Links:
17 * ** ClearCore Documentation: https://teknic-inc.github.io/ClearCore-library/
18 * ** ClearCore Manual: https://www.teknic.com/files/downloads/clearcore_user_manual.pdf
19 *
20 *
21 * Copyright (c) 2020 Teknic Inc. This work is free to use, copy and distribute under the terms of
22 * the standard MIT permissive software license which can be found at https://opensource.org/licenses/MIT
23 */
24
25#include "ClearCore.h"
26
27
28int main() {
29 // Set up connector IO-0 in analog output mode.
30 // Note that only connector IO-0 is capable of analog current output.
31 ConnectorIO0.Mode(Connector::OUTPUT_ANALOG);
32
33 while (true) {
34 // Ramp the current output of IO-0 up to 20 mA (20,000 uA). If using an
35 // operating range of 4-20 mA, change the lower bounds of the loops
36 // below to 4000 instead of 0.
37 for (uint16_t microAmps = 0; microAmps < 20000; microAmps += 10) {
38 ConnectorIO0.OutputCurrent(microAmps);
39 Delay_ms(2);
40 }
41
42 // Ramp the current output of IO-0 back down.
43 for (uint16_t microAmps = 20000; microAmps > 0; microAmps -= 10) {
44 ConnectorIO0.OutputCurrent(microAmps);
45 Delay_ms(2);
46 }
47 }
48}
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287
void OutputCurrent(uint16_t currentuA)
Command the DAC to output the given number of microamps (uA).
virtual ConnectorModes Mode() override
Get the connector's operational mode.
Definition DigitalInOutAnalogOut.h:70