PRESA Raphaël
/
essai_DS1621
capteur DS1621
Main.cpp@0:78facd7c14b8, 2020-05-20 (annotated)
- Committer:
- rpresa
- Date:
- Wed May 20 12:03:32 2020 +0000
- Revision:
- 0:78facd7c14b8
essai DS1621
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rpresa | 0:78facd7c14b8 | 1 | #include "ds1621.h" |
rpresa | 0:78facd7c14b8 | 2 | |
rpresa | 0:78facd7c14b8 | 3 | |
rpresa | 0:78facd7c14b8 | 4 | |
rpresa | 0:78facd7c14b8 | 5 | #define DS1621_ADDR 0x90 // I2c DS1621 address is 0x00 |
rpresa | 0:78facd7c14b8 | 6 | |
rpresa | 0:78facd7c14b8 | 7 | Serial pc(USBTX, USBRX); // port série USB |
rpresa | 0:78facd7c14b8 | 8 | //pins are: TX RX |
rpresa | 0:78facd7c14b8 | 9 | |
rpresa | 0:78facd7c14b8 | 10 | |
rpresa | 0:78facd7c14b8 | 11 | I2C i2c(p9, p10); // Declare I2C (pullup resistors 2.2k from p9 and p10 to +5v) |
rpresa | 0:78facd7c14b8 | 12 | DS1621 ds(&i2c, DS1621_ADDR); // Declare ds1621 throught i2c interface |
rpresa | 0:78facd7c14b8 | 13 | |
rpresa | 0:78facd7c14b8 | 14 | |
rpresa | 0:78facd7c14b8 | 15 | |
rpresa | 0:78facd7c14b8 | 16 | |
rpresa | 0:78facd7c14b8 | 17 | float Temperature = 24.0, |
rpresa | 0:78facd7c14b8 | 18 | Temp_H=25.0, |
rpresa | 0:78facd7c14b8 | 19 | Temp_L=23.0, |
rpresa | 0:78facd7c14b8 | 20 | Temp_cons=35, |
rpresa | 0:78facd7c14b8 | 21 | hysteresis=5.0, |
rpresa | 0:78facd7c14b8 | 22 | periode=1.0; // acquisition toutes les secondes |
rpresa | 0:78facd7c14b8 | 23 | |
rpresa | 0:78facd7c14b8 | 24 | unsigned char trame[6]; |
rpresa | 0:78facd7c14b8 | 25 | int cpt=0; // compteur trame |
rpresa | 0:78facd7c14b8 | 26 | int flag=0; // detection de debut de trame |
rpresa | 0:78facd7c14b8 | 27 | int etat_regulation=0; // =0 pas de regulation =1 regulation |
rpresa | 0:78facd7c14b8 | 28 | int Sortie_reg=0; // etat sortie reg du DS1621 |
rpresa | 0:78facd7c14b8 | 29 | |
rpresa | 0:78facd7c14b8 | 30 | |
rpresa | 0:78facd7c14b8 | 31 | |
rpresa | 0:78facd7c14b8 | 32 | int main() { |
rpresa | 0:78facd7c14b8 | 33 | i2c.frequency(5000); //5khz |
rpresa | 0:78facd7c14b8 | 34 | pc.printf("-----------------------\n\rMain\n\r"); |
rpresa | 0:78facd7c14b8 | 35 | char reg; |
rpresa | 0:78facd7c14b8 | 36 | int result; |
rpresa | 0:78facd7c14b8 | 37 | |
rpresa | 0:78facd7c14b8 | 38 | |
rpresa | 0:78facd7c14b8 | 39 | |
rpresa | 0:78facd7c14b8 | 40 | ds.SetConfig(0x00); // POL=1, 1SHOT=0 |
rpresa | 0:78facd7c14b8 | 41 | wait(1); |
rpresa | 0:78facd7c14b8 | 42 | reg=ds.ReadReg(ACCESS_CONFIG); // lecture registre CONFIG pour controle |
rpresa | 0:78facd7c14b8 | 43 | pc.printf("REG=%d\n\r",reg); |
rpresa | 0:78facd7c14b8 | 44 | ds.SetLimit(ACCESS_TH,-20); // fixe TH: valeur basse pour avoir commande de sortie =0 |
rpresa | 0:78facd7c14b8 | 45 | wait(1); |
rpresa | 0:78facd7c14b8 | 46 | ds.SetLimit(ACCESS_TL, -21.0); // fixe TL: valeur basse pour avoir commande de sortie =0 |
rpresa | 0:78facd7c14b8 | 47 | wait(1); |
rpresa | 0:78facd7c14b8 | 48 | |
rpresa | 0:78facd7c14b8 | 49 | ds.StartConversion(1); |
rpresa | 0:78facd7c14b8 | 50 | wait(1); |
rpresa | 0:78facd7c14b8 | 51 | |
rpresa | 0:78facd7c14b8 | 52 | result=ds.GetTemp(ACCESS_TL,&Temp_L); |
rpresa | 0:78facd7c14b8 | 53 | if(result==1) pc.printf("TL=%3.1f\n\r",Temp_L); |
rpresa | 0:78facd7c14b8 | 54 | wait(1); |
rpresa | 0:78facd7c14b8 | 55 | result= ds.GetTemp(ACCESS_TH,&Temp_H); |
rpresa | 0:78facd7c14b8 | 56 | if(result==1) pc.printf("TH=%3.1f\n\r",Temp_H); |
rpresa | 0:78facd7c14b8 | 57 | wait(1); |
rpresa | 0:78facd7c14b8 | 58 | |
rpresa | 0:78facd7c14b8 | 59 | while (1) { |
rpresa | 0:78facd7c14b8 | 60 | result= ds.GetTemp(READ_TEMPERATURE,&Temperature); // acquisition Temp à 0.5 |
rpresa | 0:78facd7c14b8 | 61 | //result= ds.GetHResTemp(&Temperature); // acquisition Temp à 0.1 °C |
rpresa | 0:78facd7c14b8 | 62 | pc.printf("Temperature=%3.1f C\n\r",Temperature); |
rpresa | 0:78facd7c14b8 | 63 | wait(1); |
rpresa | 0:78facd7c14b8 | 64 | } |
rpresa | 0:78facd7c14b8 | 65 | } |