Bu Malzeme, SPI arayüzüyle (ben Hardware kullanmadım) çalışan 10-50-100k ohmluk çeşitleri olan verdiğiniz değere göre potansiyometre direnç değerini değiştiren bir IC.
Paket içerisinde iki adet Potansiyometre olanı (14pin) ve tek potansiyometre barındıranı mevcut. (8pin)
Çalışması oldukça basit CE yi 0 a çek, CLK ile birlikte 16 bitlik bilgiyi gönder. Bu 16 bit in ilk 8 bit i konfig. Açıklaması aşağıda.
1 2 3 4 5 6 7 8 9 10 11 |
/** Kontrol Byte ----------------------------------------------------------------- | x | x | C1 | C0 | | x | x | P0 | P1 | ----------------------------------------------------------------- | x | x | 0 | 0 |None | x | x | 0 | 0 |Dummy Code | x | x | 0 | 1 |Write Data | x | x | 0 | 1 |Potentiometer 0. | x | x | 1 | 0 |Shutdown | x | x | 1 | 0 |Potentiometer 1. | x | x | 1 | 1 |None | x | x | 1 | 1 |both ----------------------------------------------------------------- */ |
son 8 bit potansiyometrenin alacağı değer. Ben 100K lık olan ı kullandım her adım (100k /256) 390ohm civarlarına geliyor (tabik tam oturmuyor)
Ben stm 32f103 kullandım, ama heryerde kullanabilirsiniz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
/* ** ** Main.c ** ** **********************************************************************/ /* Last committed: $Revision: 00 $ Last changed by: $Author: $ Last changed date: $Date: $ ID: $Id: $ **********************************************************************/ #include "stm32f10x_conf.h" #define SCL GPIO_Pin_7 #define SIO GPIO_Pin_5 #define CS GPIO_Pin_8 #define PORT GPIOA #define RCC_PORT RCC_APB2Periph_GPIOA #define KontrolByte 0x11 /** Kontrol Byte (gönderilen ilk 8 bit) ----------------------------------------------------------------- | x | x | C1 | C0 | | x | x | P0 | P1 | ----------------------------------------------------------------- | x | x | 0 | 0 |None | x | x | 0 | 0 |Dummy Code | x | x | 0 | 1 |Write Data | x | x | 0 | 1 |Potentiometer 0. | x | x | 1 | 0 |Shutdown | x | x | 1 | 0 |Potentiometer 1. | x | x | 1 | 1 |None | x | x | 1 | 1 |both ----------------------------------------------------------------- */ void resistorSet(uint8_t Value){ uint8_t i=0; uint16_t ResValue=(KontrolByte<<8) | Value; GPIO_ResetBits(PORT,CS); for(i=0; i<16; i++) { GPIO_ResetBits(PORT,SCL); if((ResValue<<i)&(0x8000)) { GPIO_SetBits(PORT,SIO); } else { GPIO_ResetBits(PORT,SIO); } GPIO_SetBits(PORT,SCL); } GPIO_ResetBits(PORT,SCL); GPIO_ResetBits(PORT,SIO); GPIO_SetBits(PORT,CS); } static void init_GPIO(void) { RCC_APB2PeriphClockCmd(RCC_PORT, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = SCL | SIO | CS;//SCLK SIO CS GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(PORT, &GPIO_InitStructure); } int main(void) { init_GPIO(); resistorSet(0x01); while(1) { } } |
For example , if we write 222 to MCP41100 ,The resistance will equal :
Rwa= (100*10^3)*(256-222)/256 – 125 = 13.41K ohm .
datasheet için http://ww1.microchip.com/downloads/en/DeviceDoc/11195c.pdf