Why is this code so slow?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Why is this code so slow?

3,304件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave3891 on Sun Jul 31 21:21:01 MST 2011
I have been trying different ideas to get 3 (6 in the future) variable frequency's generated with the 1343.

My best case is with match registers and interrupts.
But with just 3 (all on timer32 0) I can't get anything better then 125khz max.
I am looking to get around 350khz on 6 pins max, but nothing seems to get me close.

Each one has to be able to have a variable frequency/period and an adjustable on time. And right now I am testing worst case will all on at a high frequency.
Any idea's on the right way to do this or am I asking to much of this chip?

I have tried the highest optimization level as well.

Thanks
Dave
0 件の賞賛
返信
18 返答(返信)

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Aug 03 02:32:25 MST 2011

Quote:
...I will find out in a few days when I get the boards...



Please keep me informed. Can't be wrong to think out of the box :)
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Rob65 on Wed Aug 03 01:05:26 MST 2011
Could we get back to the lpc1xxx again?
This forum still is about LPCXpresso and not about STM or other Cortex chips ...

You need 6 PWM channels with a frequency (up to) 350 kHz if I remember correctly.
The question is if you really need diffent PWM frequencies.

The lpc17xx (I use the lpc1754) has one general PWM unit with 6 outputs that all share the same frequency (one timer with 6 match outputs) and a motor control PWM that contains 3 completely seperate PWM channels all with their own timer and match register.

So you can get up to 4 different frequencies.
And the general PWM unit can also be set such that 2 match registers are used to get 3 "double edge controller" PWM outputs. They still all share the same frequency but you are free to choose at which time each signal becomes high or low again.

Regards,

Rob
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Wed Aug 03 00:32:39 MST 2011
Nuvoton M0 chips have up to 8 PWM channels wih independent cycle settings plus 4 toggle-capable timers. All of this at less than $1.5.
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave3891 on Tue Aug 02 15:47:18 MST 2011

Quote: qili
how many of those timers can be configured to have their own output pins?


Looking at the 32 discovery board it looks like most of the timers have a pin.
There are about 18 pins with a timer association, but this was just a quick look.
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by qili on Tue Aug 02 04:46:13 MST 2011

Quote: Dave3891

I might order a STM32 discovery... it has 12 timers.



how many of those timers can be configured to have their own output pins?
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by acno on Tue Aug 02 01:50:43 MST 2011

Quote: Dave3891
I wanted to use toggle mode with the match registers, but I could not think of a good compact code way to keep track of if the toggle is high or low.
And I need to be able to set the pulse to active high or active low depending on the application.



The constraint is if you want indipendent control of active high or low on each channel. If all the channels are of the same polarities, I think that with a 'set on match' or 'clear on match' you should be able to do what you want and with a LPC17xx where you have a PWM timer with 6 channel and motor control PWM timer it should be finally possible.

I still not used the motor control PWM timer, but it is quite sophisticated and specifically designed to generate up to 6 complex PWM signals, that is basically your problem.


Andrea
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave3891 on Mon Aug 01 17:02:50 MST 2011

Quote: KTownsend
Don't worry ... I've heard he just gets his trainee to answer most of the questions now :D



What does he do that he gets a trainee? Is he a embedded programmer for a profession?
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ktownsend on Mon Aug 01 14:51:59 MST 2011

Quote: Dave3891
Thanks for the help Zero, they should be paying you for all the questions you answer.



Don't worry ... I've heard he just gets his trainee to answer most of the questions now :D
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave3891 on Mon Aug 01 11:46:40 MST 2011
I ordered 2 of them with shipping for $27.70 so they are a good deal.

Looking in the reference manual it does look like I can use the general purpose timers to generate 6 individual PWM channels.

I will find out in a few days when I get the boards.

Dave
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Aug 01 11:21:09 MST 2011

Quote: Dave3891
I might order a STM32 discovery... it has 12 timers.Dave




Quote:

Up to 12 timers
[LIST]
[*]Up to three 16-bit timers, each with up to 4 IC/OC/PWM or pulse counter
[/LIST]
                
[LIST]
[*]16-bit, 6-channel advanced-control timer: up to 6 channels for PWM output, dead time generation and emergency stop
[/LIST]
                
[LIST]
[*]One 16-bit timer, with 2 IC/OC, 1 OCN/PWM, dead-time generation and emergency stop
[/LIST]
                
[LIST]
[*]Two 16-bit timers, each with IC/OC/OCN/PWM, dead-time generation and emergency stop
[/LIST]
                
[LIST]
[*]2 watchdog timers (Independent and Window)
[/LIST]
                
[LIST]
[*]SysTick timer: 24-bit downcounter
[/LIST]
                
[LIST]
[*]Two 16-bit basic timers to drive the DAC
[/LIST]

Sorry, I'm not (yet) familiar with ST so I don't know if  it's possible to generate 6 independent timer :mad:

But it's worth a trial :)
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave3891 on Mon Aug 01 10:12:55 MST 2011
I will need the 6 outputs, and it looks like PWM is the only fast way to go.

I might order a STM32 discovery... it has 12 timers.

Thanks for the help Zero, they should be paying you for all the questions you answer.


Dave
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Aug 01 09:58:45 MST 2011

Quote: Dave3891
So even with PWM the 1343 and 1769 only have 4 timers...



1769 has an additional PWM and RIT and therefore the possibility to add a calculated  output :)

So it's a fundamental question if you need (or want to use) a 1769 :confused:
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave3891 on Mon Aug 01 09:44:13 MST 2011
So even with PWM the 1343 and 1769 only have 4 timers... so I am not going to get 6 indipendent output then ...
Back to the drawing board. Mabey a CPLD generator attached to the 1343.

Thanks
Dave
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Aug 01 09:02:32 MST 2011

Quote:

...I am looking to get around 350khz on 6 pins max, but nothing seems to get me close...

Just measured your Interrupt: 2.3 µs for 3 pins, and that's your problem :mad:

With 6 pins you're ending below 100kHz :eek:

I think your only chance is to use PWM. Unfortunately you need one timer per PWM, so 4 independent timer should be no problem.

Your basic idea to calculate new MR values costs a lot of time (and then you don't use Match outputs :eek:).

Overall I would say it's hopeless to expand your code even to 4 fast pins :mad:
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave3891 on Mon Aug 01 08:45:28 MST 2011
I wanted to use toggle mode with the match registers, but I could not think of a good compact code way to keep track of if the toggle is high or low.
And I need to be able to set the pulse to active high or active low depending on the application.
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Dave3891 on Mon Aug 01 08:28:52 MST 2011

Quote:
Did you try to reduce your Prescale Register ?



I have reduced the match register, but anything lower and it misses interrupts.


Quote:
At 50MHz of bus this means only 200 cycles. What is the CPU clock ?



I am running at 72mhz. I am using the Embedded Artists LPC1343.


Thanks
Dave
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by acno on Mon Aug 01 06:01:26 MST 2011

Quote: Dave3891
I have been trying different ideas to get 3 (6 in the future) variable frequency's generated with the 1343.

My best case is with match registers and interrupts.
But with just 3 (all on timer32 0) I can't get anything better then 125khz max.
I am looking to get around 350khz on 6 pins max, but nothing seems to get me close.

Each one has to be able to have a variable frequency/period and an adjustable on time. And right now I am testing worst case will all on at a high frequency.
Any idea's on the right way to do this or am I asking to much of this chip?

I have tried the highest optimization level as well.

Thanks
Dave



Well, with that code You have 2 IRQ per cycle, so at 125kHz the cpu has only 4us (8/2) for executing the ISR. At 50MHz of bus this means only 200 cycles. What is the CPU clock ?
You can also check how much time the cpu spend in the ISR, trace it with a GPIO port for example.
Also, I will try to use directly the timer match outputs, with them the ISR routine should need much less code.

Andrea
0 件の賞賛
返信

3,278件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Aug 01 00:18:33 MST 2011
Did you try to reduce your Prescale Register ?
0 件の賞賛
返信