Boa tarde,

Estou trabalhando em um TCC usando o CI CS5463 para medir o fator de potência e outras grandezas também, minha ideia é desenvolver um controlador de FP que acione bancos de capacitores, mas que seja um projeto aberto que possa ser montado facilmente, tendo em vista que os controladores comerciais são caríssimos.

Já montei o circuito com o CS e agora estou partindo para a comunicação SPI com o Arduino, preciso escrever em alguns registradores do CS e também ler alguns. Já li bastante coisa na internet sobre SPI e estou estudando o exemplo de código que vem na IDE do arduino mas ainda está um pouco difícil de entender a sintaxe do código.

Se alguém puder me dar uma ajuda ou sugerir algum material para eu estudar agradeceria bastante.

Exibições: 11391

Anexos

Responder esta

Respostas a este tópico

não aposentado .... sim, DISPONÍVEL ! kkkk

Então eu preciso primeiro concatenar o H_Byte, M_Byte e L_Byte para formar um único número em hexa e depois converter o valor para decima e aplicar na fórmula?

Por exemplo se:

H_Byte = 10010110

M_Byte = 1001001

L_Byte = 1011100

X = 1001 0110     0100 1001       0101 1100

Em hexa:

X = 96495C

Como o MSB é 1 o número é negativo e excluo o MSB fica então:

X = 0001 0110    0100 1001     0101 1100

Em Hexa:

X = 16495C

Em decimal:

X = 1460572

Aplicando na fórmula:

Valor Dec = {[ 1 / (8388608 -1) ] x 1460572} - (1)

Valor Dec = {[ 1 / (8388608 -1) ] x 1460572} - (1)

Valor Dec = -0.82588

Bom dia Alan , 

Valor Dec = {[ 1 / (8388608 -1) ] x 1460572} - (1)

Valor Dec = { 1460572 / 8388607 } - (1) = 0,17411377 - 1 

Valor Dec = -0.82588

Correto !!! É isso aí , desde que o registrador seja no formato que eu informei. 

Veja que existem outros formatos. 

3) Fórmula de conversão : 

 Terceiro Formato é muito parecido com o primeiro Formato. 

 A única diferença é que o bit MSB sempre será ZERO. 

Explicando melhor essa fórmula :  

   2^23 = 8.388.608

0 <= Valor Decimal  < 1.0 ( isto é, o valor mínimo é 0 e o valor máximo é 1,0) 

Valor decimal = [ 1 / ( 2^23 - 1) ] x Hexto Dec ( Valor Hexadecimal) 


Para converter o número hexadecimal para decimal acesse esse link :

http://www.binaryhexconverter.com/hex-to-decimal-converter

Essa terceira  fórmula poderá ser usada  para esses registradores :

6.1.17 Reactive Power Register ( QTrig )
Address: 24

6.1.19 Apparent Power Register ( S )
Address: 27

6.3.2 Voltage Sag and Current Fault Level Registers ( VSAGLevel , ISAGLevel )
Address: 7 (Voltage Sag Level ); 11 (Current Fault Level )

CS5463 - Sketch conversão do registrador do Terceiro Formato  

Ao invés de fazer planilhas de verificação dos cálculos, resolvi fazer os Sketches de conversão 

dos registradores em valores decimais . Não sou programador, mas fiz o melhor que pude. 

No sketch citei cinco exemplos de registradores com Formato 3 e seus valores decimais correspondentes. 

[code]
// CS5463 Register calculations - Register Format 3
// Arduino Nano - IDE 1.6.7
// Gustavo Murta - 28/jul/2016

// CS5463 Register format 3
// two's complement notation
// Value decimal = [ 1 / ( 2^23 - 1) ] x HexToDec ( Value Hexadecimal)

// 6.1.19 Apparent Power Register ( S ) Address: 27
// 6.1.17 Reactive Power Register ( QTrig ) Address: 24
// 6.3.2 Voltage Sag and Current Fault Level Registers ( VSAGLevel , ISAGLevel )
// Address: 7 (Voltage Sag Level ); 11 (Current Fault Level )

float CS5463_PowerApparent = 0;
float Example, Example1, Example2, Example3, Example4, Example5 ;
long HexaValue ;

void setup()
{
Serial.begin(9600);
Serial.println ("Examples - CS5463 Register Format 3");
Serial.println ();

Example1 = 0x2E147B ;    // Converts 0x2E147B to 0.360000
Example2 = 0x73D35A ;    // Converts 0x73D35A to 0.904888
Example3 = 0x000000 ;     // Converts 0x000000 to 0
Example4 = 0x7FFFFF ;   // Converts 0x7FFFFF to 1.000000
Example5 = 0x0FFFFF ;   // Converts 0x0FFFFF to 0.125000

Example = Example1 ;
Print_PowerApparent() ;

Example = Example2 ;
Print_PowerApparent() ;

Example = Example3 ;
Print_PowerApparent() ;

Example = Example4 ;
Print_PowerApparent() ;

Example = Example5 ;
Print_PowerApparent() ;
}

void Print_PowerApparent()
{
HexaValue = Example;                                   // converts float value in long
String StringHexa = String(HexaValue,HEX);    // converts Hexa to String
CS5463_PowerApparent = Example / 8388607 ; // two's complement notation ( 2^23 - 1) = 8388607
Serial.print (StringHexa);                                // Prints Hexadecimal String
Serial.print (" = ");
Serial.println (CS5463_PowerApparent,6) ; // Prints Decimal Value with six digits after decimal point
}

void loop()
{
}
[/code]

 

Anexei o Sketch      CS5463_REG3.ino 

Anexos

CS5463 - Sketch conversão do registrador do Primeiro Formato  

No sketch citei cinco exemplos de registradores com Formato 1 e seus valores decimais correspondentes. 

Alan , baseie-me em algumas linhas do seu código. 

Mas ainda me resta uma dúvida : será que o calculo dos valores decimais negativos esta realmente correto ? 

[code]
// CS5463 Register calculations - Register Format 1
// Arduino Nano - IDE 1.6.7
// Gustavo Murta - 28/jul/2016

// CS5463 Register format 1
// two's complement notation -1.0 <= Decimal Value < 1.0
// Value decimal = {[ 1 / ( 2^23 - 1) ] x HexToDec ( Value Hexadecimal)} - MSB

// 6.1.2 Current and Voltage DC Offset Register ( IDCoff , VDCoff )
// Address: 1 (Current DC Offset); 3 (Voltage DC Offset)
// 6.1.6 Instantaneous Current, Voltage, and Power Registers ( I , V , P )
// Address: 7 (Instantaneous Current); 8 (Instantaneous Voltage); 9 (Instantaneous Power)
// 6.1.7 Active (Real) Power Register ( PActive ) Address: 10 (Active Power)
// and much more registers !

 float CS5463_PowerActive = 0;
 float Example, Example1, Example2, Example3, Example4, Example5;
 long HexaValue;
 long MSB_Mask = 0x800000; // MSB bit equals One

void setup()
{
 Serial.begin(9600);
 Serial.println ("Examples - CS5463 Register Format 1");
 Serial.println ();

 Example1 = 0x2E147B ;              // Converts 0x2E147B to 0.360000
 Example2 = 0xF3D35A ;              // Converts 0xF3D35A to -0.095112
 Example3 = 0xFFF000 ;               // Converts 0xFFF000 to -0.000488
 Example4 = 0x7FFFFF ;              // Converts 0x7FFFFF to 1.000000
 Example5 = 0x8F0000 ;               // Converts 0x8F0000 to -0.882812


Example = Example1 ;
Print_PowerActive();

Example = Example2 ;
Print_PowerActive();

Example = Example3 ;
Print_PowerActive();

Example = Example4 ;
Print_PowerActive();

Example = Example5 ;
Print_PowerActive();
}

 void Print_PowerActive()
{
    HexaValue = Example;                                      // converts float value in long
    String StringHexa = String(HexaValue,HEX);       // converts Hexa to String

if ((HexaValue & MSB_Mask) == 0)                        // Verifying if MSB Bit equals Zero
{
    CS5463_PowerActive = Example / 8388607 ;      // two's complement notation ( 2^23 - 1) = 8388607
}
else                                                                      // if MSB Bit equals One
{
    Example = Example - 0x800000;                        // Remove MSB bit
    CS5463_PowerActive = (Example / 8388607) - 1 ; // {[1/(2^23 - 1)] x HexToDec(Value Hexadecimal)} - MSB
}

   Serial.print (StringHexa);                                     // Prints Hexadecimal String
   Serial.print (" = ");
   Serial.println (CS5463_PowerActive,6) ;   // Prints Decimal Value with six digits after decimal point
}

void loop()
{
}
[/code]

Anexei o Sketch CS5463_REG1,ino

Anexos

CS5463 -  convertendo os valores dos registradores  ( continuação - Segundo Formato) :

Como eu já havia dito, existem alguns tipos de registradores no Chip CS5463. 

Esse é o segundo formato :

==================================================

2) Fórmula de conversão :

Explicando melhor essa fórmula :  

   2^24 = 16.777.216

0 <= Valor Decimal  < 1.0 ( isto é, o valor mínimo é 0 e o valor máximo é 1,0) 

   Valor decimal =  [ 1 / ( 2^24 - 1) ] x Hexto Dec ( Valor Hexadecimal) 


Para converter o número hexadecimal para decimal acesse esse link :

http://www.binaryhexconverter.com/hex-to-decimal-converter

Exemplo: 

a)  Convertendo  0x5C28F6 em decimal  0,36 

0x5C28F6 = 6039798  ( usando o link de conversão HEX para DEC ) 

Valor Dec = [ 1 / (16777216 -1) ] x 6039798

Valor Dec =  6039798 / 16777215  = 0,3600 !! 

Esse é o  registrador do CS5463 que usa esse procedimento de conversão ( veja no Datasheet do CS5463) : 

6.1.8 RMS Current & Voltage Registers ( IRMS , VRMS )
Address: 11 (IRMS); 12 (VRMS)

CS5463 - Sketch conversão do registrador do Segundo Formato  

No sketch citei cinco exemplos de registradores com Formato 2 e seus valores decimais correspondentes. 

Vejam que os resultados são diferentes do Formato 3, para os mesmos valores nos registradores.

[code]
// CS5463 Register calculations - Register Format 2
// Arduino Nano - IDE 1.6.7
// Gustavo Murta - 28/jul/2016

// CS5463 Register format 2
// two's complement notation
// Value decimal = [ 1 / ( 2^24 - 1) ] x HexToDec ( Value Hexadecimal)

// 6.1.8 RMS Current & Voltage Registers ( IRMS , VRMS )
// Address: 11 (IRMS); 12 (VRMS)

float CS5463_PowerApparent = 0;
float Example, Example1, Example2, Example3, Example4, Example5 ;
long HexaValue ;

void setup()
{
Serial.begin(9600);
Serial.println ("Examples - CS5463 Register Format 2");
Serial.println ();

Example1 = 0x5C28F6 ;         // Converts 0x5C28F6 to 0.360000
Example2 = 0x73D35A ;         // Converts 0x73D35A to 0.452444
Example3 = 0x000000 ;          // Converts 0x000000 to 0
Example4 = 0x7FFFFF ;         // Converts 0x7FFFFF to 0.500000
Example5 = 0xFFFFFF ;        // Converts 0x0FFFFF to 1.000000

Example = Example1 ;
Print_PowerApparent() ;

Example = Example2 ;
Print_PowerApparent() ;

Example = Example3 ;
Print_PowerApparent() ;

Example = Example4 ;
Print_PowerApparent() ;

Example = Example5 ;
Print_PowerApparent() ;
}

void Print_PowerApparent()
{
HexaValue = Example;                                    // converts float value in long
String StringHexa = String(HexaValue,HEX);     // converts Hexa to String
CS5463_PowerApparent = Example / 16777215; // two's complement notation ( 2^24 - 1) = 16777215
Serial.print (StringHexa);                                 // Prints Hexadecimal String
Serial.print (" = ");
Serial.println (CS5463_PowerApparent,6) ;       // Prints Decimal Value with six digits after decimal point
}

void loop()
{
}
[/code]

Anexei o Sketch      CS5463_REG2.ino  

Anexos

CS5463 -  convertendo os valores dos registradores  ( continuação - Quarto Formato) :

Mais um  tipo de registrador no Chip CS5463 usado em :

6.1.3 Current and Voltage Gain Register ( Ign , Vgn )
Address: 2 (Current Gain); 4 (Voltage Gain)

Esse é o quarto  formato :

==================================================

4) Fórmula de conversão :

           0.0 <=  Valor Decimal  < 3.9999  ( isto é, o valor mínimo é 0 e o valor máximo é 3,9999 ) 

    Para esse registrador  eu não achei a fórmula, mas através de dedução ( acho que é assim) 

     Bits MSB 

     2^1 = peso 2    e 2^0 = peso 1 

     ex:  1 1 = 3    /   1 0 = 2    /   0 1 = 1   /     0 0 = 0 

 Os outros bits servem para calcular a parte flutuante ( décimos de inteiro) . 

 Valor decimal =  [ 1 / ( 2^22 - 1) ] x Hexto Dec ( Valor Hexadecimal) 

  2^22 = 4194304


Para converter o número hexadecimal para decimal acesse esse link :

http://www.binaryhexconverter.com/hex-to-decimal-converter 

a) Fazendo um teste - 0x A6 66 66 = 2,6  ( será que estou certo ?) 

Primeiros dois Bits MSB -  valor decimal = 2 

Os outros bits = 0x 26 66 66 convertidos para decimal = 2516582

Valor decimal =  [ 1 / ( 4194304 - 1) ] x 2516582

Valor decimal = [ 1 /4194303 ] x 2516582  = 2516582 / 4194303 =0,600

b) Fazendo um teste -  0x 40 00 00 = 1,0 ( essa conversão esta no Datasheet) 

Primeiros dois Bits MSB -  valor decimal = 1 

Os outros bits = 00 00 00  convertidos para decimal = 0

Valor decimal =  [ 1 / ( 4194304 - 1) ] x 0 = 0 

Boa tarde,

Projeto evoluindo graças a ajuda do José Gustavo que desvendou o mistério.

Em anexo o código que estou usando, está bem bagunçado ainda mas acho que pode ajudar.

Abaixo as leituras que consegui na serial e com o wattímetro.

Tensao: 122.97
Corrente: 3.50
Pot. Real: 339.23
 
Tensao: 123.05
Corrente: 3.46
Pot. Real: 335.77
 
Tensao: 123.06
Corrente: 3.46
Pot. Real: 335.77
 
Tensao: 123.10
Corrente: 3.47
Pot. Real: 335.77
 
Tensao: 122.76
Corrente: 3.47
Pot. Real: 335.77
 
Tensao: 122.99
Corrente: 3.48
Pot. Real: 339.23

A potência não deu para ajustar com mais precisão pois como estava medindo no quadro de entrada da casa (na fase que alimenta toda a casa) a potência estava oscilando e o computador está em outro cômodo ficou difícil definir um multiplicador mais preciso. Mais pra frente vou calibrar melhor com uma carga mais estável para definir o multiplicador mais precisamente. Aceito sugestões para melhorar o código.

Anexos

Alan , que bom ! Fiquei feliz que esta avançando nas medições ! 

Que legal ! 

Ainda estou estudando todos os formatos. Ontem saiu até uma fumaçinha, de tanto pensar... KKKK

Tenho muitas dúvidas ainda, mas a gente esta avançando. 

Abraços, 

Gustavo Murta 

CS5463 -  convertendo os valores dos registradores  ( continuação - Quinto Formato) :

Mais um  tipo de registrador no Chip CS5463 usado em :

6.3.1 Voltage Sag and Current Fault Duration Registers ( VSAGDuration , ISAGDuration )
Address: 6 (Voltage Sag Duration); 10 (Current Fault Duration)

5) Fórmula de conversão :

Esse valor é representado na notação sem sinal . 

Esse é um dos registradores mais fáceis para entendimento, pois usa a notação binária normal . 

Mas veja que o Bit MSB será sempre ZERO. 

 Valor decimal =  Hexto Dec ( Valor Hexadecimal) 

Para converter o número hexadecimal para decimal acesse esse link :

http://www.binaryhexconverter.com/hex-to-decimal-converter 

Mas para efeito de testes das formulas , montei essa planilha para a conversão dos registradores em valores decimais. Pretendo fazer uma planilha para cada um dos formatos ( se eu  conseguir). Preencha os bits ( 1 ou 0)  nos campos e terá o valor decimal calculado ( campo azul). Não procurei no Excel ainda, uma formula para decompor um numero hexadecimal em bits. 

Anexei a planilha = CS5463 Registradores formato 5 

Anexos

RSS

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço