I need to generate PWM signal in cortex-M3. With timer example program i changed some part of the code. While compiling i was having one warning as systemclockupdate. While building the target is not created. Please help me.
Thank You.
What part of the code did you change?? The error or warning has a number. Provide the error/warning number.
Most Cortex-M3 architectures have an on-chip PWM module and dedicated PWM output channels. Why not use the module? It will reduce the burden on the software and hence the CPU. :)
I changed the interrupt handling part. Actually the warning is #223-D:function "Systemclockupdate" declared implicitly. Actually if i remove this line no error. I will be thankful if i get full details about systemclockupdate.
Thank You
Do you understand what "implicitly" means? Do you have any function named "Systemclockupdate"? If you have a function named "Systemclockupdate", then have you declared the function before calling it?
I removed systemclockupdate nd i included system init(). Now its working. but am not getting expected result. I need a square wave of ON period of 1ms and OFF period of 15ms, totally 16ms duty cycle. But am getting 16.9ms duty cycle.I duno where it gone wrong..? Can u help me please.
"I need a square wave of ON period of 1ms and OFF period of 15ms, totally 16ms duty cycle. But am getting 16.9ms duty cycle.I duno where it gone wrong..? Can u help me please."
So must be something wrong with line 123 then.
Per, Dnt be sarcastic. But the comment was funny.(sic)
Divya, The prescale value or the match register value is not proper. But that are only my guesses. Post the code. we cant solve anything without looking at the code.
Oki sir. I ,ll check it out. Anyway i ll show my code.
void TIMER0_IRQHandler (void) { if ( LPC_TIM0->IR & (0x1<<0) ) { LPC_TIM0->IR = 0x1<<0; timer0_m0_counter++; if ( ( LPC_TIM0->TCR == TIME_INTERVALmS * 15) ) { reset_timer( 0 ); enable_timer (0); LPC_TIM0->MR0 = TIME_INTERVALmS * 1; LPC_GPIO0->FIOSET|=(1<<21); LPC_GPIO1->FIOSET = 1<<29; } if (LPC_TIM0->TC == TIME_INTERVALmS * 1 ) { reset_timer( 0 ); enable_timer (0); LPC_GPIO0->FIOCLR|=(1<<21); LPC_GPIO1->FIOCLR = 1<<29; LPC_TIM0->MR0 = TIME_INTERVALmS * 15; } } if ( LPC_TIM0->IR & (0x1<<1) ) { LPC_TIM0->IR = 0x1<<1; timer0_m1_counter++; } if ( LPC_TIM0->IR & (0x1<<4) ) { LPC_TIM0->IR = 0x1<<4; timer0_capture0++; } if ( LPC_TIM0->IR & (0x1<<5) ) { LPC_TIM0->IR = 0x1<<5; timer0_capture1++; } return; }
uint32_t init_timer ( uint8_t timer_num, uint32_t TimerInterval ) { uint32_t pclkdiv, pclk; if ( timer_num == 0 ) { timer0_m0_counter = 0; timer0_m1_counter = 0; timer0_capture0 = 0; timer0_capture1 = 0; LPC_SC->PCONP |= (0x01<<1); #if TIMER_MATCH LPC_PINCON->PINSEL3 &= ~((0x3<<24)|(0x3<<26)); LPC_PINCON->PINSEL3 |= ((0x3<<24)|(0x3<<26)); #else LPC_PINCON->PINSEL3 &= ~((0x3<<20)|(0x3<<22)); LPC_PINCON->PINSEL3 |= ((0x3<<20)|(0x3<<22)); #endif LPC_TIM0->IR = 0x0F; pclkdiv = (LPC_SC->PCLKSEL0 >> 2) & 0x03; switch ( pclkdiv ) { case 0x00: default: pclk = SystemFrequency/4; break; case 0x01: pclk = SystemFrequency; break; case 0x02: pclk = SystemFrequency/2; break; case 0x03: pclk = SystemFrequency/8; break; } LPC_TIM0->PR = pclk/1000000; /* set prescaler to get 1 M counts/sec */ LPC_TIM0->MR0 = TIME_INTERVALmS * 15; /* Set up 15 mS interval */ #if TIMER_MATCH LPC_TIM0->EMR &= ~(0xFF<<4); LPC_TIM0->EMR |= ((0x3<<4)|(0x3<<6)); #else /* Capture 0 and 1 on rising edge, interrupt enable. */ LPC_TIM0->CCR = (0x1<<0)|(0x1<<2)|(0x1<<3)|(0x1<<5); #endif LPC_TIM0->MCR = (0x3<<0); //|(0x3<<3); /* Interrupt and Reset on MR0 and MR1 */ NVIC_EnableIRQ(TIMER0_IRQn); return (TRUE); }
Please help me where i done mistake...
Are you sure that this is correct? No off-by-one error, if you compare with the datasheet?
LPC_TIM0->PR = pclk/1000000; /* set prescaler to get 1 M counts/sec */
What is mS? Would be milli-Siemens if using ISO units. Don't you mean milli-seconds, i.e. lower-case "s"?
LPC_TIM0->MR0 = TIME_INTERVALmS * 15; /* Set up 15 mS interval */
You use a symbol TIME_INTERVALmS, that you don't tell us what it is.
Next thing - your timer have four different match registers. You use a single match register.
What do you think happens if you use two match registers - one for 15ms and one for 16ms. Generate interrupt for both. Let the second match register also reset the timer? Wouldn't you see an advantage in a timer that automagically restarts with zero time lost for reloading?
If you manually reconfigure the timer and restarts it, you will always leak time - it takes some time for the interrupt to be activated. Then the interrupt need to decide what to do. Then time to run the functions you don't show us to reset_timer() and enable_timer().
Another interesting thing: Your code performs absolute tests on timer registers. What happens if that register happens to tick one tick further before you have time to make that == compare? Isn't it better to just let the hardware in the timer perform the == operation, and you just quickly check which of the four match registers that detected a match? Why have hardware-acceleration if ignoring it and duplicating the functionality in software?
And by the way - your code is not easy to read. Lack of comments and not tagged as code. You didn't notice and got disappointed at the look directly when posting?