Skip to content

Commit

Permalink
Merge pull request #126 from DiSlord/master
Browse files Browse the repository at this point in the history
Fix screen artifacts, change start/stop or center/span mode set, remove Mutex use
  • Loading branch information
edy555 committed Mar 21, 2020
2 parents c40d78d + 597c2c2 commit a482160
Show file tree
Hide file tree
Showing 10 changed files with 898 additions and 826 deletions.
13 changes: 8 additions & 5 deletions adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,23 @@ uint16_t adc_single_read(uint32_t chsel)

int16_t adc_vbat_read(void)
{
// 13.9 Temperature sensor and internal reference voltage
// VREFINT_CAL calibrated on 3.3V, need get value in mV
#define ADC_FULL_SCALE 3300
#define VREFINT_CAL (*((uint16_t*)0x1FFFF7BA))
adc_stop();
float vbat = 0;
float vrefint = 0;
ADC->CCR |= ADC_CCR_VREFEN | ADC_CCR_VBATEN;
// VREFINT == ADC_IN17
vrefint = adc_single_read(ADC_CHSELR_CHSEL17);
uint32_t vrefint = adc_single_read(ADC_CHSELR_CHSEL17);
// VBAT == ADC_IN18
// VBATEN enables resiter devider circuit. It consume vbat power.
vbat = adc_single_read(ADC_CHSELR_CHSEL18);
uint32_t vbat = adc_single_read(ADC_CHSELR_CHSEL18);
ADC->CCR &= ~(ADC_CCR_VREFEN | ADC_CCR_VBATEN);
touch_start_watchdog();
uint16_t vbat_raw = (ADC_FULL_SCALE * VREFINT_CAL * vbat * 2 / (vrefint * ((1<<12)-1)));
// vbat_raw = (3300 * 2 * vbat / 4095) * (VREFINT_CAL / vrefint)
// uint16_t vbat_raw = (ADC_FULL_SCALE * VREFINT_CAL * (float)vbat * 2 / (vrefint * ((1<<12)-1)));
// For speed divide not on 4095, divide on 4096, get little error, but no matter
uint16_t vbat_raw = ((ADC_FULL_SCALE * 2 * vbat)>>12) * VREFINT_CAL / vrefint;
if (vbat_raw < 100) {
// maybe D2 is not installed
return -1;
Expand Down
2 changes: 1 addition & 1 deletion chconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
*
* @note The default is @p TRUE.
*/
#define CH_CFG_USE_MUTEXES TRUE
#define CH_CFG_USE_MUTEXES FALSE

/**
* @brief Enables recursive behavior on mutexes.
Expand Down
4 changes: 2 additions & 2 deletions fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ static void fft256(float array[][2], const uint8_t dir) {
uint16_t j, k;
for (j = i, k = 0; j < i + halfsize; j++, k += tablestep) {
uint16_t l = j + halfsize;
float tpre = array[l][real] * cos(2 * M_PI * k / 256) + array[l][imag] * sin(2 * M_PI * k / 256);
float tpim = -array[l][real] * sin(2 * M_PI * k / 256) + array[l][imag] * cos(2 * M_PI * k / 256);
float tpre = array[l][real] * cos(2 * VNA_PI * k / 256) + array[l][imag] * sin(2 * VNA_PI * k / 256);
float tpim = -array[l][real] * sin(2 * VNA_PI * k / 256) + array[l][imag] * cos(2 * VNA_PI * k / 256);
array[l][real] = array[j][real] - tpre;
array[l][imag] = array[j][imag] - tpim;
array[j][real] += tpre;
Expand Down
Loading

0 comments on commit a482160

Please sign in to comment.