Dependencies: gmc_devices mbed
main.cpp@0:608e5ac0189e, 2014-07-11 (annotated)
- Committer:
- wbeaumont
- Date:
- Fri Jul 11 14:22:13 2014 +0000
- Revision:
- 0:608e5ac0189e
NENEMNIX temperature readout , for details check tech doc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 0:608e5ac0189e | 1 | #include "mbed.h" |
wbeaumont | 0:608e5ac0189e | 2 | #include "ds1621.hpp" |
wbeaumont | 0:608e5ac0189e | 3 | |
wbeaumont | 0:608e5ac0189e | 4 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
wbeaumont | 0:608e5ac0189e | 5 | PinName const SDA = PTE25; |
wbeaumont | 0:608e5ac0189e | 6 | PinName const SCL = PTE24; |
wbeaumont | 0:608e5ac0189e | 7 | #elif defined (TARGET_KL05Z) |
wbeaumont | 0:608e5ac0189e | 8 | PinName const SDA = PTB4; |
wbeaumont | 0:608e5ac0189e | 9 | PinName const SCL = PTB3; |
wbeaumont | 0:608e5ac0189e | 10 | #else |
wbeaumont | 0:608e5ac0189e | 11 | #error TARGET NOT DEFINED |
wbeaumont | 0:608e5ac0189e | 12 | #endif |
wbeaumont | 0:608e5ac0189e | 13 | |
wbeaumont | 0:608e5ac0189e | 14 | #define VERSION 25 |
wbeaumont | 0:608e5ac0189e | 15 | //#define DEBUGPF(x) printf((x)); |
wbeaumont | 0:608e5ac0189e | 16 | #define DEBUGPF(x) |
wbeaumont | 0:608e5ac0189e | 17 | Serial pc(USBTX,USBRX); |
wbeaumont | 0:608e5ac0189e | 18 | |
wbeaumont | 0:608e5ac0189e | 19 | |
wbeaumont | 0:608e5ac0189e | 20 | char c='.'; |
wbeaumont | 0:608e5ac0189e | 21 | void callback() { |
wbeaumont | 0:608e5ac0189e | 22 | // Note: you need to actually read from the serial to clear the RX interrupt |
wbeaumont | 0:608e5ac0189e | 23 | |
wbeaumont | 0:608e5ac0189e | 24 | c = pc.getc(); |
wbeaumont | 0:608e5ac0189e | 25 | printf("%c:",c ); |
wbeaumont | 0:608e5ac0189e | 26 | |
wbeaumont | 0:608e5ac0189e | 27 | |
wbeaumont | 0:608e5ac0189e | 28 | } |
wbeaumont | 0:608e5ac0189e | 29 | |
wbeaumont | 0:608e5ac0189e | 30 | I2C i2cT(SDA, SCL); |
wbeaumont | 0:608e5ac0189e | 31 | #define THIST 20 |
wbeaumont | 0:608e5ac0189e | 32 | #define NRSENS 2 |
wbeaumont | 0:608e5ac0189e | 33 | int main(void) { |
wbeaumont | 0:608e5ac0189e | 34 | |
wbeaumont | 0:608e5ac0189e | 35 | i2cT.frequency(100000); |
wbeaumont | 0:608e5ac0189e | 36 | pc.attach(&callback); |
wbeaumont | 0:608e5ac0189e | 37 | |
wbeaumont | 0:608e5ac0189e | 38 | DS1621 digT1(&i2cT,0x90); |
wbeaumont | 0:608e5ac0189e | 39 | DS1621 digT2(&i2cT,0x96); |
wbeaumont | 0:608e5ac0189e | 40 | |
wbeaumont | 0:608e5ac0189e | 41 | DS1621* digT[NRSENS]={&digT1,&digT2}; |
wbeaumont | 0:608e5ac0189e | 42 | float tmpsum[NRSENS]; |
wbeaumont | 0:608e5ac0189e | 43 | float temphist[NRSENS][THIST]; |
wbeaumont | 0:608e5ac0189e | 44 | float digTemp[NRSENS]; |
wbeaumont | 0:608e5ac0189e | 45 | DEBUGPF("init hw done \n\r"); |
wbeaumont | 0:608e5ac0189e | 46 | int lc=0; |
wbeaumont | 0:608e5ac0189e | 47 | while (true) { |
wbeaumont | 0:608e5ac0189e | 48 | for (int ns=0; ns<NRSENS; ns++) digT[ns]->init_meassure(); |
wbeaumont | 0:608e5ac0189e | 49 | DEBUGPF("init meas "); |
wbeaumont | 0:608e5ac0189e | 50 | for (int ns=0; ns<NRSENS; ns++) digT[ns]->init_read(); |
wbeaumont | 0:608e5ac0189e | 51 | |
wbeaumont | 0:608e5ac0189e | 52 | wait(0.1); |
wbeaumont | 0:608e5ac0189e | 53 | |
wbeaumont | 0:608e5ac0189e | 54 | for (int ns=0; ns<NRSENS; ns++){ |
wbeaumont | 0:608e5ac0189e | 55 | digTemp[ns]= digT[ns]->read_T(); |
wbeaumont | 0:608e5ac0189e | 56 | temphist[ns][lc]=digTemp[ns]; |
wbeaumont | 0:608e5ac0189e | 57 | tmpsum[ns]=0; |
wbeaumont | 0:608e5ac0189e | 58 | for (int lc2=0; lc2 < THIST;lc2++) { |
wbeaumont | 0:608e5ac0189e | 59 | tmpsum[ns]+=temphist[ns][lc2]; |
wbeaumont | 0:608e5ac0189e | 60 | } |
wbeaumont | 0:608e5ac0189e | 61 | tmpsum[ns]/=THIST; |
wbeaumont | 0:608e5ac0189e | 62 | } |
wbeaumont | 0:608e5ac0189e | 63 | switch (c) { |
wbeaumont | 0:608e5ac0189e | 64 | case 't' : |
wbeaumont | 0:608e5ac0189e | 65 | { for (int ns=0; ns<NRSENS; ns++) { printf("ch %03d %2.4f %2.4f ",ns, digTemp[ns], tmpsum[ns] );} |
wbeaumont | 0:608e5ac0189e | 66 | printf("\n\r" ); |
wbeaumont | 0:608e5ac0189e | 67 | |
wbeaumont | 0:608e5ac0189e | 68 | } |
wbeaumont | 0:608e5ac0189e | 69 | break; |
wbeaumont | 0:608e5ac0189e | 70 | case 'v' : printf("version: %02d compiled date %s time :%s \n\r",VERSION,__DATE__,__TIME__); |
wbeaumont | 0:608e5ac0189e | 71 | break; |
wbeaumont | 0:608e5ac0189e | 72 | case 'i' : |
wbeaumont | 0:608e5ac0189e | 73 | case 'h' : |
wbeaumont | 0:608e5ac0189e | 74 | printf("DS1621 readout\n\r"); |
wbeaumont | 0:608e5ac0189e | 75 | printf("\tt: gives for each channel current temperture\n\r\t\tand average temperature over last 10 sampels, format:\n\r"); |
wbeaumont | 0:608e5ac0189e | 76 | printf("\t\tt:ch 000 26.5000 26.5000 ch 001 26.0000 26.0000\n\r\tv gives version\n\r"); |
wbeaumont | 0:608e5ac0189e | 77 | printf("(C) Wim Beaumont Universiteit Antwerpen Belgium\n\r"); |
wbeaumont | 0:608e5ac0189e | 78 | printf(" mail : Wim.Beaumont_AT_uantwerpen.be\n\r"); |
wbeaumont | 0:608e5ac0189e | 79 | break; |
wbeaumont | 0:608e5ac0189e | 80 | default: ;// nothing |
wbeaumont | 0:608e5ac0189e | 81 | }; |
wbeaumont | 0:608e5ac0189e | 82 | c='.'; |
wbeaumont | 0:608e5ac0189e | 83 | lc++; if (lc >= THIST) lc=0; |
wbeaumont | 0:608e5ac0189e | 84 | |
wbeaumont | 0:608e5ac0189e | 85 | } |
wbeaumont | 0:608e5ac0189e | 86 | } |