# Power

## Power Registers:

Several functions are available to monitor various status of the rover.

.

**PIC\_ReadPower();**\
`PIC_ReadPower(); //gets voltage and power values from PIC processor`  \
`powerVoltage //global variable, now holds battery voltage (in millivolts)`  \
`powerCurrent //global variable, now holds total current consumption (in milliamps)`

This function reads the key power values - battery voltage, and current consumption. This reading is accurate to within 20 milliseconds (the value returned is the last reading taken during the last 20ms cycle). The function automatically populates two global variables `powerVoltage` and `powerCurrent`. These variables can be used anywhere in your code. Each time this function is called, the variables are updated.

.

**PIC\_ReadPower\_Instant();**\
`PIC_ReadPower_Instant(); //gets instant voltage and power values from PIC processor`  \
`powerVoltage //global variable, now holds battery voltage (in millivolts)`  \
`powerCurrent //global variable, now holds total current consumption (in milliamps)`

This function works the same as the normal `PIC_ReadPower`, except the resulting values are instant, and do not include the 20 millisecond delay. When this function is run, the PIC processor will pause for a brief time to perform an instant reading of the power values and replies back with the values. It is suggested to generally use the normal `PIC_ReadPower` function, though you can use this function if a more instant reading is required.

.

**PIC\_ReadPowerAverages();**\
`PIC_ReadPowerAverages(); //gets average voltage and power values from PIC processor`  \
`powerVoltageAverage //global variable, now holds average battery voltage (in millivolts)`  \
`powerCurrentAverage //global variable, now holds average total current consumption (in milliamps)`

This function returns the average readings of battery voltage and current consumption. This is a running average from the previous 8 times the PIC processor performed its 20 millisecond interval measurement. You will find this value is more stable over time than the other readings above as the average tends to filter out spikes.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://plumgeek.gitbook.io/spirit-rover-code-quick-reference/arduino-code/power.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
