Crazy idea? Making a PWM controller without a microcontroller? Possible? - Page 1
Forum section: electronics / projects

author: MarkS
author_rank: Unknown
timestamp: July 08, 2023, 07:09:03 pm
content: In my never ending quest to make retro computer stuff, I'm designing a simple robotics platform with a MC68000 processor (yes, I'm obsessed with this part!). I need two PWM signals to the motor controllers and common sense tells me to integrate a small microcontroller for this purpose. However, when I say "retro", I really want to mean retro, i.e., any component available pre-1990's. This led me down a rabbit hole of how to design a PWM controller without a microcontroller. Unfortunately for me, I'm at a loss here, so I'll be going the microcontroller route.STILL....How could this be done? CAN it be done? I want to take an 8-bit binary signal in parallel and output an appropriate PWM pulse. I'm thinking 8-bit binary to 256-bit sequential string. So, (input)00000001 would be ...(256 total positions)...000001, 00000100 = ...001111, 00001000 = ...11111111, etc. The sequential bit string would then be shifted at a currently undefined clock frequency, creating the PWM signal. Sounds SOOO easy!My initial thought was to store the sequences in an EEPROM and use the 8-bit binary string as the address along with additional logic to fill 32 parallel-in, serial-out shift registers connected in sequence. And while I think I can make this work, that's over 32 chips... PER channel! I looked at the 74HC40103, and it initially looked promising, but it counts down to zero at a high state (good!), outputs a single low clock pulse and then goes back high to begin the count again (bad).Is this a total waste of time, even for the edutainment value, or is there a way to do this?

author: Tomorokoshi
author_rank: Super Contributor
timestamp: July 08, 2023, 07:32:17 pm
content: A non-optimal, brute-force block-diagram way would be something like:1. Have an 8-bit counter that cycles from 0 to 255 then back to 0 to generate a ramp. It drives a DAC with an appropriate op-amp.2. Have a PWM level set by an 8-bit output register that drives a similar DAC and op-amp circuit.3. Then a comparator drives the output signal.The ramp wave is compared to the setpoint. When the threshold is reached the comparator changes state. The polarity is set by either the selection of inputs to the comparator, or the counting direction of the ramp. You could use a multiplexed DAC for multiple channels using the same ramp.Or are you looking for a digital-only solution?

author: themadhippy
author_rank: Super Contributor
timestamp: July 08, 2023, 07:37:15 pm
content: 8 relays hanging off your parallel bus switching in and out resistors to set the timing on a 555

author: hatte
author_rank: Contributor
timestamp: July 08, 2023, 07:37:35 pm
content: Could you hack an I2C implementation and use something like PCA9685 (16 channel, 12 bit PWM controller) to maintain the PWM signals without requiring any intervention by the CPU.Adafruit has a board with the PCA9685https://www.adafruit.com/product/815

author: iMo
author_rank: Super Contributor
timestamp: July 08, 2023, 07:41:01 pm
content: You may do PWM control of "something" with 2 transistors - a multivibrator - where you are changing the duty cycle with a potentiometer.. Pretty retro, imho

author: ejeffrey
author_rank: Super Contributor
timestamp: July 08, 2023, 07:48:16 pm
content: Take a free running 8 bit counter and an 8 bit full adder. Add the counter output to your control word. The carry output of the adder is your PWM signal. That's 3-4 chips.

author: Bud
author_rank: Super Contributor
timestamp: July 08, 2023, 07:51:24 pm
content: R2R ladder DAC -> NE555 timer

author: Benta
author_rank: Super Contributor
timestamp: July 08, 2023, 08:04:36 pm
content: Hahahaha!Pre-1990, practically no one would use an MCU for this (far too expensive), nor do it digitally.It was a linear ramp/triangular generator followowed by a comparator. PWM level controlled by a DC input voltage.https://www.analog.com/en/design-notes/pulsewidth-modulator-operates-at-various-levels-of-frequency-and-power.html

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 08, 2023, 08:30:31 pm
content: Quote from: MarkS on July 08, 2023, 07:09:03 pmIn reverse order :Yes, it is very close toa total waste of time, even for the edutainment value.The 40103 is actually doingmostof what you need, it provides a 8 bit to clock-time delay, you just need another /256 reference and a flip flopQuote from: MarkS on July 08, 2023, 07:09:03 pmYup, the problem you have in 2023, is that the microcontroller is cheaper than the TTL LOGIC you might choose, even before you add in Board area and assembly time adders.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 08, 2023, 08:46:34 pm
content: Here are some links that may be helpful:https://www.4qdtec.com/pwm-01.htmlhttps://www.4qdtec.com/Single chip voltage controlled (obsolete?):https://www.ti.com/lit/an/slit110/slit110.pdf?ts=1688810617464&ref_url=https%253A%252F%252Fwww.google.com%252F

author: AndyBeez
author_rank: Frequent Contributor
timestamp: July 08, 2023, 09:07:58 pm
content: Left field - but retro - I thought old skool micros have sound chips? Could you 'hack' one of those in it's pulse oscillator mode, to yield a variable mark space ratio for your PWM-like output? You'll only get up to 5KHz at best though.Otherwise... a DAC creating a voltage, and then a voltage to PWM converter.

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 08, 2023, 09:14:26 pm
content: Quote from: ejeffrey on July 08, 2023, 07:48:16 pmReplace the counter with a latch, so that each cycleiyou calculateAi+1=Ai+ C, and you have a PDM, i.e. pulse density modulator.IfAis 8-bit, and you limitCto between 16 and 239, inclusive, you will always have at least one edge every 16 clock cycles, which makes it much easier to low-pass filter such a signal analogically. PWM-controlled devices like servos don't like a PDM signal, though.Here is what I would do:Two binary counters, with a carry/overflow output, and a register/latch each to store the count to reset to.One counter counts the output high period, and the other the output low period.With 8-bit binary counters, you can control the PWM frequency (as one period can be from 2 to 510 cycles).Whenever one counter carries/overflows, the output is toggled, this counter reset to its period, and the other counter enabled.Only one counter runs at any time.So, two counters, two registers/latches to store the two periods, an SR flip-flop to select which clock handles the next clock pulse, and another SR flip-flop to toggle the output.If you add a third counter and register/latch, you can make it the clock divisorD, so that the PWM period is (H+L)×Dclock cycles, and duty isH/(H+L). With 8-bit counters and a 2 MHz clock, you can then select the PWM frequency between 15.38 Hz and 1 MHz. Between 15.38 Hz and 3921 Hz the resolution is maximum possible.SN74HC590 seems eminently suitable as an 8-bit counter, because it has a separate clock enable (CCKEN), and a register carry output (RCO), and is still easily available. The latches need separate output enables, so SN74HC573 seems suitable. For the latches, a CD4043 has four S/R latches, and seems well suited.Since OP wants a robotic platform, they probably need many PWM channels, but all channels can probably use the same PWM frequency.It seems to me that a free-running 8-bit counter, with its overflow resetting all output channels would work.Each channel has a binary comparator and a S/R latch.Add an extra binary counter to divide the clock source for frequency adjust. From a 2 MHz clock, an 8-bit divider yields 8-bit PWM frequencies between 30.6 Hz and 7812.5 Hz.I think SN74HC590 is old enough for the counter(s), CD4043 for the SR flip-flops (4 outputs per chip), SN74F521 for the comparators, and SN74HC573 for the binary registers/latches. So, it's a minimum of 2.25 chips ('521 + '573 plus one fourth of a CD4043) per channel, plus one or two '590 counters.I am not sure how to interface the binary registers/latches to the 68k bus, though, to set the duty cycle for each PWM channel.Which leads me to: why not implement the 68000 architecture as a soft-core on an FPGA?

author: MarkS
author_rank: Unknown
timestamp: July 08, 2023, 09:28:53 pm
content: Quote from: Nominal Animal on July 08, 2023, 09:14:26 pmFair question! I have two working 68K chips at my disposal. Why reinvent the wheel when you have two taking up precious space?

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 08, 2023, 09:31:33 pm
content: Two counters looks like a simple arrangement.Note that there still are some logic ICs available with a dual counter inside, so could be done with one chip only.For instance the SN74LV8154 (dual 16-bit counter). There probably are dual 8-bit versions out there.

author: MK14
author_rank: Super Contributor
timestamp: July 08, 2023, 09:32:03 pm
content: Quote from: MarkS on July 08, 2023, 07:09:03 pmBecause it can access the even older, M6800 peripherals.Quotehttps://www.nxp.com/docs/en/reference-manual/MC68000UM.pdfand it hence fulfils your requirement:Quote from: MarkS link=topic=384259.msg4950310#msg4950310 date=1688843343IHence, theMC6840(is my suggestion), which can do PWMs.At a quick glance, it seems to be able to provide up to three PWM outputs.https://colorcomputerarchive.com/repo/Documents/Datasheets/MC6840%20Programmable%20Timer%20Module%20(Motorola).pdfWhich may have been the way, a real engineer from pre-1990's would have done the PWMs.

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 08, 2023, 09:59:09 pm
content: Quote from: MK14 on July 08, 2023, 09:32:03 pmOo, I didn't even know those existed back then. (I never had a 68k-based computer myself.)Since MC6840 is probably unobtainium right now – although I do see variants on offer at eBay! –, maybe use a small FPGA, perhaps the open-source programmable iCE40HX1K FPGA (seeOlimex' EVB; Mouser re-sells them if you don't want to buy directly from Olimex), to emulate a set of MC6840's? You may need a bi-directional level shifter (the kind with direction selection pin work best IMO), though, or just use the OlimexiCE40-DIOmodule.Add O4-O15, /C4-/C15, /G4-/G15, and a few additional RS (register select address) pins, maybe change the register address map a tiny bit (each has three registers, so I'd map the two LSB to select the register, and RS2-RS5 to select the PWM channel), to make a "chip" that behaves very much like five MC6840's in parallel, for 15 PWM channels?The logic for the FPGA is quite straightforward, so even a small FPGA suffices. I point out these particular FPGAs only because they don't require any proprietary or commercial tools to program, so no "hidden" or extra costs, if one goes this route.Sure, it is not original silicon, but if one had enough money back then, it is something that would have been achievable since the 3-channel one is known to have existed back then.

author: MK14
author_rank: Super Contributor
timestamp: July 08, 2023, 10:05:27 pm
content: Quote from: Nominal Animal on July 08, 2023, 09:59:09 pmBest to get it from a RELIABLE source. Such as someone from the US, who has great feedback (Ebay) or selling it on this forum, and has some lying around, as NOS (new old stock).The China sourced ones (although they can be very cheap), are a much riskier option.

author: MarkS
author_rank: Unknown
timestamp: July 08, 2023, 10:16:35 pm
content: https://www.ebay.com/itm/265811742119

author: MK14
author_rank: Super Contributor
timestamp: July 08, 2023, 10:23:00 pm
content: Quote from: MarkS on July 08, 2023, 10:16:35 pmYes, that is exactly the sort of much more reliable (looking, but best to still be careful) seller, with apparently/claimed new old stock, availability.Their other ebay sales items, seems to indicate they are a genuine US seller, with genuine items. As they seem to be selling a number of Heathkit items, such as:"Vintage Heathkit Catalog May 1966":https://www.ebay.com/itm/266323498513

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 08, 2023, 10:44:36 pm
content: Quote from: SiliconWizard on July 08, 2023, 09:31:33 pmHowever, the SN74LV8154 (and HC590 someone else suggested), fail as PWM devices, because their counters are READ path only, there is no WRITE path to the counter.

author: DiTBho
author_rank: Super Contributor
timestamp: July 08, 2023, 11:13:00 pm
content: Quote from: Nominal Animal on July 08, 2023, 09:14:26 pmthe 68000 is a very complex CISC CPU and takes a lot of LE when you try to implement it on FPGAs.Modern FPGAs have enough resources nowadays, but the complexity is very high.I wouldn't reccomend it.

author: DiTBho
author_rank: Super Contributor
timestamp: July 08, 2023, 11:34:10 pm
content: years ago I implemented a "digital resistor" device with a latch and a network of resitors.with one/two digital resistors you can modify the dutycycle of a NE555 PWM circuit.Code:. ______________. | dutycycle |. ____|___ ___|____. | | | |.8bit --- latch ----| digital| | NE555 |./ce -------x |resistor| | -------- PWM. |________| |________|. |______________|.some problems:- NE555 needs thermal compensation to avoid frequency drift- the best I was able to obtain was dutycycle from 1% to 99%- there are glitches when send a new value to the latch and it changes the configuration of the R-network- it takes a lot or resitors, which may be 1-5% of tollerance, so ... expensive- the capacitor of the "RC" cell must be low tollerance and very low ESR- the R-network is never perfectly balanced, so the resistence seen by NE555 is never exactly linear/8bit set

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 08, 2023, 11:38:36 pm
content: Quote from: PCB.Wiz on July 08, 2023, 10:44:36 pmI suggested SN74HC590, because in the multiple-PWM-channels mode it runs continuously, and in frequency divisor mode it always starts at zero, and is reset to zero at comparator match.(In the dual counter mode, indeed, each counter would require a separate comparator as well, to reset and disable the current counter and enable the other.)The 74HC40103 OP mentioned is loaded to a specific value, and then decrements to zero, with the carry, /TC, asserted for a single cycle when the outputs are all zero.

author: vk6zgo
author_rank: Super Contributor
timestamp: July 09, 2023, 12:31:21 am
content: Hardly crazy, or impossible!Pre-microcontrollers it was done for a while with a "bog standard" microprocessor & a bunch of peripherals, & before that, using various combinations of discrete or semi-integrated devices.Some devices were "specials" made for just such applications, fairly costly, & not mainstream.If the Military needed such a control, they just "threw money at it".Even some "well heeled" (or fanatical) Aeromodellers used PWM controls back in the early 1960s, made up with discrete PNP germanium devices like OC44s, OC72s, etc.

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 09, 2023, 01:04:41 am
content: Quote from: vk6zgo on July 09, 2023, 12:31:21 amHm.. Since there were/are radiation hardened versions of MC68000, how likely/unlikely it is that the military actually developed a radiation hardened multi-channel version of MC6840 PWM peripheral? Especially if they experimented with satellite robotics? With ceramic bearings and a bit of research into the effects of radiation exposure on various coil lacquers, which probably was done anyways early in the space race, you'd have most of what you need.There being three channels in MC6840 itself is interesting, being sufficient for direction and zoom control. Did spy satellites use gimbal cameras with zoom optics?Interesting stuff, anyway

author: Smokey
author_rank: Super Contributor
timestamp: July 09, 2023, 04:21:28 am
content: Go analog.Generate a triangle wave.Generate an analog voltage as the PWM duty command.User a comparator to compare the duty cycle command voltage with the triangle wave voltage.Output of the comparator is PWM.This is how servo drives controlled motors before microcontrollers with PWM peripherals.

author: gnuarm
author_rank: Super Contributor
timestamp: July 09, 2023, 04:37:28 am
content: Quote from: DiTBho on July 08, 2023, 11:34:10 pmThis approach might work better with a digital resistor based on a switched capacitor. There used to be chips, with all the details to implement tunable filters using switches and capacitors. The capacitors act like charge pumps, conveying current across a connection. The amount of charge in each switching action was pretty much fixed, and the faster the switching, the higher the current (so the lower the effective resistance).The frequency of the switching is easier to control continuously than a bank of discrete resistors. (or is it discreet? I can never remember, and the resistors are too discreet to tell me).

author: gnuarm
author_rank: Super Contributor
timestamp: July 09, 2023, 04:38:57 am
content: Quote from: DiTBho on July 08, 2023, 11:13:00 pmThere are many CPUs that are very adequate and can be implemented easily on a small FPGA. One is called the J1, using around 500 LUT4s in its basic state.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 09, 2023, 04:59:49 am
content: Quote from: gnuarm on July 09, 2023, 04:38:57 amYes, but the OP specifically wants to design around the 68000. So using something else doesn't even make sense here IMO - if he were open to that, he would just use a MCU to begin with.That said, I have evaluated a 68K soft core a few years ago, so anyone interested could have a look and do some testing as well:https://github.com/TobiFlex/TG68K.CI had tested it on a Spartan-6-45 and (just checked), the core was taking about 5500 LUTs (20% of the device LUTs). Definitely more than a simple soft core for a small FPGA, but still pretty manageable without having to resort to large FPGAs. Fmax was about 30 MHz. Certainly much lower than what you can achieve with RISC soft cores on the same kind of FPGA, but still perfectly usable as a 68K.Note that, as they state in this project, this soft core is not cycle-accurate, so if this is a concern for your particular application, you can forget about it.I didn't test it extensively, but from the few tests I did back then, it appeared to work properly.(I didn't end up using this solution though, at the time, we had to choose between a pure software emulation of the 68K and a soft core on FPGA. In the end, the software emulation won for reasons not directly linked to the performance of this soft core.)

author: Siwastaja
author_rank: Super Contributor
timestamp: July 09, 2023, 05:48:23 am
content: Analog motor controller. These were commonplace back in the days. Some kind of opamp integrator triangle or sawtooth wave generator, followed by a comparator. Also remember current sense, need that for motor control, analog or digital, unless the motors are very small. That's one comparator more plus maybe a flipflop which keeps the output off until the next PWM cycle.

author: DiTBho
author_rank: Super Contributor
timestamp: July 09, 2023, 08:12:16 am
content: Quote from: Siwastaja on July 09, 2023, 05:48:23 amyup.Code:.. /|ramp. / |. ___/__|___ trigger. / |. ________/____|_____________________________________ time.. __ __. | | | |. | | | |. ___---__|---__|_____________________________________ timeCode:. ______. | |. | ramp |. | gen | __________|\. |______| | \ voltage compare. ______ | \__________________ PWM. | | | /.8bit ____ | DAC | __________| /. |______| |/.analog parts: ramp wave generator, and OA as voltage compratordigital: latch + DAC

author: DiTBho
author_rank: Super Contributor
timestamp: July 09, 2023, 08:23:15 am
content: Quote from: gnuarm on July 09, 2023, 04:38:57 amI know it, it's used on Gameduino v1 as kind of "VGA blitter", but frankly I wouldn't reccomend it as it only works with Forth programming.OT, anyway, a minimal RISC-V multicycle core is what I would reccomend.

author: gnuarm
author_rank: Super Contributor
timestamp: July 09, 2023, 08:33:28 am
content: Quote from: DiTBho on July 09, 2023, 08:23:15 amHuh? How does any processoronlywork with a specific language??? You mean there's no C compiler written for it?

author: tggzzz
author_rank: Super Contributor
timestamp: July 09, 2023, 08:46:07 am
content: Quote from: MarkS on July 08, 2023, 07:09:03 pmWhy stick at 1990? Why not use the DAC technique invented by Claude Shannon in1948?Muchfasterthan PWM. Muchsimplerthan PWM - one bit serial output (e.g. a UART), one resistor, one capacitor, and a sample-and-hold (i.e. a switch plus capacitor). If the bit period is T, then RC =T/ln(2)https://www.radiolocman.com/review/article.html?di=656991 Yup, that's Shannon as in "useless machine", maze running mouse - and information theory.

author: DiTBho
author_rank: Super Contributor
timestamp: July 09, 2023, 09:48:48 am
content: Quote from: gnuarm on July 09, 2023, 08:33:28 amWriting an HL compiler like C is always feasable in theory but not practically a good idea for j1 as the generated assembly code the compiler outputs is so inefficient and freak that you'd better program directly in assembly, or in Forth to have a sort of built-in debugging.

author: tggzzz
author_rank: Super Contributor
timestamp: July 09, 2023, 10:03:28 am
content: Quote from: gnuarm on July 09, 2023, 08:33:28 amC presumes a flat byte-addressable memory space. Hence there are many computers for which there is no C compiler, or at least only a heavily bastardised C vaguely-looks-like-C subset+superset.I'm very out of touch with the C standards; fortunately I no longer have to waste my life understanding all the subtle meanings and omissions. Do they (still) have "near" and "far" keywords as needed for that abortion, the 80286?

author: gnuarm
author_rank: Super Contributor
timestamp: July 10, 2023, 02:54:58 am
content: Quote from: DiTBho on July 09, 2023, 09:48:48 amC compilers have been written for stack processors, and run well. Trouble is, people who use stack processors, typically understand that C is a crappy language for smaller programs and small targets. The C stack alone can use all the RAM in a small CPU. So why burden a project with such overhead?No need for assembly language, just a good language that is designed for small targets.

author: jonpaul
author_rank: Super Contributor
timestamp: July 10, 2023, 05:31:21 am
content: The PWM SMPS (analog) controller have been around since at least 1970s, simple PWM ICs.i believe one of the first regulating PWM controllers was the Silicon General SG 1524.I visited the factory and met the designer Stan Dendinger in 1976! Used in my first HID/HMI arc lamp electronic ballast.https://www.electronicdesign.com/technologies/power/article/21188405/pwm-from-a-single-chip-to-a-giant-industryThese analog ICs proceeded digital controller by about 15..25 years.Jon

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 10, 2023, 06:29:12 am
content: Quote from: jonpaul on July 10, 2023, 05:31:21 amMC6840 was introduced in 1978 (in "Motorola Semiconductor Products Inc., Specification DS9802 Programmable Timer Module MC6840, 1978."), and is an 16-bit digital programmable timer module with three-channels, capable of PWM outputs but much more besides, running at up to 1/1.5/2 MHz.

author: DiTBho
author_rank: Super Contributor
timestamp: July 10, 2023, 08:46:59 am
content: Quote from: gnuarm on July 10, 2023, 02:54:58 am"run well" ...for example, the machine code produced by gcc C/89 for hc11 in "expanded mode" (the CPU can fully address 64Kbyte) is an order of magnitude suboptimal than manual assembly programming. Hc11 has two index registers and only one accumulator, and it continuously needs push/pop in order to compute expresssion, doing IO stuff, and functions calls, so to follow the C machine layer model, from how to evaluate an expression (reverse polish notation is the best match here, all stack based) to how to handle calls of function (arguments pushed onto stack, response popped off stack), it always ends with much opcodes and stack space is wasted on machine-level glue code, which, being all stack-based, heavily uses asynchronous ram, which is several orders of magnitude slower than CPU registers.Thank goodness, the hc11/E chip comes with half 1kbyte of internal (on-chip) static ram, and I can make better use of it by turning it into "virtual registers" to have more CPU registers, say 32 registers, like RISC. Yes, again "memory-based" operations instead of "pure register operations", and the code size only benedict a 2% off, which is nothing, but the speed up is 40%!!!The commercial Avoget C/11 has a flag to use soft-registers, other commercial C compilers for hc11 don't have this trick, and with gcc ... you have to hack the old v3.3.6.The point is that it's still suboptimal vs assembly programming, where you cleverly use resources and avoid repeated patterns ... here C has problems because "optimizing" the machine code produced by the HL is a very difficult task on stack-machines, and, in any case, it's the best trick you can do when you have 512byte of internal ram at your disposal.So you say "run well" , I say "mumble"

author: MK14
author_rank: Super Contributor
timestamp: July 10, 2023, 09:08:28 am
content: Quote from: DiTBho on July 10, 2023, 08:46:59 amIt (68HC11) seems to have two accumulators, A and B, which can be combined as one 16 bit accumulator (D).https://en.wikipedia.org/wiki/Motorola_68HC11It makes a big difference, which is why I pointed it out.

author: gnuarm
author_rank: Super Contributor
timestamp: July 10, 2023, 09:31:18 am
content: Quote from: DiTBho on July 10, 2023, 08:46:59 amSo, which small processor runs C programs as well as assembly programming???

author: DiTBho
author_rank: Super Contributor
timestamp: July 10, 2023, 11:33:57 am
content: Quote from: MK14 on July 10, 2023, 09:08:28 amA and B makes no difference in practice as a lot of instructions are not able to access B, only D, and you have to swap(A,B) or use D.Also, the point was: stack-oriented, instead of regs!

author: MK14
author_rank: Super Contributor
timestamp: July 10, 2023, 11:36:17 am
content: Quote from: DiTBho on July 10, 2023, 11:33:57 amBut the point also is, that an assembly language program can usefully use both 8 bit accumulators. Contributing to the potentially higher program execution time efficiency.8 bits is big enough for many things, if you want to scrape the last ounce of performance out of a relatively slow, low end 8 bit microcontroller or microprocessor.

author: DiTBho
author_rank: Super Contributor
timestamp: July 10, 2023, 11:38:03 am
content: Quote from: gnuarm on July 10, 2023, 09:31:18 amonly RISC ones(1), I am afraid none in the stack-oriented class.(1) I think the tiny-AVR8 is a good example here.

author: Siwastaja
author_rank: Super Contributor
timestamp: July 10, 2023, 11:54:35 am
content: Quote from: gnuarm on July 10, 2023, 09:31:18 amAVR architecture (with whopping 32 registers) comes close. Of course, hand-crafted assembly by someone who knows exactly what they are doing always wins (or becomes a tie), but that is true for small and large processors, equally. C on small AVRs is definitely not any worse than C on large targets, and is definitely good enough for nearly all jobs, and as a result, it's rare to see anyone writing AVR programs in anything else than C.

author: madmac
author_rank: Contributor
timestamp: July 10, 2023, 05:51:11 pm
content: 74HC393 dual 4 bit counter wired as 8 bit counter and clocked to generate a digital ramp count. For each motor connect counter to one side of 74HC684 comparitor the other side to an eight bit latch. Use the > output as a PWM. Load latch for PWM value.To make a bit neater use a two input nand to combine '>' and '=' outputs of the comparitor.Two 20pin parts per motor with a common 14 pin counter........needs a clock from somewheremadmac

author: Siwastaja
author_rank: Super Contributor
timestamp: July 10, 2023, 06:07:50 pm
content: Nah, digital PWM controller out of discrete logic seems too simple; basically a copy of the block diagram in microcontroller timer/PWM module (minus unnecessary stuff like input capture). In essence, counter and comparator.Why not complicate things a bit and forget brushed DC motors? Do a FOC controller, BLDC (easier) or AC induction motors. I'm pretty sure some of the first, original FOC controllers were built in such discrete logic.

author: RoV
author_rank: Regular Contributor
timestamp: July 10, 2023, 08:12:11 pm
content: Many years ago I used a TL1451AC to convert analog signals to PWM. It was in 1999, I am surprised to see that the chip is still available e.g. on Mouser. This is an option if you can add an 8 bit DAC.

author: DiTBho
author_rank: Super Contributor
timestamp: July 10, 2023, 08:21:51 pm
content: Quote from: madmac on July 10, 2023, 05:51:11 pmI like this idea! It's simple and elegant.

author: MarkS
author_rank: Unknown
timestamp: July 10, 2023, 08:31:01 pm
content: Quote from: madmac on July 10, 2023, 05:51:11 pmYes, but how would I adjust the duty cycle? The '393 just takes an input clock signal. That's all well and good, but I've got an 8-bit binary signal from the processor and the motor controller uses the duty cycle to set the motor speed. The value presented on the data bus needs to directly correlate to the PWM duty cycle.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 10, 2023, 08:37:34 pm
content: Quote from: MarkS on July 10, 2023, 08:31:01 pmIn that description the 20 pin74HC684 comparitortakes the 8 bit value and compares with the rampTI can sell you 74HC684 for$3.583/1k

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 10, 2023, 09:06:51 pm
content: Quote from: PCB.Wiz on July 10, 2023, 08:37:34 pmMouser has a few dozen in stock, for 7.3€ (TI SN74HC684DW) or 10.7€ (TI SN74HC684N) apiece.

author: MarkS
author_rank: Unknown
timestamp: July 10, 2023, 09:14:01 pm
content: Quote from: PCB.Wiz on July 10, 2023, 08:37:34 pmThe74HC682is virtually identical and still active.One74ACT16373with two 74HC393's and 682's should work and allow me to use the full 16-bit data bus to control the two motors... Hmm....

author: RES
author_rank: Regular Contributor
timestamp: July 10, 2023, 10:08:25 pm
content: LTC6992 - TimerBlox: Voltage-Controlled Pulse Width Modulator (PWM)ordesign a stable two stage transistor only PWM generator; triangle wave oscillator + comparator

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 10, 2023, 10:45:12 pm
content: Quote from: MarkS on July 10, 2023, 09:14:01 pmI think you mean one 16373 or 16374 latch and one 74HC393 and two 682's ?You will likely need a D-FF on the 682 output, as the 393 is a ripple counter so will give glitches.You should always sanity-check this against a small MCU with maybe 1~2 dozen lines of assembler, to init the PWM block, and copy ports to pwm.

author: MarkS
author_rank: Unknown
timestamp: July 10, 2023, 11:07:22 pm
content: Quote from: PCB.Wiz on July 10, 2023, 10:45:12 pmYes.Quote from: PCB.Wiz on July 10, 2023, 10:45:12 pmGood idea!I forgot about ripple counter stability issues.Quote from: PCB.Wiz on July 10, 2023, 10:45:12 pmI've got an Arduino, multiple ESP-based microcontroller board and a Pico. That will not be a problem.

author: gnuarm
author_rank: Super Contributor
timestamp: July 11, 2023, 12:24:17 am
content: Quote from: MarkS on July 10, 2023, 11:07:22 pmWhat "stability" issues??? Ripple counters have no issues decoding a terminal state without additional latching, if that's what you are talking about. The carry is not a signal that enables FFs, it is simply the Q output, which is used as a typically falling edge clock. That means, every intermediate state, as the "ripple" propagates through the counter, is a lower numeric value, than the terminal state.Are you detecting intermediate states?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: July 11, 2023, 12:43:58 am
content: Quote from: MarkS on July 10, 2023, 11:07:22 pmThe PICO PIO state engine could likely manage this, stand alone, so an interesting challenge would be to do this entirelywithin a PIO, and then you have done it 'without a microcontroller'If you want to apply this ruleQuote from: MarkS on July 10, 2023, 11:07:22 pmYou could use any (modern) 8051 MCU with a PCA, as all that was designed and available pre-1990.

author: MarkS
author_rank: Unknown
timestamp: July 11, 2023, 02:50:56 am
content: With a little bit of tinkering inLogic.ly, I got madmac's idea to work. Logic.ly is just a toy when compared to LTSpice and whatnot, but it's a clever and easy to use little toy!You can use Logic.ly'sonline demoto open and run the attached file.

author: madmac
author_rank: Contributor
timestamp: July 11, 2023, 07:56:16 am
content: Going for 16 bit control might make the 74HC393 clock a bit high depending on the PWM frequency you want.Retro designs going back to the mid eighties. 8 DC servo motors with incremental encoders plus 74HC684 / 74HC573 / HCTL2020 (16 bit position count) for each motor and a 12MHz 8051 with crafted 8 x PID loop assembly code.Serial RS485 input for control.madmac

author: r6502
author_rank: Regular Contributor
timestamp: July 11, 2023, 11:12:37 am
content: Hello all,Have a look at some older Keithley stuff. They used also PWM as DAC for analog signal generating, e. g. in K263 current calibrator.Have a look on the part of the schematic, where thy do the PWM, attached to this post.Guido

author: MarkS
author_rank: Unknown
timestamp: July 11, 2023, 03:10:31 pm
content: Quote from: madmac on July 11, 2023, 07:56:16 amThe motor controller I'm going to use requires a 20 KHz PWM frequency. But maybe I'm misunderstanding you?

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 11, 2023, 03:42:19 pm
content: 20 kHz PWM frequency at 8 bit duty cycle resolution = 20,000×28= 5,120,000 or 5.12 MHz clock.20 kHz PWM frequency at 16 bit duty cycle resolution = 20,000×216= 1,310,720,000 or 1.31 GHz clock.Remember, during each PWM period, the your counter counts through all values.The Nexperia 74HC393 and 74HCT393 maximum clock frequency depends on supply voltage, but at 5V you can expect at least 20 MHz (but in room temperature up to 99 MHz). 20.48 MHz clock can provide 10 bit duty cycle resoution for 20 kHz PWM; 81.92 MHz clock 12 bit.

author: MarkS
author_rank: Unknown
timestamp: July 11, 2023, 06:58:09 pm
content: Quote from: Nominal Animal on July 11, 2023, 03:42:19 pmThe circuit is split into two 8-bit duty cycles. The counter is split between the two comparators, but is only counting from 0 to 255. Each comparator is connected to a separate byte of the data bus. A 5 MHz clock is well within the tolerance of the '393. If I'm not understanding, please explain further.

author: DiTBho
author_rank: Super Contributor
timestamp: July 11, 2023, 07:46:31 pm
content: Quote from: Nominal Animal on July 11, 2023, 03:42:19 pmThat's why I suggested the digital resistor hack: it doesn't require high clock, it has other problems.Anyway, 5Mhz is feasable.

author: SiliconWizard
author_rank: Super Contributor
timestamp: July 11, 2023, 08:35:17 pm
content: Do you really need 16-bit resolution for a PWM controller that (from what I got) is meant to control motors?

author: MarkS
author_rank: Unknown
timestamp: July 11, 2023, 08:52:29 pm
content: Quote from: SiliconWizard on July 11, 2023, 08:35:17 pmNo no no! It's only 8-bit resolution per channel. The circuit I showed has two separate channels. The 74ACT16373 consists of two 8-bit latches in one package. The full 16-bit data bus is connected to the latch, with the lower byte controlling one motor and the upper byte controlling the second. These are two separate circuits sharing two chips (the '393 and '16373). I combined the Latch Load and Clear inputs in the simulation for simplicity. In the actual circuit, these would be gated to address decode logic and the UDS and LDS strobes from the processor.I removed the hex displays and it makes the wiring somewhat clearer.

author: Nominal Animal
author_rank: Super Contributor
timestamp: July 12, 2023, 04:57:43 am
content: Quote from: MarkS on July 11, 2023, 08:52:29 pmYep, no problem there.I read:Quote from: madmac on July 11, 2023, 07:56:16 amas a side note, saying that two 8-bit PWM channels are fine, but using full 16 bits for a single channel would require a low PWM frequency, as the 74HC393 is limited with respect to the input clock rate it can handle. The mentionedAgilent HCTL2020is a 16-bit counter with an 8-bit parallel interface; looking at the datasheet gives ideas on how these were used back in the day.

author: MarkS
author_rank: Unknown
timestamp: July 13, 2023, 12:38:43 pm
content: Quote from: Nominal Animal on July 12, 2023, 04:57:43 amThat's good to know, but I don't see any need for that kind of resolution for this application. The PWM signals will just control motor speed. This is a small hobbyist robot, not a racecar!In fact, I'm probably going to wind up using only 7-bits of the data bus per channel with the 8th bit being dedicated to direction control.

author: DavidAlfa
author_rank: Super Contributor
timestamp: July 13, 2023, 03:35:22 pm
content: Quote from: MarkS on July 08, 2023, 07:09:03 pmhttp://www.hobby-circuits.com/circuits/pwm-and-power-control/852/discrete-pwm-generator-circuithttps://web.archive.org/web/20180208013328/http://homepages.which.net/~paul.hills/Circuits/PwmGenerators/PwmGenerators.html