冰楓論壇

標題: Renesas RX113 [打印本頁]

作者: 洪嵐峰    時間: 2023-4-20 04:26
標題: Renesas RX113
製作一個多通道示波器需要以下零件:

Renesas RX113 微控制器板 (RX113-ek)

8 位元串聯至並行型態轉換晶片 (74HC165)

雙向直流電壓轉換器模組 (MAX485)

4.3 吋 TFT LCD 顯示屏

10K 歐姆可變電阻器

電阻器和電容器

透過 Renesas RX113 微控制器板進行編程:


#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "r_cg_timer.h"
#include "r_cg_adc.h"
#include "r_cg_port.h"
#include "r_cg_cgc.h"

#define MAX_SAMPLES 4096

volatile uint16_t samples[MAX_SAMPLES];
volatile uint16_t sample_count = 0;

void setup() {
    R_ADC_Create();
    R_ADC_Set_OperationOn();
    R_ADC_Set_Result(ADC_AN000, ADC_RES_FIFO_16, 1);
    R_ADC_Start();
   
    R_PORT_Create();
    R_PORT_Set_GPIO(PDL_NO, PDL_GPIO_OUTPUT);
    R_PORT_Write(GPIO_PD1_PIN, 0);
   
    R_CGC_Create();
    R_CGC_Set_MainClkSrc(CGC_CLK_SRC_HOCO);
    R_CGC_Set_HocoDiv(CGC_HOCODIV_2);
    R_CGC_Start();
   
    R_TAU0_Create();
    R_TAU0_Channel0_Start();
   
    R_SAU0_Create();
    R_SAU0_Start();
}

void loop() {
    while (sample_count < MAX_SAMPLES) {
        while (!R_ADC_Get_Result(ADC_RES_FIFO_16, &samples[sample_count]));
        sample_count++;
    }
   
    R_TAU0_Channel0_Stop();
   
    uint16_t max_sample = 0;
    for (uint16_t i = 0; i < MAX_SAMPLES; i++) {
        if (samples[i] > max_sample) {
            max_sample = samples[i];
        }
    }
   
    for (uint16_t i = 0; i < MAX_SAMPLES; i++) {
        samples[i] = samples[i] * 4096 / max_sample;
    }
   
    R_PORT_Write(GPIO_PD1_PIN, 1);
    for (uint16_t i = 0; i < MAX_SAMPLES; i++) {
        while (!R_SAU0_Send((uint8_t*)&samples[i], 2));
    }
    R_PORT_Write(GPIO_PD1_PIN, 0);
   
    sample_count = 0;
    R_TAU0_Channel0_Start();
}

void main(void) {
    setup();
    while (true) {
        loop();
    }
}
這個程式碼使用 Renesas RX113 微控制器板的 ADC 功能,從模擬輸入中讀取樣本。

然後使用 TAU0 定時器計算每個樣本的最大值,以便進行垂直縮放。

最後,使用 SAU0 串列通訊介面將樣本數據傳輸到外部顯示器顯示。

程式碼中的 GPIO_PD1_PIN 定義了控制 MAX485 轉換器的引腳,以便在傳輸數據時開啟/關閉。




歡迎光臨 冰楓論壇 (https://bingfong.com/) Powered by 冰楓