Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/24/11 23:00
Read: 938 times


 
Msg Score: -1
 -1 Message Not Useful
#183021 - ATTENTION:CS5460A CODE HERE CANNOT WORK
http://www.8052.com/forum/read/134946

This is the code origin:
I add "++++++" to the error code!





sbit CS5460ADin = P1^5; // CS4560A serial data in
sbit CS5460ADout = P1^6; // CS4560A serial data out
sbit CS5460AClk = P1^7; // CS4560A serial clock


//CS5460A register addresses
#define CS5460A_REG_CONFIG 0x00
#define CS5460A_REG_AIN1_OFFSET 0x02++++++++++++++++++++++and follow
#define CS5460A_REG_AIN1_GAIN 0x04
#define CS5460A_REG_AIN2_OFFSET 0x06
#define CS5460A_REG_AIN2_GAIN 0x08
#define CS5460A_REG_CYCLE 0x0A
#define CS5460A_REG_PULSE 0x0C
#define CS5460A_REG_CURRENT 0x0E
#define CS5460A_REG_VOLT 0x12
#define CS5460A_REG_POWER 0x14
#define CS5460A_REG_ENERGY 0x16
#define CS5460A_REG_IRMS 0x18
#define CS5460A_REG_VRMS 0x1A
#define CS5460A_REG_TBC 0x1C
#define CS5460A_REG_PWR_OFFSET 0x1E
#define CS5460A_REG_STATUS 0x20
#define CS5460A_REG_IACOFFSET 0x22
#define CS5460A_REG_VACOFFSET 0x24
#define CS5460A_REG_MASK 0x34
#define CS5460A_REG_CONTROL 0x38

//CS5460A commands
#define CONVERT_CONTINOUS 0xE8
#define CONVERT_ONCE 0xE0
#define CS5460A_SYNC0 0xFE
#define CS5460A_SYNC1 0xFF
#define POWER_UP_HALT 0xA0
#define CAL_AIN1_DC_GAIN 0xCA
#define CAL_AIN1_DC_OFFSET 0xC9
#define CAL_AIN2_DC_GAIN 0xD2
#define CAL_AIN2_DC_OFFSET 0xD1
#define CS5460A_WRITE 0x40
#define CS5460A_READ 0x3E

//config data
#define CLOCK_DIVIDER 0x00000004
#define AIN1_GAIN_10 0x00000000
#define AIN1_GAIN_50 0x00010000
#define SOFT_RESET 0x00000080
#define MASK_NO_INTERRUPTS 0x00000000
#define STATUS_CLR_CRDY 0x00100000
#define STATUS_CLR_DRDY 0x00800000
#define STATUS_CLR_ALL 0x00FFFFFF
#define CONTROL_DEFAULT 0x00000000
#define CURRENT_GAIN_DEFAULT 0x00100000
#define VOLT_GAIN_DEFAULT 0x00100000
#define COMPUTATION_CYCLE 0x00000FA0
#define TIME_BASE 0x00800000


//===========================================================================
bit CS5460AReadDRDYBit(void)
{
bit ReadyBit;
Byte4 xdata StatusRegister;
StatusRegister=CS5460ARead24Bits(CS5460A_REG_STATUS);
if(StatusRegister & 0x00800000){ReadyBit=1;}else{ReadyBit=0;}//get DRDY bit
return(ReadyBit);
}
//===========================================================================
bit CS5460AReadCRDYBit(void)
{
bit ReadyBit;
Byte4 xdata StatusRegister;
StatusRegister=CS5460ARead24Bits(CS5460A_REG_STATUS);
if(StatusRegister & 0x00100000){ReadyBit=1;}else{ReadyBit=0;}//get CRDY bit
return(ReadyBit);
}
//===========================================================================
void CS5460AResetConfigure(void)
{
CS5460AReset();
CS5460AWrite24Bits((CLOCK_DIVIDER |AIN1_GAIN_10),CS5460A_REG_CONFIG);//Ain1
CS5460AWrite24Bits(CONTROL_DEFAULT,CS5460A_REG_CONTROL);//write default
CS5460AWrite24Bits(STATUS_CLR_ALL,CS5460A_REG_STATUS);//clear all status
CS5460AWrite24Bits(MASK_NO_INTERRUPTS,CS5460A_REG_MASK);//no interrupts
//gain is 10, clock divider is 4
CS5460AWrite24Bits(CURRENT_GAIN_DEFAULT,CS5460A_REG_AIN1_GAIN);//Ain1 gain
CS5460AWrite24Bits(VOLT_GAIN_DEFAULT,CS5460A_REG_AIN2_GAIN);//Ain2 gain
CS5460AWrite24Bits(COMPUTATION_CYCLE,CS5460A_REG_CYCLE);//rms cycle
CS5460AWrite24Bits(TIME_BASE,CS5460A_REG_TBC);//default time base
CS5460AWriteCommand(CONVERT_CONTINOUS);//start conversions
return;
}
//===========================================================================
void CS5460AReset(void)
{
Byte xdata BitCounter;
//Cirrus Logic data sheet page 43
for(BitCounter=0;BitCounter<3;BitCounter++)//send 3 SYNC1 bytes
{
CS5460AWriteCommand(CS5460A_SYNC1);
}
CS5460AWriteCommand(CS5460A_SYNC0);//send 1 SYNC0 byte
CS5460AWrite24Bits(SOFT_RESET,CS5460A_REG_CONFIG);//issue soft reset
return;
}
//===========================================================================
void CS5460AWriteCommand(Byte Command)
{
Byte xdata WriteByte;
Byte xdata BitCounter;
WriteByte=Command;
for(BitCounter=0;BitCounter<8;BitCounter++)
{
if(WriteByte & 0x80){CS5460ADin=1;}else{CS5460ADin=0;}
CS5460APulseClock();WriteByte=WriteByte<<1;
}
return;
}
//===========================================================================
void CS5460AWrite24Bits(Byte4 RegisterData, Byte AdcRegisterAddress)
{
Byte xdata BitCounter;
Byte xdata WriteByte;
Byte4 xdata WriteLong;
WriteLong=RegisterData;
WriteByte=(CS5460A_WRITE | AdcRegisterAddress);//write command with reg address
for(BitCounter=0;BitCounter<8;BitCounter++)//send command
{
if(WriteByte & 0x80){CS5460ADin=1;}else{CS5460ADin=0;}
CS5460APulseClock();
WriteByte=WriteByte<<1;
}
for(BitCounter=0;BitCounter<24;BitCounter++)//write 24 bits
{
if(WriteLong & 0x00800000){CS5460ADin=1;}else{CS5460ADin=0;}
CS5460APulseClock();
WriteLong=WriteLong<<1;
}
return;
}
//===========================================================================
Byte4 CS5460ARead24Bits(Byte AdcRegisterAddress)
{
Byte xdata BitCounter=0;
//send read command with register address
Byte xdata WriteByte=CS5460A_READ & AdcRegisterAddress;
Byte4 xdata Data24Bits=0;
Byte4 xdata ThreeSync0=0x00FEFEFE;
CS5460ADout=1;//pull up port pin for a read
for(BitCounter=0;BitCounter<8;BitCounter++)
{
if(WriteByte & 0x80){CS5460ADin=1;}else{CS5460ADin=0;}
CS5460APulseClock();
WriteByte=WriteByte<<1;
}
for(BitCounter=0;BitCounter<24;BitCounter++)//read 24 bits
{
if(ThreeSync0 & 0x00800000){CS5460ADin=1;}else{CS5460ADin=0;}//SYNC0 command on SDI
CS5460APulseClock();+++++++++++++++++++++++++++++++++++++
ThreeSync0=ThreeSync0<<1;
if(CS5460ADout){Data24Bits=((Data24Bits<<1)| 0x1);}//get msb and other bits
else{Data24Bits=Data24Bits<<1;}
}
return(Data24Bits>>1 & 0x00FFFFFF);+++++++++++++++++++++++++
}
//===========================================================================
void CS5460APulseClock(void){CS5460AClk=1;CS5460AClk=0;return;}
//===========================================================================
// MAIN Routine
//===========================================================================
void main (void)
{
CS5460AClk=0;
CS5460AResetConfigure();
Delay10MilliSec(100);
if(CS5460AReadCRDYBit()){Va=1;}
Gain=CS5460ARead24Bits(CS5460A_REG_VOLT);//dummy read
//===========================================================================
while(1)
{
if(CS5460AReadCRDYBit())
{
//CS5460AWrite24Bits(STATUS_CLR_DRDY,CS5460A_REG_STATUS);//clear DRDY
//Test=CS5460ARead24Bits(CS5460A_REG_IRMS);
Test=CS5460ARead24Bits(CS5460A_REG_CURRENT);
Volt=CS5460ARead24Bits(CS5460A_REG_VOLT);
CS5460AWrite24Bits(STATUS_CLR_CRDY,CS5460A_REG_STATUS);//clear CRDY
}
}//end of while
}//end of main
//===========================================================================
//end of main
//===========================================================================


Hope this helps,
John.

List of 9 messages in thread
TopicAuthorDate
ATTENTION:CS5460A CODE HERE CANNOT WORK      Li Jumen      07/24/11 23:00      
   How to post legible source code      Andy Neil      07/25/11 00:24      
   ATTENTION:be specific      Stefan KAnev      07/25/11 12:29      
      Must be the register address      John D. Maniraj      07/26/11 06:49      
         i'm sorrry,      Stefan KAnev      07/26/11 11:55      
            #Define and other      Li Jumen      07/27/11 01:20      
               Very pleased to share?      Andy Neil      07/27/11 02:43      
               congratulations      Stefan KAnev      07/27/11 22:01      
                  Probably the first version      John D. Maniraj      07/28/11 10:37      

Back to Subject List