Skip to content

Commit 31f6c7b

Browse files
Reduced SPI speed for Expander Pi
Reduce the speed of the SPI bus to improve ADC accuracy.
1 parent c0101d6 commit 31f6c7b

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

ExpanderPi/ABE_ExpanderPi.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ apt-get install libi2c-dev
3838
#define IOADDRESS 0x20
3939
#define IODIRA 0x00 // IO direction A - 1= input 0 = output
4040
#define IODIRB 0x01 // IO direction B - 1= input 0 = output
41-
#define IPOLA 0x02 // Input polarity A
41+
#define IPOLA 0x02 // Input polarity A
4242
#define IPOLB 0x03 // Input polarity B
4343
#define GPINTENA 0x04 // The GPINTEN register controls the interrupt-onchange feature for each pin on port A.
4444
#define GPINTENB 0x05 // The GPINTEN register controls the interrupt-onchange feature for each pin on port B.
@@ -80,7 +80,7 @@ using namespace ABElectronics_CPP_Libraries;
8080
ExpanderPi::ExpanderPi(){
8181
// SPI Bus Variables
8282
mode = SPI_MODE_0; // SPI_MODE_0
83-
speed = 2500000; // SPI bus speed
83+
speed = 200000; // SPI bus speed
8484

8585
// ADC Variables
8686

@@ -174,11 +174,11 @@ int ExpanderPi::adc_read_raw(int channel, int mode) {
174174
struct spi_ioc_transfer spi;
175175
memset(&spi,0,sizeof(spi));
176176

177-
spi.tx_buf = (unsigned long)adctx;
177+
spi.tx_buf = (unsigned long)adctx;
178178
spi.rx_buf = (unsigned long)adcrx;
179179
spi.len = 3;
180180
spi.speed_hz = 1800000; // 1.8MHz Clock Speed
181-
spi.delay_usecs = 0;
181+
spi.delay_usecs = 0;
182182
spi.bits_per_word = 8;
183183

184184

@@ -254,7 +254,7 @@ void ExpanderPi::dac_set_raw(uint16_t raw, int channel, int gain) {
254254
tr.rx_buf = (unsigned long)NULL;
255255
tr.len = 2;
256256
tr.speed_hz = 20000000; // 20MHz clock speed
257-
tr.delay_usecs = 0;
257+
tr.delay_usecs = 0;
258258
tr.bits_per_word = 8;
259259
tr.cs_change = 0;
260260

@@ -277,7 +277,7 @@ void ExpanderPi::dac_set_voltage(double voltage, int channel, int gain) {
277277
if (gain == 2) {
278278
dacvoltage = 4.096;
279279
}
280-
280+
281281
if ((voltage >= 0.0) && (voltage < dacvoltage)) {
282282
uint16_t rawval = ((voltage / 2.048) * 4096) / gain;
283283
dac_set_raw(rawval, channel, gain);
@@ -850,7 +850,7 @@ unsigned char *ExpanderPi::rtc_read_memory(unsigned char address, int length) {
850850
else {
851851
throw std::out_of_range("address out of range");
852852
return NULL;
853-
}
853+
}
854854
}
855855

856856
/*===================RTC Methods End ===================*/

0 commit comments

Comments
 (0)