@ everybody(Erik, Per & ...) it is very interesting for me to know how did you found that i am an electronic student??? and which school session, is finished at October (in my country)? unfortunately internet is full of 'EXPERT TROLLs' instead of real 'engineers'.
Amir
thank you Per i downloaded the code bundle. i think that it is better to work with PWM + QEI to implement PID, instead of MCPWM. it is not easy to work with QEI (catch position and time)in MCPWM.
as i asked before:
but i don't know what's the effect of PID calculation's time waste during interrupt, on pid accuracy?(i want to refresh pid calculation every 50us and clock frequency of 1768 is 100 MHz) is it feasible to earn 50us refresh time? how much clock pulses were spent in a simple (without extra codes) interrupt? how can i find that how much clock pulses are spent in a simple interrupt.
thanks
Using C/C++, you aren't intended to know exactly how many clock cycles an ISR is consuming.
You can spend some time figuring out how large percent of the total CPU capacity that gets spent by a constantly ticking interrupt by checking how much it slows down a busy-looping main loop.
But in the end, you normally set up a control loop where it doesn't matter what exact response time the ISR has, i.e the control loop is normally fine with getting one update every interrupt and the program is fine that each interrupt leave enough time for all other interrupts and for the main loop with a bit to spare for safety margin.
If the jitter delay and execution time in the ISR will destroy your regulation performance, then you are running a too slow processor or expecting too much of the regulation.
Exactly what RPM are you planning to run the motor, and exactly what position precision are you demanding?
OK got it!
i decide to run the motor at 79310 encoder pulses per second and 34 encoder pulses precision. in other words, it must run at 34 pulses per 428 microseconds.
i think there are two approaches :
I. set PWM1->MR0 (lim register) to (428/2=214)microseconds and setup an interrupt at the end of cycle includes PID routine that adjusts 17 pulses per this pwm cycle.
(this method has about 1/17 pulse error)
II. set PWM1->MR0 (lim register) to 14 microseconds but setup interrupt for QEI ENCLK_Int(encoder pulses) that takes about 12.5 microseconds and change PWM1->MR1 (match register) using PID during this interrupt for the next pwm cycle.
is it applicable to implement 2nd approach? thanks
Hi another question I have doubts about LER in PWM. assume that:
LPC_PWM1->MR0=1000000; LPC_PWM1->MR1=500000
and TC value is about 20 and it haven't been mached with 500000 ! now if an interrupt occurs that contains:
LPC_PWM1->MR1=200 LPC_PWM1->LER =0x01;
does the match occurs for MR1=200 or the program runs the match for MR1=500000 and uses the new value (MR1=200) for the next cycle?