Fork of Smoothie to port to mbed non-LPC targets.
Fork of Smoothie by
ad5206.h
00001 #ifndef AD5206_H 00002 #define AD5206_H 00003 00004 #include "libs/Kernel.h" 00005 #include "libs/utils.h" 00006 #include <libs/Pin.h> 00007 #include "mbed.h" 00008 #include <string> 00009 #include <math.h> 00010 00011 #define max(a,b) (((a) > (b)) ? (a) : (b)) 00012 00013 class AD5206 : public DigipotBase { 00014 public: 00015 AD5206(){ 00016 this->spi= new mbed::SPI(P0_9,P0_8,P0_7); //should be able to set those pins in config 00017 cs.from_string("4.29")->as_output(); //this also should be configurable 00018 cs.set(1); 00019 } 00020 00021 void set_current( int channel, float current ) 00022 { 00023 if(channel<6){ 00024 current = min( max( current, 0.0L ), 2.0L ); 00025 char adresses[6] = { 0x05, 0x03, 0x01, 0x00, 0x02, 0x04 }; 00026 currents[channel] = current; 00027 cs.set(0); 00028 spi->write((int)adresses[channel]); 00029 spi->write((int)current_to_wiper(current)); 00030 cs.set(1); 00031 } 00032 } 00033 00034 00035 //taken from 4pi firmware 00036 unsigned char current_to_wiper( float current ){ 00037 unsigned int count = int((current*1000)*100/743); //6.8k resistor and 10k pot 00038 00039 return (unsigned char)count; 00040 } 00041 00042 float get_current(int channel) 00043 { 00044 return currents[channel]; 00045 } 00046 00047 private: 00048 00049 Pin cs; 00050 mbed::SPI* spi; 00051 float currents[6]; 00052 }; 00053 00054 00055 #endif
Generated on Tue Jul 12 2022 20:09:00 by 1.7.2