This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to program an Analogic output on pin 18

Hello

I have seen in the various examples that most of the time the output are digital (0 or 1) . i program a PWM signal to make any DC output on the pin 18

but unfortunately, this occurs into a loop checking UART data coming. It is simple to let a pin at 0 or 1, but i need to constantly generate the PWM signal if something in between. if i write a while loop in this event handler, i cannot check if there is new data coming since my event handler is stuck doing the PWM. 

How is the best way to turn a pin as an analog output without condamning the event loop to detect if there is a BLE data coming to shut down this signal or modify its value?

Thanks

Philippe

  • You need a HW PWM, either use the PWM peripheral or make one with TIMER + PPI + GPIOTE. 

    Search the devzone for implementation specifics. 

  • Thanks I will check that. It seems like the event of a button changing the demo numbers in the pwm_driver example might be the closest of what i need to do. some PWM who can be changed by an event

  • I tried to merge the PWM driver example and the UART one. but i get some issues in SES. these two examples are running perfectly independantly. but i just try to add this very first line of code, adding all the includes missing in the UART examples

    static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0); 

    I added also all the missing c files in the driver and i also get that error. i have no idea where this variable is defined

    return NRF_SUCCESS;  (undeclared, first use of this function)

  • It's probably the sdk_config.h files that is missing the settings for the PWM. Di you merge the PWM example into the UART example or the other way around? 

  • Hi, 

    I have finally been able to combine and compile those two examples together. 

    I didnt really understand the code of the pwm_driver solution. Does it exist a more detailed documentation regarding what is done step by step?  

    especially this function:

    static void init_bsp()
    {
    APP_ERROR_CHECK(nrf_drv_clock_init());
    nrf_drv_clock_lfclk_request(NULL);

    APP_ERROR_CHECK(app_timer_init());
    APP_ERROR_CHECK(bsp_init(BSP_INIT_BUTTONS, bsp_evt_handler));
    APP_ERROR_CHECK(bsp_buttons_enable());
    }

    as well as these guys: 

    __WFE();

    // Clear the event register.
    __SEV();
    __WFE();

    One more question: 

    > for merging the two sdk_config.h files (of about 10 000 lines) i had to compare manually line by line between the sdk_config of the two projects. It took me a while. is there a tool that can compare such files automatically and gives directly the values that have been modified or the missing part?

    thanks for your help

    Philippe

Related