Could be possible to use the ADC in free running mode?

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post by dkinzer »

mikep wrote:If you want to process values while waiting for other conversions to complete, then you should look into writing a native mode ISR for the ADC complete interrupt.
You can probably achieve the same objective without writing an interrupt handler. For example, you could have a task that initiates a conversion and then does a WaitForInterval() with the interval time set to just exceed the calculated conversion time.
- Don Kinzer
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

dkinzer wrote:
mikep wrote:If you want to process values while waiting for other conversions to complete, then you should look into writing a native mode ISR for the ADC complete interrupt.
You can probably achieve the same objective without writing an interrupt handler. For example, you could have a task that initiates a conversion and then does a WaitForInterval() with the interval time set to just exceed the calculated conversion time.
Using this method the smallest wait between successive calls to GetADC is a clock tick (1.95ms). This means to get all 6 readings could take ~ 11.7 ms. For most applications this would work but Ben has said that the current implementation too slow. The WaitForInterval() technique does allow other processing but has a maximum update frequency of ~85 Hz. Ultimately we need a little more information from him about the requirements.
Mike Perks
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

Don / Mike. Thanks for all your thoughts on this.

Basic requirement is to collect 6 adc channels and then perform various filtering and PID feedback loops. I need my overall loop speed to be > 500hz in order to maintain stable operation (flight).

Obviously the sensor fusion and PID functions take up a reasonable amount of time, so Im looking to save time where I can. One area where I thought I might be able to save some time after reading this thread is in the ADC calls.

I have got around the problem initially by just being a bit more froogle on my calls, so now ive got gyro readings (2 adc) coming in every loop (550hz), accelerometers (4adc) data every second loop (275hz) and other sensors (presure, mag) coming in at 30hz. This frees up quite a lot of time.

However as the math code keeps getting added to my main loop, the likelyhood of dropping under 500hz is getting higher. So any time I can save is a bonus!

Ben
liam.zbasic
Posts: 163
Joined: 24 March 2008, 23:33 PM
Location: Southern California (Blue)

Post by liam.zbasic »

You need more than 500Hz to maintain stable flight? For manned aircraft, rigid body dynamics are in the order 1Hz (and less), so we typically do not sample beyond 25Hz (rough order of magnitude). I can see that the rigid body dynamics of an R/C type aircraft will be higher, and this is why you need 500Hz+ sampling. Or maybe you're trying to suppress structural modes, or maybe you're dealing with a wind tunnel model? Interesting subject. Thanks for your original thread.
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

The platform is quadcopter UAV, hence need for 500hz +.
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Post by Don_Kirby »

If the craft really needs that much processing speed, it may be wiser to split the duties between multiple processors. I've found that when I start pushing the limits of the platform right from the beginning, there's usually problems down the road.

In this particular case, you could offload the math to another chip, using the one you have now to just collect the data.

Of course, you may have already pursued this line of logic and found it nor appropriate for the task.


-Don
twesthoff
Posts: 247
Joined: 17 March 2006, 6:45 AM
Location: Fredericksburg, VA

Could be possible to use the ADC in free running mode?

Post by twesthoff »

I haven't been following this thread closely, but unless the conversion time of the ADC is the limiting factor, wouldn't a native mode device give him the speed he needs?
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

sturgessb wrote:The platform is quadcopter UAV, hence need for 500hz +.
Ben, this statement helps but doesn't help if you know what I mean. I guess a quadcopter means 4 motors and 4 PWMs. Quite an advanced project.

Why are you sampling at 500 Hz? The refresh frequency for the PWMs cannot be more than 50 or 100 times a second. There is a method to get better ADC accuracy by oversampling as described in this Atmel application note. Is this what you are trying to do?

In general Don's comment about potentially pushing the limits of the platform may or may not be true. I would tend to stick to the single chip until you find a major problem and resolve it. If you have structured your code correctly, moving it to another device and setting up a slave won't be too bad. I assume you are not employing quadrature encoders on the motors and are simply calibrating them and using PID to control them.

Are you looking at or using 16:16 fixed point number to speed calculations?
Mike Perks
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

To Don:
I have thought about splitting the tasks across two chips, but worry is about speed of communication between the two. How would this be achieved?

To Mike:
Sorry, was just about to rush out the door, hence my haste. Yes quadcopter is 4 brushless motors controlled by 4 PWM escs. Im slightly confused by your comment...

"The refresh frequency for the PWMs cannot be more than 50 or 100 times a second"

Do this, do you mean the standard update rate for motor ESCs is 50-100hz? If so, I've got around this buy using custom controllers capable of update speed of 400hz.

However If you mean the harware PWM outputs on the ZX cannot be updated more than 50-100 times a second, im a bit confused. As I have mine running at 400hz update (i.e a new HPWM command every 1/400sec) and it appears to be working...?!

I have it balancing on the bench really nicely using PID type control. snapping to setpoint position very quickly. Ill post some videos up.

To be honest now, with tweaking my code a bit to only get the samples exactly when i need them, im achieving the speed i need. And as it turns out 350hz update seems more than enough for stability, so I have a bit more headroom now.

Thanks for all the input, ill keep you posted on the project.
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

sturgessb wrote:I have thought about splitting the tasks across two chips, but worry is about speed of communication between the two. How would this be achieved?
One device is either a SPI or I2C slave. You would need to work out your own application-level protocol.
sturgessb wrote:Im slightly confused by your comment...

"The refresh frequency for the PWMs cannot be more than 50 or 100 times a second"
What I meant was I cannot imagine needing a calculation cycle time of more than 50 or 100 Hz. Is the machine really that unstable that it needs refreshing at 350 Hz? Isn't the whole point of PID to integrate over time and smooth out responses? Perhaps more tuning of the PID constants is needed? I'm sure you have more experience than me in this area and the theory of PID doesn't always match the practice.
sturgessb wrote:I have it balancing on the bench really nicely using PID type control. snapping to setpoint position very quickly. Ill post some videos up.
I would love to see them.
Mike Perks
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

sturgessb wrote:I have it balancing on the bench really nicely using PID type control. snapping to setpoint position very quickly.
I just read up on cascaded control. Is this something you have considered? It may reduce the cycle time at the added expense of extra calculations.
Mike Perks
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

I may consider it, If I could understand it :)
mikep
Posts: 796
Joined: 24 September 2005, 15:54 PM

Post by mikep »

I assume you have seen STARMAC?
Mike Perks
sturgessb
Posts: 287
Joined: 25 April 2008, 6:34 AM
Location: Norwich, UK

Post by sturgessb »

Yeah, not too impressed by how they fly, they sure are intelligent units but don't seem to fly that great.

These guys are achieving great results, using 644p
www.mikrokopter.de

Waiting for some new gyros, but i should be in the air soon. ill post up my flight, and inevitable crash!
spamiam
Posts: 739
Joined: 13 November 2005, 6:39 AM

Post by spamiam »

This is very interesting. I have always been interested in autonomous navigation, starting back in the days a couple of decades ago when I built a little thing that would approach a light, aim a little rubberband powered lance and fire a pencil at the light. As long as the wattage of the bulb was always the same, it could deduce the range from intensity and come close with the projectile. No binocular "vision".

My question is why you use 4 motors. Why not a standard RC electic helicopter with a couple gyros. The gyros will do their own feedback for stability, then the CPU just feeds control for height, orientation and speed.

It seems as controlling 4 motors would be more complex, and require a lot of custom hardware to do so. Isn't it easier to start with a bunch of commercially available solutions and add to them?

BTW, I have been evolving some ideas for a autonomous GPS/ultrasonic ranger blimp. I think that LiPo batteries may be light enough and have enough power to do a reasonable job of powering the motors and GPS for a reasonable period of time.

-Tony
Post Reply