ATmega32 Controlling DS1802 pot

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
Hi,
there are some threads on controlling DS1802 with IR or Rotary encoders. I Plan to command the DS1802 with RS232 commands (out of a linn Player).
Now , the ATmega has an SPI out , that could Control the 3wire Serial Input of the DS1802 (RST, CLK, D Inputs).
Can anyone help me, how to generate the Serial commands in the ATmega32, that the DS needs to see?
Thanks a Lot, Frank
 
You can simply send raw hex values over serial communication, copy the two bytes in some local variables and then send them over SPI. Be carefull with DS1802, since it has the chip select line active on high level and the bytes are sent with LSB first.
 
Thanks,

as it´s my first uC project, I just wonder if I have to take care, that RST is "high" while the hexcode is sent and so on. In the datasheet of the DS1802 the serial controlling seems sooo complicated with the tcc, tch .... timing and the clocksynchronisation.

Is it that simple, just connecting the clock out of the ATmega (XCK pin#1) to the CLK (pin#3) of the DS1802?

Furthermore I would connect
SCK on the ATmega (pin#7) to D(pin#4) on DS1802,
SS on the ATmega (pin#4) to RST(pin#5) on DS1802
GND to GND.

...or am I missing something?

Frank
 
Just curious, why the DS1802? It will need an additional buffer circuit and the signal will be limited by the 5V supply.

It's a novel circuit to play with if your just going to use push buttons, but if you plan to put the effort into using a uC then there are better IC's available.
 
DS1802 because it´s used on the VCCS board for the Lightspeed attenuator, that I build.

The uC would translate the ASCII strings, that come out of the networkplayer, into commands for volume setting (and poweramp control by 12V toggle)

My Ipod with PlugPlayer is an upnp controlpoint of the networkplayer and it uses a slider for Volume setting. So, when I move the slider to 87% volume, the networkplayer sends a command $Volume=87$ (the value is between 0 and 100) as ASCII code to the uC (UART RX).

The uC would recognise the volume command and the value after the "=" and multiply the value by 0,64 (as the DS1802 pointer has 64 steps). Then the uC would somehow?? generate the serial commands for the RST , D and CLK inputs of the DS1802.
 
Last edited by a moderator:
first you need to look at ATMEL documentation for TWI interface, there is an AVR document for ..how to's of TWI.
You can also have a look at the documentation of IC's like TDA7449 that use the TWI inteface for controlling. The datasheet of TDA 7449 in fact carries a lot of information regarding how to send signals over TWI and how to send address etc.
Have a look at this also www.atmel.com/dyn/resources/prod_documents/doc2564.pdf
 
Furthermore I would connect
SCK on the ATmega (pin#7) to D(pin#4) on DS1802,
SS on the ATmega (pin#4) to RST(pin#5) on DS1802
GND to GND.

Connections are as following:
D (pin 4) goes to MOSI (pin 6)
CLK (pin 3) goes to SCK (pin 8)
RST (pin 5) goes to SS (pin 5) or any other port pin you like to use as chip select line.
The power supply can be the same for both ATmega and DS.

Flow of the code:
- register initialization (system clock, ports, USART, SPI);
- infinite loop in which data is received over USART and sent over SPI.

I think this thread can be placed better in Digital Line Level section of the forums.
 
8-bit vs 16 bit?

Just wondering if this might be a limiting issue of the ATmega32.
Its SPI Data register has only 8 bits.
Ds1802 has a 16 bit I/O Shift register which uses the first 8 bits for wiper0 and the bits 8 to 15 for wiper1.

Is this an issue or would there be a way to send those 2 (identical) 8 bit strings seamless one-after-the-other as a 16-bit string?

Cheers, Frank
 
doesn't look like a issue to me , if you look towards the end in the DS datasheet it shows an example transmission for controlling it via 3 wire interface. It actually expects two 8 bit values one after the other albeit you have to keep RST high all the time. Only after you have sent both the bytes ( B0 and B1 ) then pull RST to low. IMHO you don't need a 16 bit register to accomplish this.
 
Thanks,
so I´ll try to keep the RST high for the duration of those 2 x 8-bit transmissions.

The "Generation" of the 16-bit string is quite new stuff for me. Especially the composition of the 16-bit signal together with the challenge, that events on each on those 3 serial lines should occur at the right time and be coordinated.
Consulting the ATmega32 manual, I wonder , how to accomplish this. E.g. does the writing in the SPI data register automatically initiate a transmission?

....and the Master generates the required clock pulses on the SCK line to interchange data. Data is always shifted from Master to Slave on the Master Out – Slave In, MOSI, line,....
When configured as a Master, the SPI interface has no automatic control of the SS line. This must be handled by user software before communication can start. When this is done, writing a byte to the SPI Data Register starts the SPI clock generator, and the hardware shifts the eight bits into the Slave.


I would arrange the programming like this:

1) Volume command value=X is received
2) Set the I/O port , that is connected to DS1802´s RST, to 1 (high state)
3) Write the desired wiper position into the SPDR data register (bit 0 to 5 is the hex value of the desired wiper position), bit 6=0, bit 7=0
4)Is now any trigger necessary to start the transmission through MOSI?
5) After shifting one byte, the SPI clock generator stops, setting the end of Transmission Flag (SPIF).
7)
If SPIF=1, then write the second, identical, 8-bit block with desired wiper position into the SPDR data register (bit 0 to 5 is the hex value of the desired wiper position), bit 6=0, bit 7=0 . These will be the bits 8 to 15 for the DS1802 I/O shift register.
8) Ignore SPIF
9) Set the I/O port , that is connected to DS1802´s RST, to 0 (low state)

Will this work or do I have to modify this plan?

Cheers, Frank
 
E.g. does the writing in the SPI data register automatically initiate a transmission?
...
I would arrange the programming like this:

1) Volume command value=X is received
2) Set the I/O port , that is connected to DS1802´s RST, to 1 (high state)
3) Write the desired wiper position into the SPDR data register (bit 0 to 5 is the hex value of the desired wiper position), bit 6=0, bit 7=0
4)Is now any trigger necessary to start the transmission through MOSI?
5) After shifting one byte, the SPI clock generator stops, setting the end of Transmission Flag (SPIF).
7)
If SPIF=1, then write the second, identical, 8-bit block with desired wiper position into the SPDR data register (bit 0 to 5 is the hex value of the desired wiper position), bit 6=0, bit 7=0 . These will be the bits 8 to 15 for the DS1802 I/O shift register.
8) Ignore SPIF
9) Set the I/O port , that is connected to DS1802´s RST, to 0 (low state)

Will this work or do I have to modify this plan?

Cheers, Frank

OK, I had a quick look at the datasheets, I only worked with an Atmega once, and I didn't program that, but I've used a lot of PICs and done a lot of programming of other controllers.

I don't see any details as to what clock speed you're going with. There's an internal clock, but this might not be very convenient to use with the incoming data, so you need to do some calculations as to what divisor you're going to use. The chosen clock also impacts on the SPI datarate.

One other thing I notice is that SS in the controller is active low for data transfer, but RST on the pot is active high, so you need to use a pin other than SS to connect to RST and set it in opposition to SS (or use an invertor).

Your program as laid out is a bit sketchy. You should make your pseudocode more comprehensive, with all the loops shown if you want a comprehensive critique.

First you're going to have a one-time-only setup section as set out by ratza.

You need to select the clock source.

You need to set the UART baud rate, number of data bits, parity if any and number of stop bits. The baud rate setup will depend on the clock you have chosen and the baud rate of the incoming data.

You need to enable the SPI, set SPE in the SPCR.

A few output bits for debug is a good idea, as you have plenty available. 2 or 3 bits set as output with LEDs on them can be a help, and you can use one to show a heartbeat.

Now you've got a receive loop for the UART. You need to unpack all the bytes into storage, or at least count them.

Are you going to do any integrity check on the received data? You can check all the incoming bytes (except the volume number), but this will require a specimen string to be set up in memory in the initialisation section. You can turn on an LED for debug when you receive a string correctly. You also need an abort (clear received bytes and reset counter) option if the string is garbled.

Once this loop completes successfully you can drop through into the SPI transfer. The SS line must be reset followed by the shifting of a byte into the tx register to initiate transmission. My reading is that you cannot ignore SPIF, as this will be reset when transmission of the second byte starts, and you need to know when you can set SS and reset RST.

You need to think about what will happen if another ASCII string starts to arrive while the SPI transmit is in progress.

Anyway, that's enough for the moment, I have to go out.

w
 
Start by getting one of the Atmel sample applications working, something that uses the UART. Do searches on the AVR forums to help you do this. Find some sample SPI code, hook up a scope to the SPI port and play around with the registers until you understand how it works. Then start designing the real code.
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.