Reply by swee...@hotmail.com●January 31, 20082008-01-31
Thank you very much.
Reply by "ryan.gossink"●January 26, 20082008-01-26
As promised I have 'improved' the code I aupplied before, it is not
perfect, though this should be a bit more robust than the old code. I
have tried to keep it fairly portable.
I have not had time to set it up to configure all of the registers
automatically, though adding the few extra lines if you need them
should be very straight forward. Code below:
#include // LPC2119 MPU Register
#include
/
**********************************************************************/
/************ The sections below here can be modified for
*************/
/*************the desired frequency and to match the host
*************/
/
**********************************************************************/
//The macro below defines the desired PWM frequency in hertz
#define PWM_FREQ (100)
//This is the core clock frequency for the CPU core
#define CPU_CORE_CLCK 58980000
//Pin output divider value
#define PBSD 2
/
**********************************************************************/
/
**********************************************************************/
/
**********************************************************************/
/
***********************************************************************
The Inisitalise PWM function is intended to configure the neceasry
registers to enable a PWM driver, the number parameter refers to the
output of ineterest.
***********************************************************************/
void InitialisePWM(unsigned char number){
if (number == 1){
PCB_PINSEL0 &= 0xFFFFFFFC; //P0.0 as PWM1
PCB_PINSEL0 |= 0x00000002;
}
if (number == 2){
PCB_PINSEL0 &= 0xFFFF3FFF; //P0.7 as PWM2
PCB_PINSEL0 |= 0x00008000;
}
if (number == 3){
PCB_PINSEL0 &= 0xFFFFFFF3; //P0.1 as PWM3
PCB_PINSEL0 |= 0x00000008;
}
// PWM Init
PWM_TCR = PWMCR_RESET; // reset PWM counter
PWM_PR = PWM_PCLK_DIV; // set PWM Prescaler
PWM_MR0 = PWM_MR0INIT; // set Match0 (for the Single
Edge PWM-Channels)
PWM_LER |= (1<<0); // Enable PWM Match0 Latch
PWM_MCR |= (1<<1); // reset PWM Timer on PWMMR0
match
PWM_PCR &= ~(1<
speciefied PWM
PWM_PCR |= (1<<(8+number)); // enable outputs for specified
PWM
/
***********************************************************************
The set duty cycle function is intended to set the duty cycle of a
specified PWM, the first value is the duty cycle, a float is used to
allow greater control, the second value is the number of the PWM to
use.
***********************************************************************/
if (number==1) PWM_MR1 = (int)((PWM_MR0INIT*duty_cycle)/100L);
if (number==2) PWM_MR2 = (int)((PWM_MR0INIT*duty_cycle)/100L);
if (number==3) PWM_MR3 = (int)((PWM_MR0INIT*duty_cycle)/100L);
if (number==4) PWM_MR4 = (int)((PWM_MR0INIT*duty_cycle)/100L);
if (number==5) PWM_MR5 = (int)((PWM_MR0INIT*duty_cycle)/100L);
if (number==6) PWM_MR6 = (int)((PWM_MR0INIT*duty_cycle)/100L);
PWM_LER |= (1<
}
Reply by "ryan.gossink"●January 24, 20082008-01-24
I am using the following code at the moment (I haven't cleaned it up,
or made it generic, but I intend to make a generic version with
better doc), it is based on code from Martin Thomas' T-Clock ( http://
gandalf.arubi.uni-kl.de/avr_projects/arm_projects/ ), once the PWM
has been initialised just send a number using the set brighness
function (duty cycle as an integer), frequency is set at the top in
the PWM_FREQ macro.
You should be able to more or less drop this into your existing code
and change labels to match whatever PWM output you are using.
I wasnt bothered by correct frequency, just converting ADC to a PWM level. I
did not read the right post, I accidently read reply to your post, new to
forum myself, learning how to use it!.
Use or ignore what I sent when i pasted the code, it just sets the pwm to
respond to the adc, it IS a multi channel ADC to PWM, if thats any use...
nice because you can vary brightness of couple of LED's with two
potentiometers, but I didnt use or care about the frequency.
Good luck
-----Original Message-----
From: l... [mailto:l...]On Behalf Of
s...@hotmail.com
Sent: 24 January 2008 06:53
To: l...
Subject: [lpc2000] How to use PWM on LPC2119?
I want to know how to use PWM.
I use Keil and LPC2119.
Please give me some example code.
and told me how to set Frequency, duty ratio and anything that
important to know when use PWM.
I'd read in datasheet and try by myself for a month but it's
still
don't work.
Please help me.
Thank for advance.
09:58
Reply by gareth james●January 24, 20082008-01-24
'Bogders toolkit' here, I've tried to get a few things working
for future
work as I'm learning ARM myself since dec 2007
Have a code dump, this is a get going what you can demo, with adc measured
from potentiometer and sent to the pwm and lcd. (then i fiddled and messed
with the RTC to set it using switches.)
I don't fully understand what I've done, but it works as far as I
know,
since its 90% borrowed code , you will have to put the init type functions
first as i've pasted from a project, hope this helps (eg init serial,
init
adc should go first)
the sections you are interested in are where I've put the xxxxxxxxs,
sorry
about the other junk in the way to do with LCD etc
Gareth
/***************************************************************************
*************/
/* Target MCU : Philips ARM7-LPC2119 : X-TAL : 19.6608 MHz
(58.9824MHz) */
/* : X-TAL : 19.6608 MHz (58.9824MHz)
*/
/* Function : Example PWM2(P0.7) & ADC0(P0.27)
*/
/***************************************************************************
*************/
#include // LPC2119 MPU Register
#include // For Used Function printf
#include
#include
init_serial_pwm(); //init the serial output to the comm port AND the pwm
registers
// PINSEL0 = 0x00000000;
IODIR0 = 0x00000018; //PART 3 set io on for all except lower bit for
serial comms and bit 10,11 for i/p
while(1) // Loop Continue
{
delay2++;
if(delay2>10){ //output to lcd
goto_cursor(0x00); // Set Cursor Line-1
sprintf(ztime,"%02u-%02u %02u:%02u:%02u",DOM,MONTH,HOUR ,MIN, SEC );
//ztime=toascii(SEC);
lcd_print(ztime); // Display LCD Line-1
goto_cursor(0x40);
//sprintf(zadc,"%01u:%01u :%04u",(adcsnap1/64),(adcsnap2/64),IOPIN0 );
// Set Cursor = Line-2
iopin24= IOPIN1&0x02000000;
iopin24=(iopin24>>25);
iopin23= IOPIN1&0x01000000;
iopin23=(iopin23>>24);
iopin22= IOPIN1&0x00800000;
iopin22=(iopin22>>23);
iopin21= IOPIN1&0x00400000;
iopin21=(iopin21>>22);
-----Original Message-----
From: l... [mailto:l...]On Behalf Of
Pont, Michael J.
Sent: 24 January 2008 08:59
To: l...
Subject: Re: [lpc2000] How to use PWM on LPC2119?
>I want to know how to use PWM.
> I use Keil and LPC2119.
> Please give me some example code.
s...@hotmail.com wrote: > Thank for help me.
>
> I want to know how to write code with keil?
>
> what register i must to set.
> and what i write in code that make output.
>
> Example I want a output with 60kHZ and duty cycle 50%
> on port PWM1.
> How to write?
I think you'll need to look up the RTFM register. I can't
remember the exact page but if you start looking near the
beginning of the LPC2119 User manual you'll be sure to see it.
Ralph
Reply by swee...@hotmail.com●January 24, 20082008-01-24
Thank for help me.
I want to know how to write code with keil?
what register i must to set.
and what i write in code that make output.
Example I want a output with 60kHZ and duty cycle 50%
on port PWM1.
How to write?
Thank for advance,
SweetCorn
Reply by "Pont, Michael J."●January 24, 20082008-01-24
>I want to know how to use PWM.
> I use Keil and LPC2119.
> Please give me some example code.
Reply by swee...@hotmail.com●January 24, 20082008-01-24
I want to know how to use PWM.
I use Keil and LPC2119.
Please give me some example code.
and told me how to set Frequency, duty ratio and anything that
important to know when use PWM.
I'd read in datasheet and try by myself for a month but it's still
don't work.
Please help me.