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

Return to SDK Examples for Microchip Studio

1/*
2 * Title: ClearCoreStatusRegister
3 *
4 * Objective:
5 * This example demonstrates how to read and display bits in the ClearCore
6 * Status Register.
7 *
8 * Description:
9 * This example gets a snapshot of the ClearCore's real-time status register
10 * and prints the state of the status register bits to the USB serial port.
11 *
12 * Requirements:
13 * ** None
14 *
15 * Links:
16 * ** ClearCore Documentation: https://teknic-inc.github.io/ClearCore-library/
17 * ** ClearCore Manual: https://www.teknic.com/files/downloads/clearcore_user_manual.pdf
18 *
19 *
20 * Copyright (c) 2020 Teknic Inc. This work is free to use, copy and distribute under the terms of
21 * the standard MIT permissive software license which can be found at https://opensource.org/licenses/MIT
22 */
23
24#include "ClearCore.h"
25
26// Select the baud rate to match the target serial device
27#define baudRate 9600
28
29// Specify which serial to use: ConnectorUsb, ConnectorCOM0, or ConnectorCOM1.
30#define SerialPort ConnectorUsb
31
32int main() {
33 // Set up serial communication at a baud rate of 9600 bps then wait up to
34 // 5 seconds for a port to open.
35 // Serial communication is not required for this example to run, however the
36 // example will appear to do nothing without serial output.
37 SerialPort.Mode(Connector::USB_CDC);
38 SerialPort.Speed(baudRate);
39 uint32_t timeout = 5000;
40 uint32_t startTime = Milliseconds();
41 SerialPort.PortOpen();
42 while (!SerialPort && Milliseconds() - startTime < timeout) {
43 continue;
44 }
45
46 while (true) {
47 // Get a copy of the real-time status register.
48 StatusManager::StatusRegister statusReg = StatusMgr.StatusRT();
49
50 SerialPort.SendLine("Status Register:");
51
52 SerialPort.Send("Vsupply over-voltage:\t\t");
53 if (statusReg.bit.VSupplyOverVoltage) {
54 SerialPort.SendLine('1');
55 }
56 else {
57 SerialPort.SendLine('0');
58 }
59
60 SerialPort.Send("Vsupply under-voltage:\t\t");
61 if (statusReg.bit.VSupplyUnderVoltage) {
62 SerialPort.SendLine('1');
63 }
64 else {
65 SerialPort.SendLine('0');
66 }
67
68 SerialPort.Send("H-Bridge output overloaded:\t");
69 if (statusReg.bit.HBridgeOverloaded) {
70 SerialPort.SendLine('1');
71 }
72 else {
73 SerialPort.SendLine('0');
74 }
75
76 SerialPort.Send("H-Bridge resetting:\t\t");
77 if (statusReg.bit.HBridgeReset) {
78 SerialPort.SendLine('1');
79 }
80 else {
81 SerialPort.SendLine('0');
82 }
83
84 // This status bit denotes the state of the 5 volt supply for off-board
85 // items
86 SerialPort.Send("Offboard 5V overloaded:\t\t");
87 if (statusReg.bit.Overloaded5V) {
88 SerialPort.SendLine('1');
89 }
90 else {
91 SerialPort.SendLine('0');
92 }
93
94 SerialPort.Send("Output overloaded:\t\t");
95 if (statusReg.bit.OutputOverloaded) {
96 SerialPort.SendLine('1');
97 }
98 else {
99 SerialPort.SendLine('0');
100 }
101
102 SerialPort.Send("CCIO-8 output overloaded:\t");
103 if (statusReg.bit.CcioOverloaded) {
104 SerialPort.SendLine('1');
105 }
106 else {
107 SerialPort.SendLine('0');
108 }
109
110 SerialPort.Send("CCIO-8 link broken:\t\t");
111 if (statusReg.bit.CcioLinkBroken) {
112 SerialPort.SendLine('1');
113 }
114 else {
115 SerialPort.SendLine('0');
116 }
117
118 SerialPort.Send("ADC in timeout:\t\t\t");
119 if (statusReg.bit.AdcTimeout) {
120 SerialPort.SendLine('1');
121 }
122 else {
123 SerialPort.SendLine('0');
124 }
125
126 SerialPort.Send("Ethernet disconnect:\t\t");
127 if (statusReg.bit.EthernetDisconnect) {
128 SerialPort.SendLine('1');
129 }
130 else {
131 SerialPort.SendLine('0');
132 }
133
134 SerialPort.Send("Ethernet remote fault:\t\t");
135 if (statusReg.bit.EthernetRemoteFault) {
136 SerialPort.SendLine('1');
137 }
138 else {
139 SerialPort.SendLine('0');
140 }
141
142 SerialPort.Send("SD card error:\t\t\t");
143 if (statusReg.bit.SdCardError) {
144 SerialPort.SendLine('1');
145 }
146 else {
147 SerialPort.SendLine('0');
148 }
149
150 SerialPort.SendLine("------------------------");
151
152 // Wait a couple seconds then repeat...
153 Delay_ms(2000);
154 }
155}
void Delay_ms(uint32_t ms)
Blocks operations for ms milliseconds.
Definition SysTiming.h:287
uint32_t Milliseconds(void)
Number of milliseconds since the ClearCore was initialized.
StatusRegister StatusRT(StatusRegister mask=UINT32_MAX)
The real time status register.