Preliminary mbed encoder interface IC class

Dependents:   mbed_QUAD_ENCLIB_TEST Axis Axis_20181108 Axis_version2

include the mbed library with this snippet

#include "mbed.h"
#include "LS7366.h"

SPI spi(p5, p6, p7);   
LS7366 enc1(spi, p19);
LS7366 enc2(spi, p20);
Serial pc(USBTX, USBRX); // tx, rx for serial USB interface to pc

//------------------- MAIN --------------------------------
int main()
{    
    while(1){ 
        pc.printf("enc1 = %ld enc2 = %ld\r\n",enc1.read(), enc2.read());
        wait(.02);
    }//while(1)                        
}//main

Files at this revision

API Documentation at this revision

Comitter:
jebradshaw
Date:
Wed Oct 07 17:31:26 2015 +0000
Parent:
1:c627734cf04c
Commit message:
added this-> to most local variables/methods to avoid ambiguity

Changed in this revision

LS7366.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c627734cf04c -r 2193b220248b LS7366.cpp
--- a/LS7366.cpp	Mon Aug 31 17:13:34 2015 +0000
+++ b/LS7366.cpp	Wed Oct 07 17:31:26 2015 +0000
@@ -27,18 +27,18 @@
 
 //Constructor
 LS7366::LS7366(SPI& spi, PinName cs) : _spi(spi), _cs(cs) {
-    _cs = 1;           // Initialize chip select as off (high)
-    _init();
+    this->_cs = 1;           // Initialize chip select as off (high)
+    this->_init();
 }
 
 void LS7366::LS7366_cmd(int inst, int reg){
     char cmd;
     
-    _spi.format(8, 0);
-    _spi.frequency(2000000);
+    this->_spi.format(8, 0);
+    this->_spi.frequency(2000000);
     cmd = (inst << 6) | (reg << 3);
 //    printf("\r\ncmd=0X%2X", cmd);
-    _spi.write(cmd);
+    this->_spi.write(cmd);
 }
 
 long LS7366::LS7366_read_counter(){
@@ -47,64 +47,64 @@
         long long_enc;
     }counter;
     
-    _spi.format(8, 0);
-    _spi.frequency(2000000);
+    this->_spi.format(8, 0);
+    this->_spi.frequency(2000000);
 
-    _cs = 0;    
+    this->_cs = 0;    
     wait_us(1);
-    LS7366_cmd(LOAD,OTR);//cmd = 0xe8, LOAD to OTR
-    _cs = 1;
+    this->LS7366_cmd(LOAD,OTR);//cmd = 0xe8, LOAD to OTR
+    this->_cs = 1;
     wait_us(1);
     
-    _cs = 0;        
+    this->_cs = 0;        
 
     wait_us(1);
-    LS7366_cmd(RD,CNTR);  //cmd = 0x60, READ from CNTR
-    counter.byte_enc[3] = _spi.write(0x00);
-    counter.byte_enc[2] = _spi.write(0x00);
-    counter.byte_enc[1] = _spi.write(0x00);
-    counter.byte_enc[0] = _spi.write(0x00);
+    this->LS7366_cmd(RD,CNTR);  //cmd = 0x60, READ from CNTR
+    counter.byte_enc[3] = this->_spi.write(0x00);
+    counter.byte_enc[2] = this->_spi.write(0x00);
+    counter.byte_enc[1] = this->_spi.write(0x00);
+    counter.byte_enc[0] = this->_spi.write(0x00);
 
-    _cs = 1;    
+    this->_cs = 1;    
     
-    count = counter.long_enc;  
+    this->count = counter.long_enc;  
     return counter.long_enc;  //return count
 }
 
 void LS7366::LS7366_quad_mode_x4(){
     
-    _spi.format(8, 0);
-    _spi.frequency(2000000);
+    this->_spi.format(8, 0);
+    this->_spi.frequency(2000000);
     
-    _cs = 0;    
+    this->_cs = 0;    
    
     wait_us(1);
-    LS7366_cmd(WR,MDR0);// Write to the MDR0 register
-    _spi.write(0x03); // X4 quadrature count mode
+    this->LS7366_cmd(WR,MDR0);// Write to the MDR0 register
+    this->_spi.write(0x03); // X4 quadrature count mode
 
-    _cs = 1;    
+    this->_cs = 1;    
 }
 
 void LS7366::LS7366_reset_counter(){
     
-    _spi.format(8, 0);
-    _spi.frequency(2000000);
+    this->_spi.format(8, 0);
+    this->_spi.frequency(2000000);
     
-    _cs = 0;    
+    this->_cs = 0;    
    
     wait_us(1);
-    LS7366_cmd(CLR,CNTR);//Clear the counter register
+    this->LS7366_cmd(CLR,CNTR);//Clear the counter register
 
-    _cs = 1;    
+    this->_cs = 1;    
 
     wait_us(1);
     
-    _cs = 0;    
+    this->_cs = 0;    
             
     wait_us(1);
-    LS7366_cmd(LOAD,CNTR);//
+    this->LS7366_cmd(LOAD,CNTR);//
 
-    _cs = 1;    
+    this->_cs = 1;    
 }
 
 void LS7366::LS7366_write_DTR(long enc_value)
@@ -115,53 +115,53 @@
         long long_enc;
     }counter;
     
-    _spi.format(8, 0);
-    _spi.frequency(2000000);
+    this->_spi.format(8, 0);
+    this->_spi.frequency(2000000);
     
     counter.long_enc = enc_value;
     
-    _cs = 0;    
+    this->_cs = 0;    
    
     wait_us(1);
-    LS7366_cmd(WR,DTR);//
-    _spi.write(counter.byte_enc[3]);
-    _spi.write(counter.byte_enc[2]);
-    _spi.write(counter.byte_enc[1]);
-    _spi.write(counter.byte_enc[0]);
+    this->LS7366_cmd(WR,DTR);//
+    this->_spi.write(counter.byte_enc[3]);
+    this->_spi.write(counter.byte_enc[2]);
+    this->_spi.write(counter.byte_enc[1]);
+    this->_spi.write(counter.byte_enc[0]);
 
-    _cs = 1;         
+   this->_cs = 1;         
     
     wait_us(1);
 
-    _cs = 0;    
+    this->_cs = 0;    
 
     wait_us(1);
-    LS7366_cmd(LOAD,CNTR);//
+    this->LS7366_cmd(LOAD,CNTR);//
 
-    _cs = 1;    
+    this->_cs = 1;    
 }
 
 void LS7366::_init(){
-    _spi.frequency(2000000);
-    LS7366_reset_counter();
-    LS7366_quad_mode_x4();       
-    LS7366_write_DTR(0);    
+    this->_spi.frequency(2000000);
+    this->LS7366_reset_counter();
+    this->LS7366_quad_mode_x4();       
+    this->LS7366_write_DTR(0);    
 }
 
 void LS7366::write(long wcount){
-    LS7366_write_DTR(wcount);    
+    this->LS7366_write_DTR(wcount);    
 }
 
 long LS7366::read(){
-    return LS7366_read_counter();    
+    return this->LS7366_read_counter();    
 }
 
 LS7366& LS7366::operator= (long wcount) { 
-    write(wcount);
+    this->write(wcount);
     return *this;
 }
  
 
 LS7366::operator long() {
-    return read();    
+    return this->read();    
 }
\ No newline at end of file