MCP4921 12Bit Dijital Analog Çevirici

Başlatan westcoast, 21 Temmuz 2006, 20:11:05

westcoast

Merhaba Arkadaşlar
Elimde Microchip firmasının MCP4921 12bit Dijital analog çevirici entegresi var.
Ben bunu bir devrede kullanıcam ve çıkış voltajınıda pic ile kontrol edicem.
Proton kullanıyorum.Buraya kadar sorun yok.
Fakat SPI ile ilgili bilgim yok.
Data sheet'tede herhangi bir örnek koda rastlamadım.
Data Sheet



Aramızda bununla ilgili bir çalışma yapmış arkadaş var mı acaba?
SPI ile ilgili türkçe kaynak nereden bulurum? (ingilizcem yok)
Protonda hangi komut benim işime daha çok yarar?

picusta

void SPI_write (char chip, char channel, unsigned int val){

unsigned int maskData = 0x8000; // D'abord le bit de poids fort.
unsigned int decalage = 0x4000; // Fast speed , normal power

if (channel==DACCHA) {
	decalage += 0x8000;
}
if (val>4095) val = 4095; // Saturation max.

decalage += val; // Fusion des bits de données dans la trame

//Début de la transmission avec le chip select et clock =1
spi_clk = 1;

if (chip==DAC1) {
	spi_cs1=0;
	spi_cs2=1;
}
else {
	spi_cs1=1;
	spi_cs2=0;	
}
asm("nop"); /* wait *1 */




while (maskData) { /* 16 times as loop */
	spi_clk = 1; //Front montant
	if (decalage & maskData) { /* "H" output ? */
		spi_dout = 1; /* Yes SDA="H" */
	}else{
		spi_dout = 0; /* No SDA="L" */
	}
	spi_clk = 0; // Front descendant du clock
	
	maskData >>= 1; /* change mask data */
}
//Fin
spi_clk = 1; //Front montant
spi_clk = 0; // Front descendant du clock
// Désélection des circuits
spi_cs1=1;
spi_cs2=1;	
}

Iste sana 12 bit DAC tlv5618 için yazilmis kod.
SPI en kolay seri iletisim diyebiliriz, bit bit gönderiyosun, her bit arasi clock pinini degistiriyosun. önce kontrol bitleri (güç tasarufu, hangi çikis vs..), sonra veri bitleri gönderiliyor.  Hersey datasheet'e açikça yaziyor, hatta okumaya gerek kalmadan semalardan anlasiliyor.
Elektronikle ilgilenip ingilizce bilmemek (en azindan teknik terimleri) kabul edilir değil.

westcoast

Hocam ilgin için teşekkür ederim.
Ben proton ile yazıyorum c bilmediğimden protonda spi için özel bir komut var mı onu merak ediyorum.
teşekkürler.

nonstradam

merhaba.
tlv5618 veya mcp4921 gibi 12-bit SPI lı dak nereden bulabilirim karaköyde aramadığım yer kalmadı siz nereden temin ettiniz.
iyi çalışmalar.

nonstradam

arkadaşlar mcp4921 i nereden bulabilirim bana çok acil lazım bu çip. lütfen yardınmcı olurmusunuz

picusta

Bulamiyorsan yurt disindan getirtmeyi dene.
Ben tlv5618'i farnell'den almistim. Futurlec sitesine bak, orda posta parasi ucuzmus.
Ya da sitede elinde olan bir yardim sever gönderebilir.

OG

Proton için "SHIN" ve "SHOUT" aradığınız komutlardır.

Alıntı YapSHIN

Syntax
SHIN dpin , cpin , mode , [ result { \bits } { ,result { \bits }...} ]

or

Var = SHIN dpin , cpin , mode , shifts

Availability
All devices.

Overview
Shift data in from a synchronous-serial device.

Operators
Dpin is a Port.Pin constant that specifies the I/O pin that will be connected to the synchronous-serial device's data output. This pin's I/O direction will be changed to input and will remain in that state after the instruction is completed.

Cpin is a Port.Pin constant that specifies the I/O pin that will be connected to the synchronous-serial device's clock input. This pin's I/O direction will be changed to output.
Mode is a constant that tells SHIN the order in which data bits are to be arranged and the relationship of clock pulses to valid data. Below are the symbols, values, and their meanings: -


Symbol   Value   Description
MSBPRE  MSBPRE_L   0   Shift data in highest bit first.  Read data before sending clock. Clock idles low
LSBPRE  LSBPRE_L   1   Shift data in lowest bit first.  Read data before sending clock. Clock idles low
MSBPOST  MSBPOST_L   2   Shift data in highest bit first.  Read data after sending clock. Clock idles low
LSBPOST  LSBPOST_L   3   Shift data in highest bit first.  Read data after sending clock. Clock idles low
MSBPRE_H   4   Shift data in highest bit first.  Read data before sending clock. Clock idles high
LSBPRE_H   5   Shift data in lowest bit first.  Read data before sending clock. Clock idles high
MSBPOST_H   6   Shift data in highest bit first.  Read data after sending clock. Clock idles high
LSBPOST_H   7   Shift data in lowest bit first.  Read data after sending clock. Clock idles high

Result is a bit, byte, or word variable in which incoming data bits will be stored.
Bits is an optional constant specifying how many bits (1-16) are to be input by SHIN. If no bits entry is given, SHIN defaults to 8 bits.
Shifts informs the SHIN command as to how many bit to shift in to the assignment variable, when used in the inline format.

Notes
SHIN provides a method of acquiring data from synchronous-serial devices, without resorting to the hardware SPI modules resident on some PICmicro types. Data bits may be valid after the rising or falling edge of the clock line. This kind of serial protocol is commonly used by controller peripherals such as ADCs, DACs, clocks, memory devices, etc.


The SHIN instruction causes the following sequence of events to occur: -


·   Makes the clock pin (cpin) output low.
·   Makes the data pin (dpin) an input.
·   Copies the state of the data bit into the msb(lsb- modes) or lsb(msb modes) either before (-pre modes) or after (-post modes) the clock pulse.
·   Pulses the clock pin high.
·   Shifts the bits of the result left (msb- modes) or right (lsb-modes).
·   Repeats the appropriate sequence of getting data bits, pulsing the clock pin, and shifting the result until the specified number of bits is shifted into the variable.



Making SHIN work with a particular device is a matter of matching the mode and number of bits to that device's protocol. Most manufacturers use a timing diagram to illustrate the relationship of clock and data.


   SYMBOL CLK = PORTB.0
   SYMBOL DTA = PORTB.1
   SHIN DTA , CLK , MSBPRE , [VAR1]      ' Shiftin msb-first, pre-clock.

In the above example, both SHIN instructions are set up for msb-first operation, so the first bit they acquire ends up in the msb (leftmost bit) of the variable.

The post-clock Shift in, acquires its bits after each clock pulse. The initial pulse changes the data line from 1 to 0, so the post-clock Shiftin returns %01010101.


By default, SHIN acquires eight bits, but you can set it to shift any number of bits from 1 to 16 with an optional entry following the variable name. In the example above, substitute this for the first SHIN instruction:

   SHIN DTA , CLK , MSBPRE , [VAR1 \ 4] 'Shift in 4 bits.

Some devices return more than 16 bits. For example, most 8-bit shift registers can be daisy-chained together to form any multiple of 8 bits; 16, 24, 32, 40... You can use a single SHIN instruction with multiple variables.

Each variable can be assigned a particular number of bits with the
backslash (\) option. Modify the previous example: -

   ' 5 bits into VAR1; 8 bits into VAR2.
   SHIN DTA , CLK , MSBPRE , [ VAR1 \ 5 , VAR2 ]
   PRINT "1st variable: " , BIN8 VAR1
   PRINT "2nd variable: " , BIN8 VAR2

Inline SHIN Command.
The structure of the INLINE SHIN command is: -

Var = SHIN dpin , cpin , mode , shifts

DPIN, CPIN, and MODE have not changed in any way, however, the INLINE structure has a new operand, namely SHIFTS. This informs the SHIN command as to how many bit to shift in to the assignment variable. For example, to shift in an 8-bit value from a serial device, we would use: -

   VAR1 = SHIN DT , CK , MSBPRE , 8

To shift 16-bits into a WORD variable: -

   WRD = SHIN DT , CK , MSBPRE , 16

Alıntı YapSHOUT

Syntax
SHOUT Dpin, Cpin, Mode, [OutputData {\Bits} {,OutputData {\Bits}..} ]

Availability
All devices.

Overview
Shift data out to a synchronous serial device.

Operators
Dpin is a Port.Pin constant that specifies the I/O pin that will be connected to the synchronous serial device's data input. This pin will be set to output mode.
Cpin is a Port.Pin constant that specifies the I/O pin that will be connected to the synchronous serial device's clock input. This pin will be set to output mode.

Mode is a constant that tells SHOUT the order in which data bits are to be arranged. Below are the symbols, values, and their meanings: -


Symbol      Value      Description
   LSBFIRST   0      Shift data out lowest bit first.  Clock idles low
   LSBFIRST _L   0      Same as above

   MSBFIRST   1      Shift data out highest bit first.  Clock idles low
   MSBFIRST_L   1      Same as above

   LSBFIRST _H   4      Shift data out lowest bit first.  Clock idles high

   MSBFIRST_H   5      Shift data out highest bit first.  Clock idles high


OutputData is a variable, constant, or expression containing the data to be sent.
Bits is an optional constant specifying how many bits are to be output by SHOUT. If no Bits entry is given, SHOUT defaults to 8 bits.

Notes
SHIN and SHOUT provide a method of acquiring data from synchronous serial devices. Data bits may be valid after the rising or falling edge of the clock line. This kind of serial protocol is commonly used by controller peripherals like ADCs, DACs, clocks, memory devices, etc.


At their heart, synchronous-serial devices are essentially shift-registers; trains of flip flops that receive data bits in a bucket brigade fashion from a single data input pin. Another bit is input each time the appropriate edge (rising or falling, depending on the device) appears on the clock line.

The SHOUT instruction first causes the clock pin to output low and the data pin to switch to output mode. Then, SHOUT sets the data pin to the next bit state to be output and generates a clock pulse. SHOUT continues to generate clock pulses and places the next data bit on the data pin for as many data bits as are required for transmission.

Making SHOUT work with a particular device is a matter of matching the mode and number of bits to that device's protocol. Most manufacturers use a timing diagram to illustrate the relationship of clock and data. One of the most important items to look for is which bit of the data should be transmitted first; most significant bit (MSB) or least significant bit (LSB).

Example
   SHOUT DTA , CLK , MSBFIRST , [ 250 ]


In the above example, the SHOUT command will write to I/O pin DTA (the Dpin) and will generate a clock signal on I/O CLK (the Cpin). The SHOUT command will generate eight clock pulses while writing each bit (of the 8-bit value 250) onto the data pin (Dpin). In this case, it will start with the most significant bit first as indicated by the Mode value of MSBFIRST.

By default, SHOUT transmits eight bits, but you can set it to shift any number of bits from 1 to 16 with the Bits argument. For example: -


   SHOUT DTA , CLK , MSBFIRST , [ 250 \ 4 ]

Will only output the lowest 4 bits (%0000 in this case). Some devices require more than 16 bits. To solve this, you can use a single SHOUT command with multiple values. Each value can be assigned a particular number of bits with the Bits argument. As in: -

   SHOUT DTA , CLK , MSBFIRST , [ 250 \ 4 , 1045 \ 16]


The above code will first shift out four bits of the number 250 (%1111) and then 16 bits of the number 1045 (%0000010000010101). The two values together make up a 20 bit value.
FORUMU İLGİLENDİREN KONULARA ÖM İLE CEVAP VERİLMEZ.