LPC1769 : using the MCPWM

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

LPC1769 : using the MCPWM

1,216 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ethankhoo on Wed Sep 19 01:31:19 MST 2012
Hi everyone, i would like to ask about the cmsis library available for the MCPWM function in LPC1769.

i am having problems understanding certain requirements of the function,

in all the functions, there is a requirement to put in a *MCPWMx
[SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][SIZE=2] [B]MCPWM_Init[/B]([/SIZE][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032][U]LPC_MCPWM_TypeDef[/U][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][U] *MCPWMx[/U])[/SIZE][SIZE=2][COLOR=#7f0055]

[/COLOR][/SIZE][SIZE=2] [B]MCPWM_ConfigChannel[/B]([/SIZE][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032][U]LPC_MCPWM_TypeDef[/U][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][U] *MCPWMx[/U], [/SIZE][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]uint32_t[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] channelNum,[/SIZE]
[SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]MCPWM_CHANNEL_CFG_Type[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] * channelSetup)[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2]May i know what exactly are they asking for? i cant seem to put in an appropriate variable.[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2]Thanks for your help and i would appreciate any help.[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2]A sample code for initialization would be greatly appreciated too.[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2]Thank you all[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2][/SIZE]
0 Kudos
Reply
3 Replies

1,123 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Thu Sep 20 10:28:53 MST 2012
What a rude pal!!

In this code

LPC_MCPWM_TypeDef dummy;

MCPWM_Init(&dummy);


you're declaring a struct variable in user RAM (local or globally), so the reference [I]&dummy[/I] points to your RAM; however, you need to make it point to the TIMERs spaces. You can accomplish that in this way:

LPC_TMR_TypeDef * tmr32b0 = (LPC_TMR_TypeDef *)(LPC_CT32B0_BASE);
LPC_TMR_TypeDef * tmr32b1 = (LPC_TMR_TypeDef *)(LPC_CT32B1_BASE);
LPC_TMR_TypeDef * tmr16b0 = (LPC_TMR_TypeDef *)(LPC_CT16B0_BASE);
LPC_TMR_TypeDef * tmr16b1 = (LPC_TMR_TypeDef *)(LPC_CT16B1_BASE);

where tmr32b0..tmr16b1 are names that I choose, so you might change them. I used this snippet for the LPC1114, so you should take a look at the LPC1769 MCU's documentation to properly set the base addresses. Timer modules (and other peripherals) are identical in both MCUs.

Finally, you call the PWM API functions this way:

MCPWM_Init(tmr32b0);


As the tmr32b0 is already a pointer, then you don't need the '&' operator.
0 Kudos
Reply

1,123 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ethankhoo on Thu Sep 20 07:11:14 MST 2012

Quote: fjrg76
It maps the timer registers to a struct, so the programmer can write to or read from them through a pointer.

No code available, but you can check its internals here:

http://www.ethernut.de/api-beta/lpc176x_8h_source.html

(Inside the webpage find "LPC_MCPWM_TypeDef".)

This is kind of object programming in C. The LPC_MCPWM_TypeDef struct is the "class" from which several objects (pwm channels on the MCU) instantiates. So, if the MCU has 3 identical timers, you'll have 3 objects: pwm0, pwm1 and pwm2, or whatever name you choose. This objects have attributes (the fields onto the struct) and operations on those attributes (_init(), _configure(), _get(), and so on).

From here you can implement simple inheritance and polymorphism.



i know it is suppose to be a struct type variable, i tried doing this

LPC_MCPWM_TypeDef dummy;

[SIZE=2][B]MCPWM_Init[/B]([COLOR=#005032]&dummy[/COLOR]);[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2]but it doesn't seem to work. what exactly am i suppose to declare in dummy??[/SIZE][COLOR=#7f0055]


[/COLOR]
0 Kudos
Reply

1,123 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjrg76 on Wed Sep 19 15:17:04 MST 2012
It maps the timer registers to a struct, so the programmer can write to or read from them through a pointer.

No code available, but you can check its internals here:

http://www.ethernut.de/api-beta/lpc176x_8h_source.html

(Inside the webpage find "LPC_MCPWM_TypeDef".)

This is kind of object programming in C. The LPC_MCPWM_TypeDef struct is the "class" from which several objects (pwm channels on the MCU) instantiates. So, if the MCU has 3 identical timers, you'll have 3 objects: pwm0, pwm1 and pwm2, or whatever name you choose. This objects have attributes (the fields onto the struct) and operations on those attributes (_init(), _configure(), _get(), and so on).

From here you can implement simple inheritance and polymorphism.
0 Kudos
Reply