hi
i have another problem that is more important for me
the following code is OK except in one situation:
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
/* Total number of channels to be sampled by a single ADC operation.*/
#define ADC_GRP1_NUM_CHANNELS 2
/* Depth of the conversion buffer, channels are sampled four times each.*/
#define ADC_GRP1_BUF_DEPTH 1
static WORKING_AREA(Sampler, 128);
static WORKING_AREA(SampleSender, 128);
/*
* ADC samples buffer.
*/
static adcsample_t samples[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];
/*
* ADC conversion group.
* Mode: Linear buffer, 4 samples of 2 channels, SW triggered.
* Channels: IN11 (480 cycles sample time)
*/
static const ADCConversionGroup adcgrpcfg = {
FALSE,
ADC_GRP1_NUM_CHANNELS,
NULL,
NULL,
/* HW dependent part.*/
0,
ADC_CR2_SWSTART,
ADC_SMPR1_SMP_AN11(ADC_SAMPLE_480)|ADC_SMPR1_SMP_AN10(ADC_SAMPLE_480),
0,
ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
0,
ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)|ADC_SQR3_SQ2_N(ADC_CHANNEL_IN10)
};
static msg_t ADCSampler(void *arg){
systime_t time = chTimeNow();
while(TRUE){
time += MS2ST(10);
chSysLockFromIsr();
adcStartConversionI(&ADCD1, &adcgrpcfg, samples, ADC_GRP1_BUF_DEPTH);
chSysUnlockFromIsr();
chThdSleepUntil(time);
}
}
static msg_t USARTSampleSender(void *arg){
systime_t time = chTimeNow();
while(TRUE){
time += MS2ST(10);
chprintf((BaseChannel *)&SD2, "%D\r\n",samples[1]);
chThdSleepUntil(time);
}
}
int main(void){
/*
* Shell thread
*/
halInit();
chSysInit();
/*
* Initializes the ADC driver 1 and enable the thermal sensor.
*/
adcStart(&ADCD1, NULL);
palSetGroupMode(GPIOC,PAL_PORT_BIT(1) | PAL_PORT_BIT(0),0,PAL_MODE_INPUT_ANALOG);
sdStart(&SD2, NULL);
palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
(void)chThdCreateStatic(Sampler, sizeof(Sampler), NORMALPRIO, ADCSampler, NULL);
(void)chThdCreateStatic(SampleSender, sizeof(SampleSender), NORMALPRIO, USARTSampleSender, NULL);
while(1){
//chprintf((BaseChannel *)&SD2, "%CH2: %D\r\n",(samples[0]));
}
}
in the following part of code if i decrease the delay in (time += US2ST(10);) the program will not work. i red (Reliable timings using Threads) article and i know that for this code to work the program time should be less than the delay but with the rate of 921600 it takes about 0.026 (ms) for USART to send out the data!
Code: Select all
static msg_t USARTSampleSender(void *arg){
systime_t time = chTimeNow();
while(TRUE){
time += MS2ST(10);
chprintf((BaseChannel *)&SD2, "%D\r\n",samples[1]);
chThdSleepUntil(time);
}
}