pwm-led-fade
Fade an LED on PWM channel E1M_PWM0 from 0 % → 100 % → 0 %. The canonical open / set-duty / close pattern for <alp/pwm.h>.
Source: examples/pwm-led-fade/.
board.yaml
schema_version: 2
som:
sku: E1M-AEN701
carrier:
name: E1M-EVK
cores:
m55_hp:
os: zephyr
app: ./src
peripherals: [pwm]
diagnostics:
log_level: info
Source (abbreviated)
#include <alp/pwm.h>
#include <alp/e1m_pinout.h>
int main(void) {
alp_pwm_t *pwm = alp_pwm_open(&(alp_pwm_config_t){
.channel_id = E1M_PWM0,
});
if (pwm == NULL) {
printk("[pwm] open failed: err=%d\n", (int)alp_last_error());
return -1;
}
const uint32_t period_ns = 1000000u; /* 1 kHz */
for (uint32_t duty = 0; duty <= period_ns; duty += period_ns / 20u) {
alp_pwm_set(pwm, period_ns, duty);
k_msleep(50);
}
alp_pwm_close(pwm);
return 0;
}
Build
# native_sim
west alp-build -b native_sim/native/64 alp-sdk/examples/pwm-led-fade
west build -d build -t run
# Real silicon (E1M EVK + AEN)
west alp-build -b alp_e1m_evk_aen alp-sdk/examples/pwm-led-fade
west flash
The example's boards/alp_e1m_evk_aen.overlay points alp-pwm0 at the EVK's user LED.
See also
Questions about this page? Discuss in Community Forum