在线时间48 小时
UID1860622
注册时间2016-10-24
NXP金币0
TA的每日心情 | 擦汗 2023-7-4 19:10 |
---|
签到天数: 92 天 [LV.6]常住居民II
高级会员
- 积分
- 640
- 最后登录
- 2023-8-6
|
1.
main函数
uint32_t rawSample;
SystemCoreClockUpdate();
Board_Init();//初始化
DEBUGSTR("Temperature sensor demo\r\n");
/* Setup ADC for 12-bit mode and normal power */
Chip_ADC_Init(LPC_ADC, 0);//使用3.3V 12bit ADC 采集(使能adc时钟,关断中断)
/* Setup ADC clock rate */
Chip_ADC_SetClockRate(LPC_ADC, 250000);
/* Setup a sequencer to do the following:
Perform ADC conversion of ADC channels 0 with EOS interrupt *///选定通道及中断模式
Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQA_IDX, (ADC_SEQ_CTRL_CHANSEL(0) |
ADC_SEQ_CTRL_MODE_EOS));
/* Power up the internal temperature sensor - this also selects the
temperature sensor as the input for the ADC0 input *///选择输入源
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_TS_PD);
/* Use higher voltage trim */
Chip_ADC_SetTrim(LPC_ADC, ADC_TRIM_VRANGE_HIGHV);
/* Need to do a calibration after initialization and trim */
Chip_ADC_StartCalibration(LPC_ADC);
while (!(Chip_ADC_IsCalibrationDone(LPC_ADC))) {}
/* Clear all pending interrupts */
Chip_ADC_ClearFlags(LPC_ADC, Chip_ADC_GetFlags(LPC_ADC));
/* Enable ADC sequence A completion interrupt */
Chip_ADC_EnableInt(LPC_ADC, ADC_INTEN_SEQA_ENABLE);
/* Enable ADC NVIC interrupt */
NVIC_EnableIRQ(ADC_A_IRQn);
/* Enable sequencer */
Chip_ADC_EnableSequencer(LPC_ADC, ADC_SEQA_IDX);
/* This example uses the periodic sysTick to manually trigger
the ADC burst cycle *///这个例子使用的是突发模式 用systick 来触发
SysTick_Config(SystemCoreClock / TICKRATE_HZ);
/* Endless loop */
while (1) {
/* Sleep until something happens */
__WFI();//等待中断
/* Is a conversion sequence complete? */
if (tempCycleComplete()) {
rawSample = tempGetSample();
if ((rawSample & ADC_SEQ_GDAT_DATAVALID) != 0) {
// DEBUGOUT("Sampled temp value = 0x%04x (first = 0x%04x)\r\n", ADC_DR_RESULT(rawSample),
// ADC_DR_RESULT(temp[0]));
DEBUGOUT(" temp value = %04f \r\n ", (606-ADC_DR_RESULT(rawSample)*3.3*1000/4096)/2.36);//显示实时的温度
}
else {
DEBUGSTR("\r\nInvalid sample read\r\n");
}
}
}
2.这里解释下上面的转换,由数据手册可知y(ADC 电压 单位mv)=-2.36x(温度 单位摄氏度)+606(mv)
3.systick 中断
- void SysTick_Handler(void)
- {
- static uint32_t count;
- /* Every 1/2 second */
- count++;
- if (count >= (TICKRATE_HZ / 1)) {
- count = 0;
- /* Restart temperature cycle */
- tempStartCycle();
- }
- }
复制代码 500ms 使能一次采集
4.adc 中断
- <blockquote>void ADCA_IRQHandler(void)
复制代码 5.串口输出
这个温度是片内温度(利用本征PN结输出电压与温度关系)。
|
|