2020-12-29 01:26:39 -05:00
|
|
|
/* adcmain.c -- ADC reading of reference voltage and temperature sensor */
|
2021-06-30 00:09:11 -04:00
|
|
|
/* Copyright (c) 2020-2021 Renaud Fivet */
|
2020-12-29 01:26:39 -05:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
#define RAW
|
|
|
|
|
2021-07-01 01:23:19 -04:00
|
|
|
#define TS_CAL2 ((const short *) 0x1FFFF7C2)
|
|
|
|
#define USER0 ((const unsigned char *) 0x1FFFF804)
|
|
|
|
|
2020-12-29 01:26:39 -05:00
|
|
|
int main( void) {
|
|
|
|
unsigned last = 0 ;
|
|
|
|
short calV, calC ;
|
|
|
|
|
|
|
|
/* Initialize ADC and fetch calibration values */
|
|
|
|
adc_vnt( VNT_INIT, &calV, &calC) ;
|
|
|
|
#ifdef RAW
|
|
|
|
printf( "%u, %u\n", calV, calC) ;
|
2021-07-01 01:23:19 -04:00
|
|
|
|
|
|
|
int baseC = 300 ;
|
|
|
|
# ifdef USER0
|
|
|
|
if( 0xFF == (USER0[ 0] ^ USER0[ 1]))
|
|
|
|
baseC = USER0[ 0] * 10 ;
|
|
|
|
# endif
|
2020-12-29 01:26:39 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for( ;;)
|
|
|
|
if( uptime == last)
|
|
|
|
yield() ;
|
|
|
|
else {
|
|
|
|
short Vsample, Csample ;
|
|
|
|
|
|
|
|
last = uptime ;
|
|
|
|
#ifdef RAW
|
|
|
|
adc_vnt( VNT_RAW, &Vsample, &Csample) ;
|
|
|
|
printf( "%i, %i, %i, %i, ", calV, Vsample, calC, Csample) ;
|
2021-07-01 01:23:19 -04:00
|
|
|
Csample = baseC + (calC - (int) Csample * calV / Vsample)
|
|
|
|
# ifdef TS_CAL2
|
|
|
|
* 800 / (calC - *TS_CAL2) ;
|
|
|
|
# else
|
|
|
|
* 10000 / 5336 ;
|
|
|
|
# endif
|
2020-12-29 01:26:39 -05:00
|
|
|
Vsample = 330 * calV / Vsample ;
|
|
|
|
#else
|
|
|
|
adc_vnt( VNT_VNC, &Vsample, &Csample) ;
|
|
|
|
#endif
|
|
|
|
printf( "%i.%i, %i.%i\n", Vsample / 100, Vsample % 100,
|
|
|
|
Csample / 10, Csample % 10) ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end of adcmain.c */
|