I want to drive LED using NRF_PWM0, but It is not working.
I want to increase brightness of LED but it is alyway on.
Please help me.
/* * Copyright 2019. Seonguk Jeong All rights reserved * uAHRS Project * Example : Pulse Width Modulation(PWM) * Created at Dec. 11, 2019 * Author : Seonguk Jeong */ #include <nrf_drv_pwm.h> #include <nrf_drv_timer.h> #include <nrf_delay.h> void Initialize(); void setDuty(int16_t duty); int main(void){ // Initialize PWM Initialize(); int16_t test = 0; while(1){ if(test >= 32000){ test = 0; } setDuty(test); test++; nrf_delay_ms(2); } return 0; } void Initialize(){ NRF_PWM0->PSEL.OUT[0] = 23; NRF_PWM0->PSEL.OUT[1] = 24; NRF_PWM0->ENABLE = 0x01; // Enable PWM NRF_PWM0->MODE = 0x00; // Up mode NRF_PWM0->PRESCALER = 0x00 ; // No prescaler NRF_PWM0->COUNTERTOP = 32000; // Set 2ms NRF_PWM0->LOOP = 0x00; // Disable loop NRF_PWM0->DECODER = 0x00; // Common Mode NRF_PWM0->SEQ[0].REFRESH = 0; NRF_PWM0->SEQ[0].ENDDELAY = 0; } void setDuty(int16_t duty){ int16_t dutyMemory[4] = {duty}; NRF_PWM0->SEQ[0].PTR = (uint32_t)dutyMemory; NRF_PWM0->SEQ[0].CNT = (sizeof(dutyMemory) / sizeof(uint16_t)); // PWM TASK START NRF_PWM0->TASKS_SEQSTART[0] = 1; while(!NRF_PWM0->EVENTS_SEQSTARTED[0]){} NRF_PWM0->EVENTS_SEQSTARTED[0] = 0; }