Content originally posted in LPCWare by Jantje7600 on Tue Oct 07 12:14:23 MST 2014
Hello everyone,
I have a LPC1769 microcontroller and I would like to use it for my DC-AC inverter (using PWM).
I am a newbie, I have figured out how the blinky program works and a little bit more :)
On the internet I could not found any useful tutorial or book (I have read the user manual), many people on the internet say look at the examples. Well I did that but for me it is still not clear and the manual isn't a tutorial.
Along the way I have marked my questions with a number.
Please correct me if I'm wrong:
If I want to select GPIO Port 2.0 I use the following code:
// Select P2.0 and use GPIO Port 2.0 function
LPC_PINCON->PINSEL4 |= ( (0<<0) | (0<<1) );
1) so LPC_PINCON is always used when a pin needs to be selected ?
//According to manual: FIODIR = Fast GPIO Port Direction control register. This register individually controls the direction of each port pin.
// Set pin P2.0 as output
LPC_GPIO2->FIODIR = (1<<0);
2) Okay, so when do I use FIODIR? Only when I have to declare the pin as an input or output?
// Set pin P2.0 high
LPC_GPIO2->FIOPIN |= (1<<0);
3) I have seen the following & = ~ so LPC_GPIO2->FIOPIN &= ~(1<<0); does this mean "disable" ? When is this used?
Now the real part comes. I want to use PWM (in combination with a driver IC) to drive my MOSFETS. First I want to know how I can use the PWM functionality of the LPC1769 to drive only one MOSFET.
To set the frequency of the PWM signal I need to use the clock frequency of the microcontroller I believe...
4) So do I have to use PCLKSEL0 and PCLKSEL1 ? If yes, how can I set them (please show the code :p, I think it is one line) ?
5) For pin select I use LPC_PINCON and for pheripheral clock I use LPC_SC is this correct?
In the manual it says: "Peripheral clock: In the PCLKSEL0 register (Table 40), select PCLK_PWM1. "
6) Do I have to set it to 00 or 01 or 10 or 11? And why?
So assume I set it like this:
LPC_SC->PCLKSEL0 |= ((1 << 12) | (1 << 13));
Then
LPC_PINCON->PINSEL4 |= ( (1 << 0) | (0 << 1) ); //select PWM 1.1
and
LPC_PINCON->PINMODE4 |= ((0 << 0) |(1 << 1)); //Port 2 pin 0 control, this is somehow needed because of the pull-up/pull-down register which are both disabled
7) Have I missed something else? I just want to use a PWM to drive MOSFETS in order to drive my full bridge DC-AC inverter ( When I have finished this I will use a good Driver IC with bootstrapping for the inverter because the microcontroller cannot supply enough current to charge up the gate capacitance of the MOSFETS)
I know it is a lot but I would appreciate your help ! I really really searched a lot on the internet... Thanks