|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
Re: Servo 'smoothing'
Quote:
Does the incount++ action actually happen? I mean, when you check if the "if" statment is true, does the Microprocessor increase the valuce of incount? If it doesn't work, this should be done in a for loop, but if this "if" statment counts as a loop, then OK (it's just a method of a loop i've never seen before ). |
|
#2
|
|||||
|
|||||
|
Re: Servo 'smoothing'
Quote:
As with most things in the IFI RC, a for loop wouldn't work here. Remember that for the vast majority of things you do in the IFI RC, you do something once in one pass of the "slow loop", then wait 26.2ms for the next "slow loop" pass, and then do the next step in the sequence. What we're trying to do is measure the input signal at several different points in time, then average those measurements. If we were to use a for loop, the measurement we'd be taking would be very very close together in time on an analog input, or exactly the same if we're looking at a value from the operator interface. Averaging 8 samples of the same number obviously isn't very helpful! So, since we want some time to pass, we just record one sample of the value during a single pass of the "slow loop" then wait until the next pass to take another one. In Alan's code, once we've built up 8 of these samples, we average them all together. Then the next time through the slow loop, we start all over again. So to answer your question, this isn't a traditional for loop like you usually think of them. We have a timed, (nominally) infinitely repeating loop to work inside of, and this if statement lets us do something like a for loop inside this timed loop. Also, I think Alan meant: if( ++incount == 8) // is this the eighth sample? as he's using a zero-based count, so you'd want to stop when count + 1 == 8. Also to Erik and viewers at home, The domain of tau is obviously changeable with the #define SCL. To move to a 0..255 range, you'd state #define SCL 8. It's important to note that at that point, you can't have an equivalent of tau=1.0, which basically removes the effect of the filter. Also, fixed point math may be painful at times, but it is and always* will be stupendously faster than floating point. If our audience members are at all interested in programming embedded controllers and/or high speed DSPs in the future, it can't hurt to look into fixed point math and play around with it. *For the foreseeable future, until FPUs are fast enough that you couldn't possibly want to do things any faster than they can be done with floating point. |
|
#3
|
|||
|
|||
|
Re: Servo 'smoothing'
Put your signal line on an o-scope and you can look at the jitter there. I would try then putting a low-pass filter on it to reduce some of the noise. my 2 cents.
|
|
#4
|
|||||
|
|||||
|
Re: Servo 'smoothing'
Quote:
![]() |
|
#5
|
|||||
|
|||||
|
Re: Servo 'smoothing'
Kevin,
What I meant was does the processor really increment incount by putting that line inside an if statment. But I presume it does, since eveyone is saying the code is correct. |
|
#6
|
|||
|
|||
|
Re: Servo 'smoothing'
Quote:
http://www.difranco.net/cop2220/op-prec.htm (see Note 2) shows the precedence of operators. In the IF statement, the compare will be evaluated, then incount will be incremented. |
|
#7
|
|||
|
|||
|
Re: Servo 'smoothing'
Quote:
DON'T OVER OPTIMIZE A fixed point multiply takes two or three clock cycles to execute. A single precision floating point multiply takes three clock cycles to execute. A double precision floating point multiply takes four clock cycles to execute. In addition to the "execute" phase, each instruction must also go through fetch, decode/dispatch, and complete, which adds three more clock cycles. Simply put, the difference between single fixed or floating instructions just don't matter any more. What will matter is how many instructions. By converting to fixed point math (and adding the shift instructions), you actually slowed down the filter. To make things even more interesting, the processor is capable of dispatching up to 2 instructions per clock, but only if they are different types of instructions: You can dispatch a fixed point and a floating point instruction simultaneously, but you can't do the same with two fixed point instructions. This means that you are *much* better off allowing a compiler to order your instructions. Write what you mean, and trust in the compiler. - Eric (with a C) PS: Eliminating divides are almost worth your time. Fixed point divides take 20 cycles to execute. Floating point divides take 18 (single precision) or 33 (double precision) cycles to execute. For reference sake, a double precision divide on the cRIO takes about the same amount of time as an 8 bit fixed point instruction on the PIC. However, it will also be executing fixed point math while the FPU is working on the divide. |
|
#8
|
|||||
|
|||||
|
Re: Servo 'smoothing'
Quote:
To be brief, I wasn't maintaining that fixed point math is faster or would make more sense for most operations on the cRIO. NI's processor selection obviously makes that untrue. Two points remain, however: 1. At some point, we'll hopefully be given access to the FPGA behind the RIO in cRIO. Floating point math is more or less untenable on this FPGA. If a team wants to do fast filtering, averaging, oversampling, etc. with no extra processor load, fixed-point on the FPGA is the way to go. Many interesting applications on the FPGA are going to require some sort of fixed point math, really. 2. Fixed point math is loads faster on processors designed with it in mind and such processors consume less power to do the same amount of work as a floating point processor. I was attempting to point this out so everyone reading the thread didn't simply consign fixed-point to the dustbin of history. There's a reason the big DSP makers are still designing and making new fixed-point DSPs, after all. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Data Smoothing | Lafleur | Programming | 3 | 14-01-2008 22:06 |
| Servo behavior question / advanced servo/PIC programming question | DanL | Electrical | 12 | 18-10-2005 18:33 |
| Servo Values | DanDon | Motors | 8 | 14-02-2005 15:49 |
| Buying Servo | Gamer930 | Motors | 4 | 13-02-2005 20:44 |
| Servo | MASherry | General Forum | 6 | 04-10-2004 22:46 |