Preliminary mbed encoder interface IC class
Diff: LS7366.cpp
- Revision:
- 3:6063c8171873
- Parent:
- 2:2193b220248b
diff -r 2193b220248b -r 6063c8171873 LS7366.cpp --- a/LS7366.cpp Wed Oct 07 17:31:26 2015 +0000 +++ b/LS7366.cpp Tue Mar 24 05:03:07 2020 +0000 @@ -27,7 +27,7 @@ //Constructor LS7366::LS7366(SPI& spi, PinName cs) : _spi(spi), _cs(cs) { - this->_cs = 1; // Initialize chip select as off (high) + this->_cs = 0; // Initialize chip select as off (high) this->_init(); } @@ -50,13 +50,13 @@ this->_spi.format(8, 0); this->_spi.frequency(2000000); - this->_cs = 0; + this->_cs = 1; wait_us(1); this->LS7366_cmd(LOAD,OTR);//cmd = 0xe8, LOAD to OTR - this->_cs = 1; + this->_cs = 0; wait_us(1); - this->_cs = 0; + this->_cs = 1; wait_us(1); this->LS7366_cmd(RD,CNTR); //cmd = 0x60, READ from CNTR @@ -65,7 +65,7 @@ counter.byte_enc[1] = this->_spi.write(0x00); counter.byte_enc[0] = this->_spi.write(0x00); - this->_cs = 1; + this->_cs = 0; this->count = counter.long_enc; return counter.long_enc; //return count @@ -76,13 +76,13 @@ this->_spi.format(8, 0); this->_spi.frequency(2000000); - this->_cs = 0; + this->_cs = 1; wait_us(1); this->LS7366_cmd(WR,MDR0);// Write to the MDR0 register this->_spi.write(0x03); // X4 quadrature count mode - this->_cs = 1; + this->_cs = 0; } void LS7366::LS7366_reset_counter(){ @@ -90,21 +90,21 @@ this->_spi.format(8, 0); this->_spi.frequency(2000000); - this->_cs = 0; + this->_cs = 1; wait_us(1); this->LS7366_cmd(CLR,CNTR);//Clear the counter register - this->_cs = 1; + this->_cs = 0; wait_us(1); - this->_cs = 0; + this->_cs = 1; wait_us(1); this->LS7366_cmd(LOAD,CNTR);// - this->_cs = 1; + this->_cs = 0; } void LS7366::LS7366_write_DTR(long enc_value) @@ -120,7 +120,7 @@ counter.long_enc = enc_value; - this->_cs = 0; + this->_cs = 1; wait_us(1); this->LS7366_cmd(WR,DTR);// @@ -129,16 +129,16 @@ this->_spi.write(counter.byte_enc[1]); this->_spi.write(counter.byte_enc[0]); - this->_cs = 1; + this->_cs = 0; wait_us(1); - this->_cs = 0; + this->_cs = 1; wait_us(1); this->LS7366_cmd(LOAD,CNTR);// - this->_cs = 1; + this->_cs = 0; } void LS7366::_init(){