请选择 进入手机版 | 继续访问电脑版
查看: 3523|回复: 2

[原创] 【LPC11U68】板载温度ADC中断采集,串口显示

[复制链接]
  • TA的每日心情
    擦汗
    2023-7-4 19:10
  • 签到天数: 92 天

    [LV.6]常住居民II

    15

    主题

    222

    帖子

    23

    高级会员

    Rank: 4

    积分
    640
    最后登录
    2023-8-6
    发表于 2018-12-14 15:24:20 | 显示全部楼层 |阅读模式
    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)
    微信截图_20181214144918.png
    3.systick 中断

    1. void SysTick_Handler(void)
    2. {
    3.         static uint32_t count;

    4.         /* Every 1/2 second */
    5.         count++;
    6.         if (count >= (TICKRATE_HZ / 1)) {
    7.                 count = 0;

    8.                 /* Restart temperature cycle */
    9.                 tempStartCycle();
    10.         }
    11. }
    复制代码
    500ms 使能一次采集

    4.adc 中断

    1. <blockquote>void ADCA_IRQHandler(void)
    复制代码
    5.串口输出 微信截图_20181214132945.png
    这个温度是片内温度(利用本征PN结输出电压与温度关系)。




    微信截图_20181214144918.png
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    2023-7-4 19:10
  • 签到天数: 92 天

    [LV.6]常住居民II

    15

    主题

    222

    帖子

    23

    高级会员

    Rank: 4

    积分
    640
    最后登录
    2023-8-6
     楼主| 发表于 2018-12-14 15:25:29 | 显示全部楼层
    temp.rar (2.5 KB, 下载次数: 29)
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    前天 15:16
  • 签到天数: 266 天

    [LV.8]以坛为家I

    3296

    主题

    6541

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    31904
    最后登录
    2024-3-28
    发表于 2018-12-17 11:05:24 | 显示全部楼层
    支持下楼主
    签到签到
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-3-28 21:42 , Processed in 0.136149 second(s), 23 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表