PDA

View Full Version : Clock connection to DS1802 from 16F877A



coyotegd
- 23rd December 2005, 22:19
I thought this would be a simple solution for someone more experienced than me before I breadboard a mess. It is not a programming question, but I need the circuit correct before I can test my programming.

I am using a 16F877A as the brains for an IR receiver in a preamp. In conjunction with the 16F877A, I am using a Dallas Semiconductor (Maxim) DS1802, dual-digital potentiometer. The DS1802 has a "RST" (Serial Port Reset Input) pin that must be "high" to trigger an internal read and write routine of a "Word" (I’ve got this covered). In addition, however, the DS1802 has a "CLK" (Serial Port Clock Input) pin, which I am almost 100% sure needs the clock speed from the 16F877A.

I have a 20MHz crystal connected to pins 13 and 14 of the 16F877A with paralleled 22pf caps to ground.

My question is, can I just simply connect the "CLK" pin of the DS1802 to pin 14 (OSC2/CLKOUT) of the 16F877A or is it more complicated?

If I must use a separate pin of the 16F877A, how do I place the clock speed on the pin so the DS1802 can see 20MHz?

Thanks

Ken Klausner

Mith
- 23rd December 2005, 23:26
Take a look at the timing diagram on page 9 of the datasheet (Figure 6a). The clk line needs to be connected to a port pin and it makes a transition signaling that a 'new bit' is ready to be latched into the DS1802. You can use the shiftin command to communicate with this device.

Mith
- 23rd December 2005, 23:29
I was a bit too quick to reply to your post. Shiftout will write to a device and Shiftin is used to read from a device. You will want to concentrate on Shiftout to communicate with the DS1802.

coyotegd
- 24th December 2005, 05:48
I see that I could set the RST pin high and, possibly, use PULOUT to send 20MHz to the CLK pin of the DS1802. Then during the pulse, I could read the WORD output on the DS1802's COUT pin. However, I don't know if this is a "best practice".

The datasheet states:

When RST is driven high, bit 0 is present on the COUT pin. When the CLK input transitions low to high, bit 0 is loaded into the first position of
the I/O shift register and bit 1 becomes present on COUT. After 16 bits, the data has shifted completely around and back to its original position.

So, can I use pin 14 (OSC2/CLKOUT) on the CLK pin, and use two other pins to to set RST high and use SERIN on COUT?

Or, do I use three other pins to set RST high, PULOUT, and SERIN?

Also, with regard to PULOUT, the PICBASIC PRO manual states, "The pulse is generated by toggling the pin twice, thus the initial state of the pin determines the polarity of the pulse." I have no idea whether the pin should start HIGH or LOW before using PULOUT. Can someone explain?

I looked at the SHIFTIN command, but I don't understand how to implement it in my situation. I not sure it's the right answer to my problem.

Mith
- 24th December 2005, 12:08
I don't believe that using a 20mhz clock would even come close to working. If you look at the timing diagrams the clk has to transition low to high for each bit that you are reading in. The instruction clock of a pic running at 20mhz is running at 20mzh/4 = 5mhz. If you put the osc line to the clk input on the DS1802 then your clock will be transitioning much to fast. Try something like this:
Dedicate four lines for the interface, RST, CLK, D, C.
To read C use the shiftin, something like this (this is not tested and may have errors):

high RST 'data appears on C when rst transitions to high
input D 'left floating during read of the C line according to datasheet
shiftin C,CLK,0,[CDATA\16]
low RST

To write to the D line something like this should work:
high RST 'data appears on C when rst transitions to high
input C 'just to make sure that it doesn't interfere by holding high or low
shiftout D,CLK,0,[DDATA\16]
low RST

Again this is not tested but it seems to fit the specifications in the datasheet. You may have to adjust the mode values which are found on page 146 of the PBC manual.

By the way, the datasheet lists the maximun clk rate at 10mhz.

coyotegd
- 24th December 2005, 17:11
I will try using your approach when I breadboard in a few days. I appreciate your efforts and will post back with the results.

I swear that I thoroughly read datasheets, but my brain gets overwhelmed and short-ciruits with misunderstood information due to my inexperience. I have attached the DS1802 datasheet in case anyone else is interested.

Thanks again

Ken

Mith
- 24th December 2005, 22:43
I fully understand how overwhelming they can be. I've been trying to get my head wrapped around the DS2406 datasheet and trying to understand how the one wire commands can be used to communicate with them. It's less than clear on several points. Good luck with your project.

coyotegd
- 3rd January 2006, 18:52
I didn't realize that just designating a "CLK" pin on the 16F877A is all that was needed. I was under the impression that I had to somehow place a square wave on the "CLK" pin for the DS1802's reference. I used a 4 MHz crystal on the 16F877A. The following relevant code works great for reading pot values from the DS1802 and displaying the pot values on an Optrex LCD:


INCLUDE "modedefs.bas"

@ DEVICE XT_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF

DEFINE LCD_DREG PORTA ' RA to LCD data port
DEFINE LCD_DBIT 0 ' Starting data bit on A0 & last on A3
DEFINE LCD_BITS 4 ' Set 4-bit data bus width
DEFINE LCD_RSREG PORTA ' Set LCD register select port to A
DEFINE LCD_RSBIT 4 ' Set A4 to register select pin
DEFINE LCD_EREG PORTE ' Set LCD enable to port E
DEFINE LCD_EBIT 0 ' Set E0 to LCD enable pin
DEFINE LCD_LINES 4 ' LCD is a 4 line display
DEFINE LCD_COMMANDUS 2000 ' Set LCD command delay time in uS
DEFINE LCD_DATAUS 50 ' Set LCD data delay time in uS

ADCON1 = 7 ' Digital I/O for RA & RE
INTCON.7 = 1 ' Enable all unmasked interrupts (GIE)
TRISB = 255 ' All PORTB pins as inputs for panel switches
OPTION_REG.7 = 0 ' Enable all PORTB internal pull-ups
RST var PORTD.5 ' Set high to read potentiometer settings
RST = 0
CLK var PORTE.1 ' Clock DS1802 to read potentiometer settings
ReadPots var PORTE.2 ' Read potentiometer settings
LPot var byte ' Left channel
RPot var byte ' Right channel

pause 500
LCDOUT 254, 12 ' Turn cursor off & display on
lcdout 254, 1 ' Clear display
pause 200
lcdout 254, 135, "Volume"
gosub update_lcd

MAIN:
if PORTB <> 255 THEN

endif
GOTO MAIN

UPDATE_LCD:
RST = 1
shiftin readpots, clk, LSBPRE, [lpot, rpot]
rst = 0
lpot = lpot & %00111111
rpot = rpot & %00111111
if lpot < 10 then
lcdout 254, 194, "L:-", #lpot, "db ", " R:-", #rpot, "db "
else
lcdout 254, 194, "L:-", #lpot, "db", " R:-", #rpot, "db "
endif
return