ATmega32 Controlling DS1802 pot - Page 2 - diyAudio
Go Back   Home > Forums > Amplifiers > Chip Amps

Chip Amps Amplifiers based on integrated circuits

Please consider donating to help us continue to serve you.

Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving
Reply
 
Thread Tools Search this Thread
Old 19th June 2010, 12:13 PM   #11
fbee is offline fbee  Germany
diyAudio Member
 
Join Date: Mar 2010
Default 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
  Reply With Quote
Old 19th June 2010, 12:38 PM   #12
sasmit is offline sasmit  India
diyAudio Member
 
Join Date: May 2006
Send a message via Yahoo to sasmit
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.
  Reply With Quote
Old 20th June 2010, 08:26 AM   #13
fbee is offline fbee  Germany
diyAudio Member
 
Join Date: Mar 2010
Thanks,
so Ill 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 DS1802s 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 DS1802s RST, to 0 (low state)

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

Cheers, Frank
  Reply With Quote
Old 20th June 2010, 02:46 PM   #14
Banned
 
Join Date: Jan 2008
Blog Entries: 2
Quote:
Originally Posted by fbee View Post
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 DS1802s 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 DS1802s 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
  Reply With Quote
Old 20th June 2010, 03:53 PM   #15
paulb is offline paulb  Canada
diyAudio Member
 
Join Date: Jun 2001
Location: Calgary
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.
  Reply With Quote

Reply


Hide this!Advertise here!
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Encoder for DS1802 tifosi_f1 Solid State 3 16th January 2007 01:10 PM
WTB: DS1802 digital pot or similar Moose Swap Meet 0 8th July 2005 11:11 PM
DS1666 vs. DS1802 dalli Chip Amps 0 10th March 2005 09:05 AM
DS1802 with LM3875 soundNERD Chip Amps 11 26th February 2005 09:10 AM
Controlling TDA7448 with DS1802 Help Wanted abid_rehan Digital Source 2 6th September 2004 05:55 PM


New To Site? Need Help?

All times are GMT. The time now is 12:17 PM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio

Content Relevant URLs by vBSEO 3.3.2