Hello,
I am trying to use PWM block of iMX286. I read the datasheet carefully and also read another thread at https://community.freescale.com/message/273292#273292 but it does not work yet.
My code did the following steps:
1. Setup HW_PINCTRL_MUXSELx register to enable PWM pin
2. Soft reset PWM block by clearing the two bits SFTRST and CLKGATE of HW_PW_CTRL register
3. Update value for the two registers HW_PWM_ACTIVEx and HW_PWM_PERIODx to set the period and duty cycle of output pulses
4. Enable PWM channel by setting bit in HW_PW_CTRL register
Could you let me know is there any wrong step?
Thanks,
Solved! Go to Solution.
Hi all,
I fixed the problem successfully by setting inactive period in HW_PWM_ACTIVEx register.
writel(0x4FFF2ee0, HW_PWM_ACTIVE7); //12000 ticks
The inactive period should be bigger than active period so the PWM block works as following description
1. The internal counter reset to 0 and start increasing
2. When the counter equal or greater than ACTIVE period, the PWM ouput change to Active state (HIGH level in my case)
3. When the counter equal or greater than INACTIVE period, the PWM output change to In-Active state (LOW level in my case)
The code works well.
Thuan.
Here is my source code:
writel(1<<20, HW_PINCTRL_MUXSEL7_SET);
writel(1<<21, HW_PINCTRL_MUXSEL7_CLR);
// Set the HW_PINCTRL_DRIVEx (3.3V, 12mA)
writel(0x00000600, HW_PINCTRL_DRIVE15_SET);
writel(1<<29 | 1 <<30, HW_CLKCTRL_XTAL_CLR); //gate clock for PWM
/* Reset PWM module*/
writel(1<<31, HW_PWM_CTRL_CLR); //SFTRST = 0;
/* Enable clock*/
//for(i = 100; i; i--);
writel(1<<30, HW_PWM_CTRL_CLR); //CLKGATE = 0;
writel(1<<7, HW_PWM_CTRL_CLR); //Disable PWM7
// Setup PWM channels
writel(0x00002ee0, HW_PWM_ACTIVE7); //12000 ticks
writel(0x000E5DBF, HW_PWM_PERIOD7); //24000 ticks
writel(1<<7, HW_PWM_CTRL_SET); //Enable PWM7
I checked the value of control and status register (all registers was set properly)
HW_CLKCTRL_XTAL: 00 00 00 01
HW_PWM_CTRL: 3F C0 00 80 (PWM7 is enabled)
HW_PWM_ACTIVE7: 00 00 2E E0
HW_PWM_PERIOD7: 00 0E 5D BF
Hi all,
I fixed the problem successfully by setting inactive period in HW_PWM_ACTIVEx register.
writel(0x4FFF2ee0, HW_PWM_ACTIVE7); //12000 ticks
The inactive period should be bigger than active period so the PWM block works as following description
1. The internal counter reset to 0 and start increasing
2. When the counter equal or greater than ACTIVE period, the PWM ouput change to Active state (HIGH level in my case)
3. When the counter equal or greater than INACTIVE period, the PWM output change to In-Active state (LOW level in my case)
The code works well.
Thuan.