asd

Committer:
vitlog
Date:
Mon Jun 22 09:52:01 2020 +0000
Revision:
0:9a5218876095
Tozhe ne pomnyu

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vitlog 0:9a5218876095 1 #include "ad5422_arduino.h"
vitlog 0:9a5218876095 2 #include "PGA280.h"
vitlog 0:9a5218876095 3 #include <math.h>
vitlog 0:9a5218876095 4 #include "PerifConfig.h"
vitlog 0:9a5218876095 5 #include <stdbool.h>
vitlog 0:9a5218876095 6
vitlog 0:9a5218876095 7
vitlog 0:9a5218876095 8 void ad5422_resetDevice ( unsigned char adr )
vitlog 0:9a5218876095 9 {
vitlog 0:9a5218876095 10 pga280_setAdress ( adr );
vitlog 0:9a5218876095 11 ADS1259_RESET = 0;
vitlog 0:9a5218876095 12
vitlog 0:9a5218876095 13 wait_ms ( 1 ); // ??? 1 Mhz 70
vitlog 0:9a5218876095 14
vitlog 0:9a5218876095 15 ADS1259_RESET = 1;
vitlog 0:9a5218876095 16 pga280_resetAdress ();
vitlog 0:9a5218876095 17 }
vitlog 0:9a5218876095 18
vitlog 0:9a5218876095 19 void ad5422_powerDownDevice ( unsigned char adr )
vitlog 0:9a5218876095 20 {
vitlog 0:9a5218876095 21 pga280_setAdress ( adr );
vitlog 0:9a5218876095 22
vitlog 0:9a5218876095 23 ADS1259_RESET = 0;
vitlog 0:9a5218876095 24
vitlog 0:9a5218876095 25 pga280_resetAdress ();
vitlog 0:9a5218876095 26 }
vitlog 0:9a5218876095 27
vitlog 0:9a5218876095 28 void ad5422_powerUpDevice ( unsigned char adr )
vitlog 0:9a5218876095 29 {
vitlog 0:9a5218876095 30 pga280_setAdress ( adr );
vitlog 0:9a5218876095 31
vitlog 0:9a5218876095 32 ADS1259_RESET = 1;
vitlog 0:9a5218876095 33
vitlog 0:9a5218876095 34 pga280_resetAdress ();
vitlog 0:9a5218876095 35 }
vitlog 0:9a5218876095 36
vitlog 0:9a5218876095 37 char ad5422_readyDevice ( unsigned char ch )
vitlog 0:9a5218876095 38 {
vitlog 0:9a5218876095 39 char tmp;
vitlog 0:9a5218876095 40
vitlog 0:9a5218876095 41 pga280_setAdress ( ch );
vitlog 0:9a5218876095 42
vitlog 0:9a5218876095 43 if ( CRDYA == 0 )
vitlog 0:9a5218876095 44 tmp = true;
vitlog 0:9a5218876095 45 else
vitlog 0:9a5218876095 46 tmp = false;
vitlog 0:9a5218876095 47
vitlog 0:9a5218876095 48 pga280_resetAdress ();
vitlog 0:9a5218876095 49
vitlog 0:9a5218876095 50 return tmp;
vitlog 0:9a5218876095 51 }
vitlog 0:9a5218876095 52
vitlog 0:9a5218876095 53 char ad5422_sendCommandDevice ( unsigned char reg, unsigned char high_byte, unsigned char low_byte, unsigned char adr )
vitlog 0:9a5218876095 54 {
vitlog 0:9a5218876095 55 pga280_setAdress ( adr );
vitlog 0:9a5218876095 56
vitlog 0:9a5218876095 57 CS = 0;
vitlog 0:9a5218876095 58 SPI1MasterTransferByte ( reg );
vitlog 0:9a5218876095 59 SPI1MasterTransferByte( high_byte );
vitlog 0:9a5218876095 60 SPI1MasterTransferByte( low_byte );
vitlog 0:9a5218876095 61 CS = 1;
vitlog 0:9a5218876095 62
vitlog 0:9a5218876095 63 pga280_resetAdress ();
vitlog 0:9a5218876095 64
vitlog 0:9a5218876095 65 return true;
vitlog 0:9a5218876095 66 }
vitlog 0:9a5218876095 67
vitlog 0:9a5218876095 68 uint32_t ad5422_readReg ( unsigned char reg, unsigned char adr )
vitlog 0:9a5218876095 69 {
vitlog 0:9a5218876095 70 union {
vitlog 0:9a5218876095 71 struct {
vitlog 0:9a5218876095 72 uint8_t
vitlog 0:9a5218876095 73 b0,
vitlog 0:9a5218876095 74 b1,
vitlog 0:9a5218876095 75 b2;
vitlog 0:9a5218876095 76 };
vitlog 0:9a5218876095 77 uint32_t data;
vitlog 0:9a5218876095 78 }read;
vitlog 0:9a5218876095 79
vitlog 0:9a5218876095 80 pga280_setAdress ( adr );
vitlog 0:9a5218876095 81 CS = 0;
vitlog 0:9a5218876095 82
vitlog 0:9a5218876095 83 SPI1MasterTransferByte( AD5422_READBACK );
vitlog 0:9a5218876095 84 SPI1MasterTransferByte( 0x00 );
vitlog 0:9a5218876095 85 SPI1MasterTransferByte( reg );
vitlog 0:9a5218876095 86
vitlog 0:9a5218876095 87 read.b0 = SPI1MasterReadByte();
vitlog 0:9a5218876095 88 read.b1 = SPI1MasterReadByte();
vitlog 0:9a5218876095 89 read.b2 = SPI1MasterReadByte();
vitlog 0:9a5218876095 90
vitlog 0:9a5218876095 91 CS = 1;
vitlog 0:9a5218876095 92 pga280_resetAdress ();
vitlog 0:9a5218876095 93
vitlog 0:9a5218876095 94 return read.data;
vitlog 0:9a5218876095 95 }
vitlog 0:9a5218876095 96
vitlog 0:9a5218876095 97 unsigned int ad5422_setRegisters ( void )
vitlog 0:9a5218876095 98 {
vitlog 0:9a5218876095 99 ad5422_sendCommandDevice ( AD5422_REG_RESET, 0x00, 0x01, AD5422_ADR );
vitlog 0:9a5218876095 100 ad5422_sendCommandDevice ( AD5422_REG_CONTROL, 0x30, 0b00000001, AD5422_ADR );
vitlog 0:9a5218876095 101 return 1;
vitlog 0:9a5218876095 102 }
vitlog 0:9a5218876095 103
vitlog 0:9a5218876095 104 unsigned int ad5422_setRegistersChannal ( char channal )
vitlog 0:9a5218876095 105 {
vitlog 0:9a5218876095 106 int i;
vitlog 0:9a5218876095 107
vitlog 0:9a5218876095 108 for ( i = 0; i < channal; i++ )
vitlog 0:9a5218876095 109 ad5422_sendCommandDevice ( AD5422_REG_RESET, 0x00, 0x01, AD5422_ADR );
vitlog 0:9a5218876095 110
vitlog 0:9a5218876095 111 wait_ms (1);
vitlog 0:9a5218876095 112
vitlog 0:9a5218876095 113 for ( i = 0; i < channal; i++ )
vitlog 0:9a5218876095 114 ad5422_sendCommandDevice ( AD5422_REG_CONTROL, 0x00, 0x08, AD5422_ADR );
vitlog 0:9a5218876095 115
vitlog 0:9a5218876095 116 wait_ms (1);
vitlog 0:9a5218876095 117
vitlog 0:9a5218876095 118 for ( i = 0; i < channal; i++ )
vitlog 0:9a5218876095 119 ad5422_sendCommandDevice ( AD5422_REG_CONTROL, 0x30, 0x09, AD5422_ADR );
vitlog 0:9a5218876095 120
vitlog 0:9a5218876095 121 wait_ms (1);
vitlog 0:9a5218876095 122
vitlog 0:9a5218876095 123 return 1;
vitlog 0:9a5218876095 124 }
vitlog 0:9a5218876095 125
vitlog 0:9a5218876095 126 unsigned char ad5422_setVoltageChannal ( float voltage, char channal )
vitlog 0:9a5218876095 127 {
vitlog 0:9a5218876095 128 unsigned long tmp;
vitlog 0:9a5218876095 129 float v_ref = 5.2;
vitlog 0:9a5218876095 130 unsigned char gain = 2;
vitlog 0:9a5218876095 131 unsigned int value_output;
vitlog 0:9a5218876095 132 unsigned char value_output_high;
vitlog 0:9a5218876095 133 unsigned char value_output_low;
vitlog 0:9a5218876095 134 int i;
vitlog 0:9a5218876095 135
vitlog 0:9a5218876095 136 tmp = ( voltage / ( v_ref * gain ) ) * 0xFFFF;
vitlog 0:9a5218876095 137 value_output = ( v_ref * gain ) - tmp;
vitlog 0:9a5218876095 138 value_output_high = ( value_output >> 8 ) * 0xFF;
vitlog 0:9a5218876095 139 value_output_low = value_output * 0xFF;
vitlog 0:9a5218876095 140
vitlog 0:9a5218876095 141 for ( i = 0; i < channal; i++ )
vitlog 0:9a5218876095 142 ad5422_sendCommandDevice ( AD5422_REG_DATA, value_output_high, value_output_low, AD5422_ADR );
vitlog 0:9a5218876095 143
vitlog 0:9a5218876095 144 return (0);
vitlog 0:9a5218876095 145 }