Hello,
I need to generate a signal of at least 2MHz form a GPIO of a RAK11720, is it possible?
I have spotted a library called udrv_pwm.h and played a bit with it, but maybe I got my setting wrong, as maximum frequency was 46KHz.
Thanks
Hello,
I need to generate a signal of at least 2MHz form a GPIO of a RAK11720, is it possible?
I have spotted a library called udrv_pwm.h and played a bit with it, but maybe I got my setting wrong, as maximum frequency was 46KHz.
Thanks
Hello @pico,
For this type of speed, it is not possible to generate it directly with RUI3 functions. You must patch uhal_pwm.c file (…/cores/apollo3/component/core/mcu/apollo3/uhal/uhal_pwm.c). Inside this function, you must change “period_in_us” and “duty” variables according to your requirements.
The second way is to use directly AmbiqSuiteSDK files. If you will select this way, please take a look “AmbiqSuiteSDK/boards/apollo3_evb/examples/ctimer_repeated_pattern” example. You can use AmbiqSuiteSDK inside RUI3. It is possible. You can add “am_mcu_apollo.h” header file to your Arduino project like below:
extern "C" {
#include "am_mcu_apollo.h"
}
Please do not hesitate to ask any further questions.
Best regards,
Sercan.
Hi Sercan,
thanks for your reply!
Is this the function your refere to?
int32_t uhal_pwm_set_duty(udrv_pwm_port port, uint32_t duty) {}
L164 reports this:
//uint32_t period_in_us = (uint32_t) (12000000/pwm_status[port].freq_hz);
shall I hard cod it there or elsewhere?
Hello @pico,
Yes. Function is uhal_pwm_set_duty(). Inside this function, please try to adjust ontime and period_in_us parameters. I added lines inside uhal.pwm.c file so you can find them:
if (set_periods)
{
am_hal_ctimer_period_set(timer, segment, period_in_us, ontime);
am_hal_ctimer_aux_period_set(timer, segment, period_in_us, ontime);
am_hal_ctimer_start(timer, segment);
}
Also please try to increase following XTAL speed.
#define CLK AM_HAL_CTIMER_HFRC_12MHZ // Use an Ambiq HAL provided value to select which clock
Best regards,
Sercan.
Thanks, it works.
Will these hardcoded values impact any other function for LoRa/BLE operations?
This changes will not affect any LoRa or BLE operation. It is good to hear that you solved your problem.
Best regards,
Sercan.