AnsweredAssumed Answered

RDAC AD5206: doesn't works like i need it

Question asked by ASantos on Nov 7, 2011
Latest reply on Nov 17, 2011 by ASantos


Well,

 

Im trying to use all potenciometers (AD5206) but anything is wrong, I use Pic 16F877A and CCS compiler, I attached  my source code.

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <16f877A.h>
#include <stdlib.h>
#fuses  HS,NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use DELAY(CLOCK=8000000)
#use STANDARD_IO (A)
#use spi( force_hw, bits=8, MODE=0)
#byte PA = 0x05
#byte PC = 0x07
main(){
int x=0;
set_tris_A(0x02);   //A1 like a input, when i do press a button the wiper must be change
set_tris_C(0x00);  
setup_spi( spi_master | spi_l_to_h | spi_clk_div_16 );
output_high(PIN_A0);   //CS to high
   while(1){
      if(input_state(PIN_A1)==1)
         {
            output_toggle(PIN_A5);
            delay_ms(100);
            output_toggle(PIN_A5);
            delay_ms(100);
            output_toggle(PIN_A5);
            delay_ms(100);
            output_toggle(PIN_A5);    //It shows which enter to if sentence
            delay_ms(100);
            x=x+8;
            output_low(PIN_A0);
            delay_ms(10);
            spi_write(0x00);
            spi_write(x);
            delay_ms(10);
            output_high(PIN_A0);
            delay_ms(10);
            output_low(PIN_A0);
            spi_write(0x01);
            spi_write(x);
            output_high(PIN_A0);
            delay_ms(10);
            output_low(PIN_A0);
            spi_write(0x02);
            spi_write(x);
            output_high(PIN_A0);
            delay_ms(10);
            output_low(PIN_A0);
            spi_write(0x03);
            spi_write(x);
            output_high(PIN_A0);
            delay_ms(10);
            output_low(PIN_A0);
            spi_write(0x04);
            spi_write(x);
            output_high(PIN_A0);
            delay_ms(10);
            output_low(PIN_A0);
            spi_write(0x05);
            spi_write(x);
            output_high(PIN_A0);
            delay_ms(10);
         }
}}  //close while and main

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

regards

Outcomes