当前位置: 首页 > news >正文

Renesas R7FA8D1BH (Cortex®-M85) 生成4路PWM

目录

 概述

1 软硬件环境

1.1 软件版本信息

1.2 硬件接口

2 FSP生成配置

2.1 配置参数

 2.2 创建Stack和配置PWM参数

3 FSP库函数介绍

3.1 R_GPT_Open()

3.2 R_GPT_Stop() 

3.3  R_GPT_Start() 

3.4 R_GPT_Enable() 

3.5  R_GPT_PeriodSet()

3.6  R_GPT_DutyCycleSet()

3.7 R_GPT_OutputEnable()

 3.8 R_GPT_PwmOutputDelaySet()

3.9 R_GPT_OutputDisable()


 概述

本文主要介绍使用Renesas 提供的FSP工具配置参数实现PWM功能,内容包括参数配置,PWM功能代码的实现,以及如何生成项目工程,还使用逻辑分析仪捕捉波形,以验证PWM波形的准确性。

1 软硬件环境

1.1 软件版本信息

软硬件信息版本信息
Renesas MCUR7FA8D1BH(Cortex®-M85)
KeilMDK ARM 5.38
FSP 版本5.3.0
调试工具:dap-linkCMSIS-DAP-NSLink V2.0.0

1.2 硬件接口

1) GPT-1:   P105

2) GPT-2:   P102

3) GPT-6:   PA11 and PA12  

2 FSP生成配置

2.1 配置参数

1)配置GPT参数(GPT1)

2)配置GPT参数(GPT2)

3)  配置GPT参数(GPT6)

 2.2 创建Stack和配置PWM参数

1) 创建Stack

2) 配置参数

 配置channel-1参数

 配置channel-2参数

  配置channel-6参数

3 FSP库函数介绍

3.1 R_GPT_Open()

函数原型:


fsp_err_t R_GPT_Open	(	timer_ctrl_t *const 	p_ctrl,timer_cfg_t const *const 	p_cfg 
)	

初始化定时器模块并应用配置。实现timer_api_t::开放。

GPT硬件本身不支持一次性功能。当使用单镜头模式时,计时器将在请求的时间段过去后在ISR中停止。

通用定时器的GPT实现可以接受gpt_extended_cfg_t扩展参数。

应用范例:

/* Initializes the module. */err = R_GPT_Open(&g_timer0_ctrl, &g_timer0_cfg);

 返回值:

Return values

FSP_SUCCESSInitialization was successful and timer has started.
FSP_ERR_ASSERTIONA required input pointer is NULL or the source divider is invalid.
FSP_ERR_ALREADY_OPENModule is already open.
FSP_ERR_IRQ_BSP_DISABLEDtimer_cfg_t::mode is TIMER_MODE_ONE_SHOT or timer_cfg_t::p_callback is not NULL, but ISR is not enabled. ISR must be enabled to use one-shot mode or callback.
FSP_ERR_INVALID_MODETriangle wave PWM is only supported if GPT_CFG_OUTPUT_SUPPORT_ENABLE is 2. Selected channel does not support external count sources. External and event count sources not are available in this mode.
FSP_ERR_IP_CHANNEL_NOT_PRESENTThe channel requested in the p_cfg parameter is not available on this device.

3.2 R_GPT_Stop() 

函数原型:

fsp_err_t R_GPT_Stop	(	timer_ctrl_t *const 	p_ctrl	)	

应用案例:

  /* (Optional) Stop the timer. */(void) R_GPT_Stop(&g_timer0_ctrl);

返回值

Return values

FSP_SUCCESSTimer successfully stopped.
FSP_ERR_ASSERTIONp_ctrl was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.

3.3  R_GPT_Start() 

函数原型

fsp_err_t R_GPT_Start	(	timer_ctrl_t *const 	p_ctrl	)	

应用范例:

/* Start the timer. */(void) R_GPT_Start(&g_timer0_ctrl);

返回值:

Return values

FSP_SUCCESSTimer successfully started.
FSP_ERR_ASSERTIONp_ctrl was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.

3.4 R_GPT_Enable() 

函数原型:

fsp_err_t R_GPT_Enable	(	timer_ctrl_t *const 	p_ctrl	)	

使用案例:

/* Enable captures. Captured values arrive in the interrupt. */(void) R_GPT_Enable(&g_timer0_ctrl);

返回值:

Return values

FSP_SUCCESSExternal events successfully enabled.
FSP_ERR_ASSERTIONp_ctrl was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.

3.5  R_GPT_PeriodSet()

函数原型:

fsp_err_t R_GPT_PeriodSet	(	timer_ctrl_t *const 	p_ctrl,uint32_t const 	period_counts 
)		

设置提供的周期值。

如果定时器正在运行,则在下一个计数器溢出后更新周期。如果计时器停止,该函数重置计数器并更新周期。实现timer_api_t:: periodSet。

警告
如果使用周期性输出,则占空比缓冲寄存器在周期缓冲寄存器之后更新。如果在计时器运行时调用此函数,并且在处理过程中发生GPT溢出,则在处理完成后计数器溢出之前,占空比将不会是期望的50%占空比。

应用范例:

  /* Get the source clock frequency (in Hz). There are 3 ways to do this in FSP:*  - If the PCLKD frequency has not changed since reset, the source clock frequency is*    BSP_STARTUP_PCLKD_HZ >> timer_cfg_t::source_div*  - Use the R_GPT_InfoGet function (it accounts for the divider).*  - Calculate the current PCLKD frequency using R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKD) and right shift*    by timer_cfg_t::source_div.** This example uses the 3rd option (R_FSP_SystemClockHzGet).*/uint32_t pclkd_freq_hz = R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKD) >> g_timer0_cfg.source_div;/* Calculate the desired period based on the current clock. Note that this calculation could overflow if the* desired period is larger than UINT32_MAX / pclkd_freq_hz. A cast to uint64_t is used to prevent this. */uint32_t period_counts =(uint32_t) (((uint64_t) pclkd_freq_hz * GPT_EXAMPLE_DESIRED_PERIOD_MSEC) / GPT_EXAMPLE_MSEC_PER_SEC);/* Set the calculated period. */err = R_GPT_PeriodSet(&g_timer0_ctrl, period_counts);assert(FSP_SUCCESS == err);

3.6  R_GPT_DutyCycleSet()

函数原型:


fsp_err_t R_GPT_DutyCycleSet	(	timer_ctrl_t *const 	p_ctrl,uint32_t const 	duty_cycle_counts,uint32_t const 	pin 
)	

在请求引脚上设置占空比。实现timer_api_t:: dutyCycleSet。

占空比在缓冲寄存器中更新。更新后的占空比在下一个周期结束后反映(计数器溢出)。

应用案例:

 /* Get the current period setting. */timer_info_t info;(void) R_GPT_InfoGet(&g_timer0_ctrl, &info);uint32_t current_period_counts = info.period_counts;/* Calculate the desired duty cycle based on the current period. Note that if the period could be larger than* UINT32_MAX / 100, this calculation could overflow. A cast to uint64_t is used to prevent this. The cast is* not required for 16-bit timers. */uint32_t duty_cycle_counts =(uint32_t) (((uint64_t) current_period_counts * GPT_EXAMPLE_DESIRED_DUTY_CYCLE_PERCENT) /GPT_EXAMPLE_MAX_PERCENT);/* Set the calculated duty cycle. */err = R_GPT_DutyCycleSet(&g_timer0_ctrl, duty_cycle_counts, GPT_IO_PIN_GTIOCB);assert(FSP_SUCCESS == err);

3.7 R_GPT_OutputEnable()

函数原型:

fsp_err_t R_GPT_OutputEnable	(	timer_ctrl_t *const 	p_ctrl,
gpt_io_pin_t 	pin 
)	

Enable output for GTIOCA and/or GTIOCB.

Return values

FSP_SUCCESSOutput is enabled.
FSP_ERR_ASSERTIONp_ctrl or p_status was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.

 3.8 R_GPT_PwmOutputDelaySet()

函数原型:


fsp_err_t R_GPT_PwmOutputDelaySet	(	timer_ctrl_t *const 	p_ctrl,
gpt_pwm_output_delay_edge_t 	edge,
gpt_pwm_output_delay_setting_t 	delay_setting,
uint32_t const 	pin 
)		

Set the Output Delay setting for the PWM output pin.

Return values

FSP_SUCCESSThe output delay was set.
FSP_ERR_ASSERTIONAn input parameter was invalid.
FSP_ERR_NOT_OPENThe instance is not opened.
FSP_ERR_INVALID_CHANNELThe channel does not support this feature.
FSP_ERR_NOT_INITIALIZEDThe PWM Output Delay Circuit has not been initialized.
FSP_ERR_INVALID_STATEThe PWM Output Delay setting cannot be updated in the current state.
FSP_ERR_UNSUPPORTEDThis feature is not supported on this MCU.

3.9 R_GPT_OutputDisable()

函数原型:

fsp_err_t R_GPT_OutputDisable	(	timer_ctrl_t *const 	p_ctrl,gpt_io_pin_t 	pin 
)	

Disable output for GTIOCA and/or GTIOCB.

Return values

FSP_SUCCESSOutput is disabled.
FSP_ERR_ASSERTIONp_ctrl or p_status was NULL.
FSP_ERR_NOT_OPENThe instance is not opened.


http://www.mrgr.cn/news/33383.html

相关文章:

  • 大数据学习14之Scala面向对象--至简原则
  • C++编程:利用环形缓冲区优化 TCP 发送流程,避免 Short Write 问题
  • 【话题讨论】AI赋能电商:创新应用与销售效率的双轮驱动
  • springboot自动装配
  • node.js安装和配置教程
  • Request和Response
  • 【ArcGIS微课1000例】0123:数据库中要素类批量转为shapefile
  • 数据结构之堆(优先级队列)
  • 2024/9/22周报
  • 【面经】查找中常见的树数据结构
  • 8. Data Member的绑定
  • 国产游戏技术能否引领全球【终稿】
  • CompletableFuture如何优雅处理异步任务超时!妙就完了
  • 国人卖家可折叠无线充电器发起TRO专利维权,功能相同可能侵权
  • 【深入学习Redis丨第六篇】Redis哨兵模式与操作详解
  • 图神经网络的新篇章:通用、强大、可扩展的图变换器
  • WebGL基础知识快速入门
  • 空栈压数 - 华为OD统一考试(E卷)
  • thinkphp 做分布式服务+读写分离+分库分表(分区)(后续接着写)
  • 【shell脚本4】Shell脚本学习--字符串和数组
  • 掌控历史:如何通过Git版本管理工具提升你的开发效率
  • 2024华为杯E题成品文章已出!
  • 【AI算法岗面试八股面经【超全整理】——深度学习】
  • 软件开发事故分级极简理解(灾难级、高级、中级、轻微级)
  • 学习C4模型的新网站
  • 【langchain学习】深度解析:Langchain TextSplitter 与新型正则表达式分割器的性能对比