PWM Sequence from HAL to NRFX

Hello

I am trying to change the code from the HAL code up to NRFX in order to make it event-based instead of using infinite while loops. 

I am using 52840 on a custom PCA with goal in mind to create a half-duplex-half-UART communication.

Working with HAL drivers, the code works as intended, but it is not optimized and is very power hungry for our needs. 

The HAL Setup and sending of the message (Byte by byte, each byte 10 bits at a time (Start - 8xData - Stop)): 

The issue with this approach, again, is the while loops that, among other issues, can sometimes get stuck and hang the rest of the process. 

The actual issue rewriting this with NRFX drivers is the fact that I cannot, for the life of me, figure out how to write out my "initialSequence." I can get the PWM to toggle on or off, but not actually make it do that in sequence as I need it to. I tried following a few examples I found on Devzone, but nothing concrete enough to help me with my issue. 

The HAL Implementation repeats every 100 milliseconds, so the NRFX one should be able to match that. If anyone has an idea of how to write this using the NRFX drivers, or to point me in the direction of a set-up example, I'd be very grateful. 
To add to this: The idea is for this code to run along with a Zephyr based system that runs the rest of the functionality of the board (Thus why we're trying to make it event based as opposed to current implementation).

Thank you in advanced for response. If you need any more information, please ask. 

EDIT: Added the missing code that was calling the TX sequence in order. (Write, Wait, Stop)

Parents Reply Children
  • Not sure the api drivers correctly handle the pins, but looking at the 'scope seems the pins aren't configured so try adding this after the init:

  • Ok couldn't resist testing further, so here's a working example using the 4-byte data you specified:

    Usually would add an interrupt to signify end-of-transmission

  • Hi, Thank you so much for working the solution out and testing it! 
    I have adapted your solution to my code and managed to get a similar output to the one that I need. But I still have one small issue: The Frequency is ~1KHz, I need 32. 
    Duty cycle keeps varrying from 20-80% where as I need it on 50% (As fixed as possible). I've tried changing some values in the code you provided, but I'm having no luck with getting the wanted result. 
    If you have a fix for that as well, that'll have solved my issue. 
    And if not, I am beyond grateful for the help thus far, it's helped me get a little deeper understanding of how the new API is working.

  • Not sure I understand your duty cycle comments; can you sketch a wavefor of a specific character?

    The frequence is set by LL_BAUDRATE =1200, which is 1.2kHz; 32kHz is set by LL_BAUDRATE =32000

    To get crystal-stable frequency with no jitter add this code at the start:

    Standard UART: