1.in pwm chanel callback
Code: Select all
static void pwmc1cb(PWMDriver *pwmp)
{
(void)pwmp;
chSysLockFromISR();
adcStartConversionI(&ADCD1, &adcgrpcfg, samples, ADC_GRP_BUF_DEPTH);
chSysUnlockFromISR();
}
2. in adc callback
Code: Select all
static void adccallback(ADCDriver *adcp, adcsample_t *buffer, size_t n)
{
(void)adcp;
(void)buffer;
(void)n;
chSysLockFromISR();
adcStopConversionI(&ADCD1);
chBSemSignalI(¤t_bsem);
chSysUnlockFromISR();
}
3. create a thread to get the samples after signall
Code: Select all
static THD_WORKING_AREA(waThread2, 128);
static THD_FUNCTION(Thread2, arg)
{
(void)arg;
chRegSetThreadName("current");
while (true)
{
msg_t msg = chBSemWait(¤t_bsem);
(void)msg;
float ret = getCurrent(motor1.state);
(void)ret;
}
}
(getCurrent can get adc samples and transform it to current)
now the thread doesn't work ,mabe i need use other way to get the current on PWM_ACTIVE voltage?