Skip to content
Snippets Groups Projects
Commit c86d22d6 authored by Michael DM Dryden's avatar Michael DM Dryden
Browse files

Prevent going out of bounds with DAC offset.

parent e59f8cbe
Branches
Tags
No related merge requests found
......@@ -7,7 +7,7 @@
#include <max5443.h>
volatile uint16_t max5443_offset = 105;
volatile int16_t max5443_offset = 105;
struct usart_spi_device spi_device_conf_c = {
.id = IOPORT_CREATE_PIN(PORTC, 4)
......@@ -31,8 +31,13 @@ void max5443_set_voltage1(uint16_t dacindex){
// if (buffer.ui16 == dacindex)
// return;
buffer.ui16 = dacindex+max5443_offset;
if (65535-dacindex < max5443_offset)
buffer.ui16 = 65535;
else if (dacindex < -1*max5443_offset)
buffer.ui16 = 0;
else
buffer.ui16 = dacindex+max5443_offset;
irqflags_t flags;
flags = cpu_irq_save();
......
No preview for this file type
This diff is collapsed.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment