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

PWM - continuous waveform generation. NRF52

I am using the simple code below to generate a signal from a memory buffer.
I cannot generate a signal cyclically. If ONE sequence is used, then the buffer is played once. If use TWO sequences, the signal is generated continuously. How do I do continuous generation with ONE sequence?

Thank you

#define PWM                 NRF_PWM1

#define PWM_PIN             (17UL)

#define TIMER_RELOAD        10000
#define buffer_size 256

uint16_t pwm_buffer[ buffer_size ];

  for( uint16_t j = 0; j < buffer_size; j++) {
    pwm_buffer[j] = j << 4;
  }


	PWM->PSEL.OUT[0]  = (PWM_PIN << PWM_PSEL_OUT_PIN_Pos) |
	                    (PWM_PSEL_OUT_CONNECT_Connected << PWM_PSEL_OUT_CONNECT_Pos);
  
	PWM->ENABLE       = (PWM_ENABLE_ENABLE_Enabled << PWM_ENABLE_ENABLE_Pos);
	PWM->MODE         = (PWM_MODE_UPDOWN_Up << PWM_MODE_UPDOWN_Pos);
  
	PWM->DECODER      = (PWM_DECODER_LOAD_Common << PWM_DECODER_LOAD_Pos) |
                      (PWM_DECODER_MODE_RefreshCount << PWM_DECODER_MODE_Pos);

	PWM->PRESCALER    = (PWM_PRESCALER_PRESCALER_DIV_16 << PWM_PRESCALER_PRESCALER_Pos);
	PWM->COUNTERTOP   = (TIMER_RELOAD << PWM_COUNTERTOP_COUNTERTOP_Pos);
	
	PWM->SEQ[0].PTR   = ((uint32_t)(pwm_buffer) << PWM_SEQ_PTR_PTR_Pos);
	PWM->SEQ[0].CNT   = ((sizeof(pwm_buffer) / sizeof(uint16_t)) << PWM_SEQ_CNT_CNT_Pos);
 
	//PWM->SEQ[1].PTR   = ((uint32_t)(pwm_buffer) << PWM_SEQ_PTR_PTR_Pos);
	//PWM->SEQ[1].CNT   = ((sizeof(pwm_buffer) / sizeof(uint16_t)) << PWM_SEQ_CNT_CNT_Pos);

	PWM->SEQ[0].REFRESH = 0;
	PWM->SEQ[0].ENDDELAY = 0;

	//PWM->LOOP = (PWM_LOOP_CNT_Disabled << PWM_LOOP_CNT_Pos);
	PWM->LOOP = (4 << PWM_LOOP_CNT_Pos);

	PWM->SHORTS = PWM_SHORTS_LOOPSDONE_SEQSTART0_Msk;

	PWM->TASKS_SEQSTART[0] = 1;

Parents
  • Hello Lerby,

    Sorry for the late answer here. I am happy to hear that you were able to resolve this issue!
    Thank you for sharing the solution to your issue as well, this could help future forum goers that encounter the same questions.

    I notice in your original post that you are manipulating the PWM peripheral registers directly, but that in your comment you are making use of the nrfx_pwm driver. As a general recommendation I would advice you to not mix these two approaches, as manipulating the registers directly while using the driver might place the driver in an invalid state and thus break it.
    I suspect that you now only use the nrfx_driver anyways, but I thought I should mention this just in case.

    Please do not hesitate to open a new ticket if you should encounter any issues or questions in the future.

    Good luck with your development!

    Best regards,
    Karl

Reply
  • Hello Lerby,

    Sorry for the late answer here. I am happy to hear that you were able to resolve this issue!
    Thank you for sharing the solution to your issue as well, this could help future forum goers that encounter the same questions.

    I notice in your original post that you are manipulating the PWM peripheral registers directly, but that in your comment you are making use of the nrfx_pwm driver. As a general recommendation I would advice you to not mix these two approaches, as manipulating the registers directly while using the driver might place the driver in an invalid state and thus break it.
    I suspect that you now only use the nrfx_driver anyways, but I thought I should mention this just in case.

    Please do not hesitate to open a new ticket if you should encounter any issues or questions in the future.

    Good luck with your development!

    Best regards,
    Karl

Children
No Data
Related