How do I get average value of pulse signal with ADC?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How do I get average value of pulse signal with ADC?

1,212件の閲覧回数
TonyKim
Contributor I

Hi,

I'm using S32K144, trying to get average value of sensor signal.
Input sensor signal is varying pulse signal, similar to PWM signal. 
I used ADC with Hardware average enabled to get average value of this signal, but I couldn't get constant value, just unstable value which can't be predicted. I need exact average value of signal to determine the system's mode. Do I have to match (sample time)*(samples needed to average) to specific value like pulse signal's period?

For example, if the signal's one cycle has 1ms On & 5ms Off, Do I have to match (sample time)*(32 samples) to 6ms and apply the 32 sample Hardware averaging?

Or Is there any other way using ADC to get constant average value of PWM like signal?

This is how I initialized ADC configuration

void ADC1_init(void)
{
/*!
* ADC1 Clocking:
* ===================================================
*/
PCC->PCCn[PCC_ADC1_INDEX] &=~ PCC_PCCn_CGC_MASK; /* Disable clock to change PCS */
PCC->PCCn[PCC_ADC1_INDEX] |= PCC_PCCn_PCS(1); /* PCS=1: Select SOSCDIV2 */
PCC->PCCn[PCC_ADC1_INDEX] |= PCC_PCCn_CGC_MASK; /* Enable bus clock in ADC */

/*!
* ADC0 Initialization:
* ===================================================
*/
ADC1->SC1[0] |= ADC_SC1_ADCH_MASK; /* ADCH=1F: Module is disabled for conversions */
                                                                        /* AIEN=0: Interrupts are disabled */
ADC1->CFG1 |= ADC_CFG1_ADIV_MASK
                        |ADC_CFG1_MODE(1); /* ADICLK=0: Input clk=ALTCLK1=SOSCDIV2 */
                                                               /* ADIV=0: Prescaler=1 */
                                                               /* MODE=1: 12-bit conversion */

ADC1->CFG2 = ADC_CFG2_SMPLTS(255); 
ADC1->SC2 = 0x00000000; 
ADC1->SC3 = 0x00000111; 
}

 

And these are functions i used for ADCs.

void convertAdcChan1(uint16_t adcChan)
{
ADC1->SC1[0]&=~ADC_SC1_ADCH_MASK; /* Clear prior ADCH bits */
ADC1->SC1[0] = ADC_SC1_ADCH(adcChan); /* Initiate Conversion */
}

uint8_t adc_complete1(void)
{
return ((ADC1->SC1[0] & ADC_SC1_COCO_MASK)>>ADC_SC1_COCO_SHIFT); /* Wait for completion */
}

uint32_t read_adc_chx1(void)
{
uint16_t adc_result=0;
adc_result=ADC1->R[0]; /* For SW trigger mode, R[0] is used */
return (uint32_t) ((5000*adc_result)/0xFFF); /* Convert result to mv for 0-5V range */
}

タグ(2)
0 件の賞賛
返信
1 返信

1,192件の閲覧回数
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi TonyKim,

Maybe you should show us more specific about the signal characteristics of sensor .(for example show us the manual of sensor)
If you want to ADC sample the signal, you may need check if the ADC conversion frequency in S32K1xx MCU Family - Data Sheet is high enough. 
If the signal is pulse like PWM, why not measure the duty(width of high pulse) of it by using FTM module?


Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 件の賞賛
返信