Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

implement PWM as a counter in LPC2368

Status
Not open for further replies.
check this code

PWM1TCR=0X0B;
PWM1CTCR=0X01;
PINSEL4 |=0x00001000;
PWM1CCR=0X01;

while(1)
{
if(PWM1IR&0x10==0x10) //Interrupt flag for capture input 0
{
count++;
print count(count);
PWM1IR=0x10;// to clear the Interrupt need to write 1
}
}

---------- Post added at 06:19 ---------- Previous post was at 06:14 ----------

this will work check it

PWM1TCR=0X0B;
PWM1CTCR=0X01
PINSEL4 |=0x00001000;//select pinP2.6 as PCAP1.0
PWMICCR=0X01

while(1)
{
if(PWM1IR&0X10==0X10)
{
count++;
print the count(count);
PWM1IR=0x10;//to reset the Interrupt
}
}
 

i think the code should be
if(PWM1IR&0X01==0X01)
instead of
if(PWM1IR&0X10==0X10)

correct me if i am wrong

because bit 4 is reserved
 
Last edited:

PWMCAP0 Interrupt- Interrupt flag for capture input 0

---------- Post added at 06:45 ---------- Previous post was at 06:43 ----------

i think the code should be
if(PWM1IR&0X01==0X01)
instead of
if(PWM1IR&0X10==0X10)

correct me if i am wrong

why you are going for match
if there is any pulse captured then the this intrpt is enabled
 

But as i said the interrupt flag "PWMCAP0" is available only in LPC2468(your micrcontroller)
but not in LPC2368(my microcontroller) thats why i m stuck. what flag to check if an event occurs.
 

But as i said the interrupt flag "PWMCAP0" is available only in LPC2468(your micrcontroller)
but not in LPC2368(my microcontroller) thats why i m stuck. what flag to check if an event occurs.

interrupt flag is their in LPC 2368 also....

---------- Post added at 07:28 ---------- Previous post was at 07:26 ----------

check the interrupt register of PWM module i.e PWM1IR
569 page of lpc23xx user manual
 

Dear embedded partner,thanks a lot for all your replies..actually i was using the User manual meant for LPC2364/65/66/67/68 thats why i was facing problem..

but i haven't tested the code because i am designing the hardware.
for testing purpose i am using LM555 to switch a transistor and later pulse from collector to ucontroller pin.

i don't have any knowledge about the type of pulse i will get from the vehicle speed sensor...
the interface in the vehicle(meant for pulse) contains 3 wire red,black and green...
thanks
 

dear i have tried you code but it didn't work...don't know why...all the settings are ok but still...
my code is:
PINSEL4 |=0x00001000;//select pinP2.6 as PCAP1.0


PWM1TCR=0X02; //bit 0->Counter Enable,bit1->Counter Reset on next pulse
PWM1CTCR=0X01; //Count Control Register. The CTCR selects between Timer and
//Counter mode, and in Counter mode selects the signal and
//edge(s) for counting.

PWM1CCR=0X04; //A synchronously sampled rising edge on the CAPn.0 input
//will cause CR0 to be loaded with the contents of the TC.
PWM1TCR=0X01; //enable TC

count=0;
while(1)
{
Update_WDT();
if((PWM1IR & 0x10)==0x10) //Interrupt flag for capture input 0
{
uart0Puts("I am IN 2\n\r");
count++;
uart0Puts(conv_itoa(count));
PWM1IR=0x10;// to clear the Interrupt need to write 1
PWM1TCR=0X01;
}
}
 

check the hyper terminal by sending some data .

---------- Post added at 08:30 ---------- Previous post was at 08:26 ----------

display some data on the hypertermial before waiting for the interrupt flag
 
the hyperterminal is OK.i've checked it..but it is not detecting the interrupt..i think there is a fault in the code
 

PWM mode
causes the shadow registers to operate in connection with
the Match registers.

---------- Post added at 09:52 ---------- Previous post was at 09:52 ----------

A program write to a Match register will
not have an effect on the Match result until the
corresponding bit in PWMLER has been set, followed by the
occurrence of a PWM Match 0 event.
 
Last edited:
but i think PWMLER is used for PWM generation.but here i am counting external pulse

---------- Post added at 14:09 ---------- Previous post was at 12:44 ----------

hey friend thanks a lot for your help.you were like more than a friend....
actually i didn't initialize the TC and PC. so i did TC=0x00; and PC=0x00; and it worked out.it was such a silly mistake....

i hope our conversation would be useful to other embedded engineers also who are working on the same application.

now only the task left is to install my device in vehicle.but i don't know the no of pulse for 1 complete revolution so as to calculate the distance.i'll have to check out the same physically. will let you know the same.


once again thanks a lot:)
 

hey friend just have a look on my code

i implemented the above code using interrupt and set the VICs but my program is not entering the routine

VICVectAddr5 = (unsigned long)PWM_CAPTURE_IRQHandler;/* Set Interrupt Vector */
VICVectCntl2 = (1 << 5) | 8; /* use it for Timer0 Interrupt */
VICIntEnable = (1 << 8);

is the above setting OK?

VICVectAddr5 -> 5 is unused in my code
VICVectCntl2 = (1 << 5) | 8;
here 2 is priority after timer(timer0 is 1) and (1<<5) is enable VIC
VICIntEnable = (1 << 8);
here i am enabling VIC.
please reply....
 

in the user manual VICVectCntl definition is not there.so i used other resisters..i m not in office thats y i can not send the code i'll send u on Monday...

but tell me....i've given 1st priority to timer0...and 2nd priority to pulse capture counter.. but how it would work.because pulse counting will generate regular interrupt.please reply
 

you know that in timer module capture module is also their....
if any of the timer0/capture0 interrupt occures then PC will go to isr and excecute it.

it is not possible to set priority for timer0 and capture0 modules separately.
 

but how should i implement the PWM pulse count.I can not implement in IRQ because this will generate regular interrupt.right?

please reply
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top