2960 views|1 replies

3407

Posts

0

Resources
The OP

【R7F0C809】AD sampling [Copy link]

I took a look at the AD configuration of C809 last night. It is also relatively simple. The main functions are:  Peripheral enable register 0 (PER0)  A/D converter mode register 0 (ADM0)  A/D converter mode register 2 (ADM2)  A/D conversion result high-order storage register (ADCRH)  A/D conversion result low-order storage register (ADCRL)  Analog input channel specification register (ADS) Then there are 2 registers for port mode:  Port mode registers 0, 1 (PM0, PM1)  Port mode control registers 0, 1 (PMC0, PMC1) After configuration, AD values can be collected. Regarding the reference voltage of AD, the data sheet states that it can reach the power supply voltage. If powered by 5V, the maximum input voltage of 5V can be measured. Code
  1. void R_ADC_Create(void) //AD initialization { ADCEN = 1U; /* supply AD clock */ ADM0 = 0x00U; /* disable AD conversion and clear ADM0 register */ ADMK = 1U; /* disable INTAD interrupt */ ADIF = 0U; /* clear INTAD interrupt flag */ /* Set INTAD low priority */ ADPR1 = 1U; ADPR0 = 1U; ADM0 = 0x02U; /* fCLK/8 */ ADM2 = 0x00U; /* 10 bits */ } void R_ADC1_Start(void)//AIN1 starts { ADS = 0x01U; /* ANI1 */ ADIF = 0U; /* clear INTAD interrupt flag */ ADMK = 0U; /* enable INTAD interrupt */ ADCS = 1U; /* enable AD conversion */ } void R_ADC0_Start(void)//AIN2 starts { ADS = 0x00U; /* ANI0 */ ADIF = 0U; /* clear INTAD interrupt flag */ ADMK = 0U; /* enable INTAD interrupt */ ADCS = 1U; /* enable AD conversion */ } ......
复制代码
The manual recommends that after starting the AD channel, the MCU should enter halt mode to obtain more accurate AD values. The acquisition buffers of all channels share the conversion result registers (ADCRH, ADCRL). It is worth noting that AIN0 and serial port TX pins are multiplexed.
  1. R_ADC0_Start(); /* Start AD converter */ HALT(); ADIF = 0U; /* Clear INTAD request */ R_ADC_Get_Result( &result_buffer0 ); /* Get AIN0 result */ R_ADC1_Start(); /* Start AD converter */ HALT(); /* wait for UART Rx interrupt */ ADIF = 0U; /* Clear INTAD request */ R_ADC_Get_Result( &result_buffer1 ); /* Get AIN1 result */
复制代码
Where
  1. void R_ADC_Get_Result(uint16_t *buffer) { *buffer = ((uint16_t)ADCRH << 8 | ADCRL) >> 6; }
复制代码
Well, basically all the peripherals you want to use are driven here, so let's think about the hardware solution.

This post is from Renesas Electronics MCUs

Latest reply

:hug: OP's speed,,,,  Details Published on 2015-9-2 13:40
Personal signature

So TM what......?


1868

Posts

1

Resources
2
:hug: OP's speed,,,,
This post is from Renesas Electronics MCUs
Personal signature
分享铸就美好未来。。。





Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>

    EEWorld
    subscription
    account

    EEWorld
    service
    account

    Automotive
    development
    circle

    Robot
    development
    community

    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list