LPC1837 SCT Timer PWM Duty Problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1837 SCT Timer PWM Duty Problem

1,438 Views
ertugrulkocaaga
Contributor I

Hello there,

I am trying to use SCT timer to produce one channel pwm for my project. I have used the cookbook as reference. I am setting duty cycle as I wish but when I set the duty cycle to 0%  (LPC_SCT->MATCHREL[1].L = 0) I saw mini pulses. I measured them and I saw that they were at 10MHz, meaning of SCT clock frequency. So SCT first starts the pwm as high and although the duty value is zero it takes 100ns to understand and clears the output. So actually, I can never get 0% even if I set duty register to 0. How can I proceed from now on? Is it a code bug or peripheral bug?

Thanks in advance,

Ertuğrul Kocaağa

   //PWM PIN CONFIGURATION
    SCU_PinConfigure(1, 7,  (SCU_CFG_MODE_FUNC2 | SCU_PIN_CFG_PULLDOWN_EN));
    
    LPC_SCT->CONFIG |= (1 << 17); // two 16-bit timers, auto limit
    LPC_SCT->CTRL_L |= ((18-1) << 5); // set prescaler, SCTimer/PWM clock = 10 MHz
    
    LPC_SCT->MATCHREL[0].L = 10000-1; // match 0 @ 10/1MHz = 1 msec (1 kHz PWM freq)
    LPC_SCT->MATCHREL[1].L = 5000; // match 1 used for duty cycle
    
    LPC_SCT->EVENT[0].STATE = 0xFFFFFFFF; // event 0 happens in all states
    LPC_SCT->EVENT[0].CTRL = (1 << 12); // match 0 condition only
    
    LPC_SCT->EVENT[1].STATE = 0xFFFFFFFF; // event 1 happens in all states
    LPC_SCT->EVENT[1].CTRL = (1 << 0) | (1 << 12); // match 1 condition only
    
    LPC_SCT->OUT[13].SET = (1 << 0); // event 0 will set SCTx_OUT13
    LPC_SCT->OUT[13].CLR = (1 << 1); // event 1 will clear SCTx_OUT13
    
    LPC_SCT->CTRL_L &= ~(1 << 2); // unhalt it by clearing bit 2 of CTRL reg

Labels (2)
2 Replies

1,094 Views
ertugrulkocaaga
Contributor I

Is there anyway doing this procedure without using the LPCOpen Drivers? I would like to do it as I showed (register based) because of the company policies. Also did you have a chance to test zero duty cycle? When I read the user manual I saw what in EVCTRL register that, bit10 and bit11 are called IOCOND. It says "11:10 IOCOND Selects the I/O condition for event n. (The detection of edges on outputs lags theconditions that switch the outputs by one SCT clock). In order to guarantee proper edge/state detection, an input must have a minimum pulse width of at least one SCT clock period ."

So if the same thing applies the duty register, then does it mean that in reality I can never have zero duty? 

Thanks in advance,

Ertuğrul Kocaağa

0 Kudos

1,094 Views
soledad
NXP Employee
NXP Employee

Hi,

Please try using the LPCOpen sct_pwm driver. The sct_pwm example ses the SCT PWM driver to create 2 independent PWMs (running at the same frequency). The PWM1 is used to output a square wave to an Output pin and PWM2 is used to control the brightness of the LED, the brightness goes from 0% to 100% in steps of 0.5% every 20 Milliseconds and goes down to 0% in the same step. Connect oscilloscope to the PWM OUT pin and the waveform displayed on the scope will have its duty cycle increasing from 0% to 100% in steps of 10% every second.

You can use this example as reference.

How to use SCT as a standard PWM using LPCOpen? 


Have a great day,
Sol
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------