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

nRF9160 PWM

Hello,

I'm trying to test PWM with a simple example, I've edited spm via adding

KConfig:

spm.c

I'm getting the output at the boot as;

I assume that PWM_0 initialized as Non-Secure successfully.

When I try the code, I don't get any error but I cannot see output on P0.2 either.

Parents
  • This is prj.conf file

  • I played a bit around with the PWM, and here's my example:

    pwm.zip

     

    Could you try this one and see if it works?

    The build/zephyr/merged.hex includes spm (secure_boot). Try this .hex first to see if it works at your end as well, prior to building.

     

    Kind regards,

    Håkon

Reply
  • I played a bit around with the PWM, and here's my example:

    pwm.zip

     

    Could you try this one and see if it works?

    The build/zephyr/merged.hex includes spm (secure_boot). Try this .hex first to see if it works at your end as well, prior to building.

     

    Kind regards,

    Håkon

Children
  • Hello Håkon,

    I've tried your sample and I've realized that I actually have pwm signal on P0.2 but with a super small peak-peak voltage level. I'm attaching my scope output. After realizing that I've tried my first sample and the result is same, pwm signal exist but with a low voltage output. 

    Do you think it's a hardware issue?

    My another question is about timings of signal?

    In your example the duty cycle keep going up and between 0-255us. And the period is set to 255us.

    My scope shows the period of signal 500us and duty of signal keep changing between 50% to 100%. How can I get a pwm signal below 50%? If i try to give pulse time, bigger than period, I'm getting an error as "<err> pwm_nrfx: Invalid pulse_cycles 4096, > period_cycles 4080." as expected.

  • That looks like crosstalk. Are you sure you are scoping the correct pin? If you are using the nRF9160-DK, the LEDs are not routed to the pin lists, so you have to scope from the left side of the LED1.

     

    Did you try the .hex in my .zip to see if that one worked?

     

    Kind regards,

    Håkon

  • The result was same with your hex too. You are right that was the cross talk. I  haven't checked the schematics if the P0.2 at P17 is directly connected to the microcontroller. Apperantly P0.2 is controlling a digital switch which is connected to the P17 and led1.

    I've switched the output of PWM_0 to another pin and its working well now.

    On my previous message I said I cannot get PWM signal below %50 but it's reverse actually. I cannot get PWM signal above %50 duty cycle.

    With this function if I put period 250, the period of signal is 500us.

    when the pulse 1, the duty cycle is 1%;

    When the pulse 250, the duty cycle is 50%.

    If I try to put something bigger that 250, I'm getting invalid pulse_cycle error.

    Regards,

    Gurkan

  • This is weird. If I input > 1000 on both period and pulse, it behaves "as expected", however; if I provide pulse=250 and period=500, it goes haywire.

    Pulse is correct-ish, 252 us, while the period is way off at 753 us. I would expect DC of 50%, but get approx. 25%.

    I'll report it internally.

    Best regards,

    Håkon

  • Thank you Håkon,

    Have a nice day.

    Regards,

    Gurkan