CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Electronics > General Electronics Discussion


General Electronics Discussion Discuss basic electronics, power supplies and anything else electronic related here.


This forum is sponsored by:

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 01-31-2008, 01:57 PM
 
Join Date: Dec 2007
Location: USA
Posts: 1
Elijah Turner is on a distinguished road
UP/DOWN COUNTER

UP/DOWN COUNTER I am a student designing a digital feedback control system as a project and am having difficulty with the logic that compares the number of move pulses from a microcontroller (MC68HC11) with the number of feedback pulses from the encoder. These pulses need to be subtracted to determine if the DC motor is ahead or behind the desired position so that the duty cycle of the PWM can be changed as needed. The problem is that both pulse streams are asychronous and pulses from both streams could arrive at an up/down counter at the same time. QUESTION: What logic circuit could capture both streams and subtract them without occasionally loosing a pulse? Your thoughts will be greatly appreciated. Elijah the Student.
Reply With Quote

  #2   Ban this user!
Old 01-31-2008, 09:15 PM
 
Join Date: Jan 2007
Location: USA
Posts: 355
Eurisko is on a distinguished road

Elijah,

My first instinct was to capture the pulses with a flip flop, then work on from there.

Maybe a little more info is needed.

What is the maximum pulse rate?
Will discrete logic chips be used, or will the microcontroller handle most of the work?

If you could expand on a few details of your design, it might just get the ball rolling.
Reply With Quote

  #3   Ban this user!
Old 01-31-2008, 09:39 PM
 
Join Date: Jan 2008
Location: usa
Age: 79
Posts: 16
Lew Hartswick is on a distinguished road

Rather than keeping track of pulses on two non sync pulsetrains why not use
a charge balancing scheme. One pulsetrain adds to the charge while the other
subtracts. This way the error is zero when balanced and the polarity and
magnitude represents the sign and magnitude of error.
"Think analog" :-)
...lew...
Reply With Quote

  #4   Ban this user!
Old 01-31-2008, 09:55 PM
 
Join Date: Aug 2006
Location: USA
Posts: 2,624
kreutz is on a distinguished road

It is not so simple, and all depends on the pulse repetition rate (prr) from the encoder and input pulse rate from your micro-controller.

On a micro-controller based solution you will need to decode the encoder's quadrature output and generate an interrupt on every transition (x4 decoder) to read A and B channels, then use an up/down pulse accumulator just to count the pulses, that can be done at low to medium prr (and if the overhead on your micro-controller is not too much).

There are chips which already include the decoder, up/down 16 or 32 bits counter and latch with parallel or SPI interface for higher ppr. Or you can design one on a CPLD.

You don't have to subtract both counts on the same interrupt routine you use to count the pulses in a software solution. Normally the PID routine has an associated low interrupt rate (between 1Khz and 10 Khz) and you can make the subtraction part of that routine (only if your counters don't overflow in the interval between interrupts).

For faster counting (and reducing latency to other interrupts) your encoder interrupt routine just reads the port and places the resulting two bits in a queue, re-enabling interrupts afterward. A tick clock interrupt routine (runs with interrupts re-enabled) will process the values and update the absolute position (comparing the phase between last received two bits and new received bits) and flagging an error if they are out of sequence.

Your control loop routine will read the values of the variables you use for encoder position and input pulse accumulator (treated the same way as the encoder pulses), subtract them (to calculate the error), and do the necessary calculations to generate the duty cycle of the PWM.

Last edited by kreutz; 02-01-2008 at 10:19 AM.
Reply With Quote

  #5   Ban this user!
Old 02-01-2008, 07:53 AM
vger's Avatar  
Join Date: Jan 2006
Location: usa
Posts: 664
vger is on a distinguished road
Up / Down ?

Elijah,
I remember seeing a single IC somewhere that has inputs for and incrimental encoder, and step / direction. I think it had an up / down counter and a DAC onboard to output an analog voltage that could be used to drive a servo amp. The purpose was to drive a servo motor using step / direction signals from a controller. If I remember rightly, the thing would only error out if the it counted more than 128/127 pulses off center which would lend to an 8 bit UP / Down counter. I'm not sure how they did the logic on the chip. I'll see if I can locate that chip again.

Steve
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 02-01-2008, 08:26 AM
 
Join Date: Aug 2006
Location: USA
Posts: 2,624
kreutz is on a distinguished road

Originally Posted by vger View Post
Elijah,
I remember seeing a single IC somewhere that has inputs for and incrimental encoder, and step / direction. I think it had an up / down counter and a DAC onboard to output an analog voltage that could be used to drive a servo amp. The purpose was to drive a servo motor using step / direction signals from a controller. If I remember rightly, the thing would only error out if the it counted more than 128/127 pulses off center which would lend to an 8 bit UP / Down counter. I'm not sure how they did the logic on the chip. I'll see if I can locate that chip again.

Steve
That is a rare finding, I would like to know more about that chip. But for Elijah's project will make a poor learning experience.

A real life design project is not simply a cut and paste exercise. That will make you become what most of the chip vendors want to have as customers, and will create a technology dependent product. You will only learn to read data-sheets and interface them using the application notes. A real learning experience it to solve the problem without using specialized chips (or reducing them to a minimum).

The information on that chip would be a good starting point for the project, if Elijah emulates it on his micro-controller (some additional logic could be required).

Elijah;

About making asynchronous inputs synchronous, is is very easy and explained on most of the CPLD and FPGA getting-started schematic capture literature, you can also create some simple digital filtering to the encoder and step/Dir pulses without too much overhead.

Kreutz.
Reply With Quote

  #7  
Old 02-01-2008, 09:48 AM
Gold Member
 
Join Date: Mar 2003
Location: United States
Posts: 2,717
Mariss Freimanis is on a distinguished road

I can think of two two ways of solving the problem:

1) Have 2 UD counters, counter A gets one source, while counter B gets the other source. Counter A and B outputs go to an adder, the sum being the difference between the two counters.

Example:
CNT_A = 0x00, CNT_B = 0x80. A + B = 0x80
CNT_A = 0xFF, CNT_B = 0x81. A + B = 0x80 (A-1, B+1)
CNT_A = 0x7F, CNT_B = 0x01. A + B = 0x80 (A-128, B+128) etc.

The above requires 2 counters and an adder. It is elegant, simple and is a good solution for a microprocessor. Increment reg B for CW direction, decrement reg A for CW direction, sum reg A and B for the position difference.

2) Counters and adders are "expensive" (use a lot of resources) in a CPLD. The solution is a single UD counter that has anti-collision gating on its UD and CE inputs as shown in the attached gif. Since this is homework, I leave it to you to puzzle-out how the gating works. Hint: Draw timing charts for the circuit. It is a fully synchronous design, it works with any STP pulse-width and DIR must be true only at the falling edge of the STP inputs. The STP pulse input rate must not exceed 1/4 the synchronous CLK frequency (5MHz in our design). We use this circuit in our CPLD servodrive so you know it works.

Mariss
Attached Thumbnails
Click image for larger version

Name:	ANTI-COLLISION.jpg‎
Views:	151
Size:	40.8 KB
ID:	52166  

Last edited by Mariss Freimanis; 02-01-2008 at 10:04 AM.
Reply With Quote

  #8   Ban this user!
Old 02-01-2008, 09:54 AM
vger's Avatar  
Join Date: Jan 2006
Location: usa
Posts: 664
vger is on a distinguished road

Kreutz,

Can't find that thing. Should have saved it in favs. Will keep looking though.
Yeah, buying it would be cheating the learning process. Thought the chip datasheet might have some details on how they did it.

Elijah,
If you want to do this all in disctete IC's, I think your board acreage may be fair sized. I would say first you should decode the encoder pulses to step/dir so they match what is coming from the microcontroller (assuming that is what they are) and use 4 edge triggered F/F's storing the up/down info. Scan the four F/F outputs (dual data selector/multiplexer) at a rate that is many times the maximum PRR from the encoder or microcontroller. Reset the F/F's at the end of each scan. Output of the 2 data selectors go to the up down counter chain count inputs. Use presettable U/D counters so you can preset them mid count on power up. From that point there are options, digital pulse width using magnitude comparitors and a free running counter, or DAC and an analog PWM circuit.

Sounds like a good project.
Steve
Reply With Quote

  #9  
Old 02-01-2008, 10:10 AM
Gold Member
 
Join Date: Mar 2003
Location: United States
Posts: 2,717
Mariss Freimanis is on a distinguished road

Same as above but with an X4 quadrature decoder.

Mariss
Attached Thumbnails
Click image for larger version

Name:	encoder.jpg‎
Views:	129
Size:	37.4 KB
ID:	52167  
Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Part Counter ParadiseIsle FlashCut CNC 1 06-13-2007 08:04 PM
Counter Mitutoyo wanchai101 Calibration & Measurement 0 03-17-2007 08:06 AM
Parts counter daewooevc Daewoo/Doosan 1 11-01-2006 08:38 AM
Parts counter daewooevc Mazak, Mitsubishi, Mazatrol 1 10-26-2006 04:36 PM
counter cncsdr Haas Mills 2 11-08-2005 07:56 AM




All times are GMT -5. The time now is 10:59 PM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361