Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AD5231 with ATmega32

Status
Not open for further replies.

north2012

Member level 3
Member level 3
Joined
Apr 1, 2013
Messages
63
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,813
Hi all,

I am using AD5231 with ATmega32 but I have problem to set wiper. Here is my code. Does anyone can see where is error because the resistance does not change whatever I send as command for wiper. I checked all hardware connections and everything seems to be good.

Code:
//#include<built_in.h>

sbit CLK at PORTB7_bit;
sbit CLK_Direction at DDB7_bit;

sbit DAT at PORTB5_bit;
sbit DAT_Direction at DDB5_bit;

sbit CS at PORTA4_bit;
sbit CS_Direction at DDA4_bit;

void set_pot(void)
{
   unsigned char i = 0;
   unsigned char cmd[3];
   unsigned long send = 0xb00300;

   CLK = 1; CLK = 1;
   CS = 0; CS = 0;
   for(i=0; i<24; i++)
   {
    if(send & 0x800000)
    {
    DAT = 1;
    }
    else
    {
    DAT = 0;
    }
    CLK = 0; CLK = 0;
    send = send << 1;
    CLK=1; CLK=1;
    } 
CS = 1; CS = 1;
}

void main()
{
  DAT_Direction = 1;     // define as output
  CLK_Direction = 1;     // define  as output
  CS_Direction = 1;     // define as output
  delay_ms(50);
  set_pot();
  while(1)
  {
  }
}

Thanks in advance.
 

I am making it two times just to ensure enough time for stabilization. My hardware connections are:
Vcc-#WP, #PR and Vdd
GND - Gnd, Vss, T, B
SDI- DAT
CLK - SCK
#CS - #CS
 

Post your circuit. Are you using RDY pin?

Try this code.


Code C - [expand]
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
//Pullup CS and CLK lines using 10k resistor
 
void Digital_POT_Write(unsigned int address, unsigned int data);
 
void main(){
 
    CLK = 1;
    CS = 1;
    
    for(i = 0; i < 1023; i++){
 
            Digital_POT_Write(0, i);
        _delay_ms(10);
 
    }
 
    while(1);
 
}
 
 
void Digital_POT_Write(unsigned int address, unsigned int data){
 
    unsigned char Command = 0xB0;
    unsigned char i = 0, byte1, byte0;
    
 
    CS = 0;
    Command = Command + address;
    byte1 = data >> 8;
    byte0 = data & 0xFF;
 
    for(i = 0; i < 8; i++){
        if(Command & 0x80)
            DAT = 1;
        else DAT = 0;
 
        CLK = 0;
        CLK = 1;
        Command = Command << 1;
    }
 
    for(i = 0; i < 8; i++){
        if(byte1 & 0x80)
            DAT = 1;
        else DAT = 0;
 
        CLK = 0;
        CLK = 1;
        byte1 = byte1 << 1;
    }
 
    for(i = 0; i < 8; i++){
        if(byte0 & 0x80)
            DAT = 1;
        else DAT = 0;
 
        CLK = 0;
        CLK = 1;
        byte0 = byte0 << 1;
    }
 
    CS = 1;
    CLK = 1;
 
}

 
Last edited:

I found bug in my code and here is working version written using microC for AVR compiler.
Code:
#include<built_in.h>
sbit CLK at PORTA1_bit;
sbit CLK_Direction at DDA1_bit;

sbit DAT at PORTA2_bit;
sbit DAT_Direction at DDA2_bit;

sbit CS at PORTA0_bit;
sbit CS_Direction at DDA0_bit;

void set_pot(unsigned int position)
{
   unsigned char i = 0;
   unsigned long send = 0xb00300;
   unsigned char set[3] = {0x00, 0x00, 0x00};
   set[0] = 0xB0;  //komanda za RDAC
   set[1] = Hi(position);
   set[2] = Lo(position);

   //send = 0x00b003ff;
   send = set[2]+256*set[1]+65536*set[0];
   
   CLK = 0;
   asm nop;
   CS = 0; 
   asm nop;
   for(i=0; i<24; i++)
   {
    if(send & 0x800000)
    {
    DAT = 1;
    asm nop;
    }
    else
    {
    DAT = 0;
    asm nop;
    }
    CLK = 1;
    asm nop;
    send = send << 1;
    CLK=0;
    asm nop;
    } 
CS = 1; 
asm nop;
}

void main()
{
  DAT_Direction = 1;     // define as output
  CLK_Direction = 1;     // define  as output
  CS_Direction = 1;     // define as output
  delay_ms(500);

  while(1)
  {
  set_pot(0x0100);
  delay_ms(3000);
  set_pot(0x03ff);
  delay_ms(3000);
  }
}

Now, I have another problem;

I read that tolerance is -40 to +20 % but I expected that resistance is linear in full range and for 0xb003ff I expected full scale resistance which should be around 39-40 kOhms. I measured Rwa resistance and for all measurements except last one the sum is equal to 39-40 Kohms.
Command Rwb Rwa
0xb00000 62.2 Ohms 39.74 kOhms
0xb00100 9.98 kOhms 29.78 kOhms
0xb00200 19.75 kOhms 19.86 kOhms
0xb00300 28.38 kOhms 9.94 kOhms
0xb003ff 33.29 kOhms 66.6 Ohms ????

Did anyone have similar experience?

Best regards.
 

I am using 50 kOhms version but I think that due the tolerance ( +20, -40%) it can be different from nominal value.

**broken link removed**
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top