pheloniusfriar: (Default)
Copying another post I made on the Cypress/Infineon user forum here so I have it myself.

I have written an article on my blog on the process I followed to get an audio clip into a PSoC 4200 MCU (I used the CY8CKIT-049-42xx PSoC 4 Prototyping Kit), and play it back using a TCPWM component. I start with a 44.1kHz 16-bit PCM stereo audio recording (CD quality), and go step-by-step on how to process the audio, reduce the dynamic range (bits per sample) and the sampling rate to reduce the number of bits needed for the clip, how to program the samples into flash so they're accessible to an interrupt handler, and how to use a PWM technique to generate the analog output of the audio. I provide instructions on what is needed with respect to filtering and amplification, but don't go into detail (that's for another post another time probably). I did use the two on-chip op-amps with a few resistors and capacitors to implement a 4th order Chebychev filter and then used an off-the-shelf audio amplifier to drive a speaker. Other than PSoC Creator, all of the software I used is open source or are simple little C programs I wrote myself (and provide instructions on how to duplicate). Spoiler alert: I got about 1.4 seconds of 11-bit 11.025kHz linear PCM audio into the chip (which takes about two thirds of the flash memory). If that's not enough, there are some serial (SPI) flash memories that can hold about 9 minutes at that rate/sample depth (<$4 in qty. 1). I implemented this on a PSoC 4200, but the technique is quite general (and can be used with MCUs that have proper DACs as well).

Here's the link: Stuffing an audio file into a tiny processor chip


In response, someone [odissey1] asked me if I could post the project code, so...

Project file or it never happened, eh? Fair enough. Please find attached.

1kHz_PWM_Audio_Demo_v1.0 project file is here!

The archive contains a project targeted at the CY8CKIT-049-42xx PSoC 4200 prototyping kit (including it's use of the bootloader component); but the schematic, TCPWM configuration, and source code should be easily adaptable to any PSoC target with a TCPWM component (the C code is mostly generic with a few PSoC specific commands to set things up). The CY8CKIT-049-42xx bootloader files are there too so it should compile right out of the .zip file without reconfiguration if you have one lying around. I have also included a simple audio data file ("sine_1kHz.dat") that has a 1kHz sine wave sampled in it that the code just repeats over and over again (and outputs on P3.0 for this project).

Here's a bad photo taken with my terrible phone using a sad oscilloscope of the PWM data output on a pin (you can see the density of the PWM signal changing).



Here's another bad photo taken with my terrible phone using a sad oscilloscope of the output from the not so great filter circuit using the PSoC 4200's on-chip op-amps. Note that there is a fair amount of distortion in the sine wave... the filter really isn't that good, but it's still good enough for what I needed it for. Also note that the 'scope is set to 2V/div and 0.5ms/div, and that the ground potential is the graticule below the waveform, so you can see that the centre of the sine wave (the common mode voltage) is indeed at about 1/2 of the supply voltage of the PSoC 4200 (5V... powered off the USB interface of the CY8CKIT-049-42xx). The filter could be made much better if the digital PWM signal were run through a divider first and if I were a little more careful with the component selection (but the lack of a SPICE model for the on-chip op-amps makes doing a great job a little harder).



Hopefully this proves useful.


As an aside, this project file is intended for use with the PSoC_Creator Integrated Development Environment. As a write this, it is available for free download (it was always free) at: https://www.infineon.com/cms/en/design-support/tools/sdk/psoc-software/psoc-creator/

They then asked (reasonably enough), "Do you have any idea why the sine output looks asymmetric? Is this the effect of the Chebyshev filter or intended PCM signal?"

And my answer:

There are a bunch of reasons why the "sine" is not so sinusoidal, where to start? The filter components I used were built on a little breadboard PCB plugged onto connectors I put on the CY8CKIT-049-42xx and the circuit has no particularly effective ground, so there are all kinds of basic signal integrity problems. The sine wave only has 14 samples (that I kind of randomly chose... the samples are not symmetric and the knee might simply be from looping), so it's going to be pretty choppy no matter what (it would be that way even with a proper DAC), but the problem is compounded by using a PWM and asking a sub-optimal filter circuit to do a lot of heavy lifting in filtering out that digital signal. The filter circuit itself doesn't have the exact component values I wanted because I didn't have those values on hand, so it's approximate in its performance that way too. If I wasn't swinging nearly 5V peak-to-peak I think that would help a lot as well. The op-amps on the PSoC 4200 kind of suck in terms of their performance, and using a filter built with good quality external components would give a much better result (my early attempts were nightmarish, so the distortion here is actually a huge step forward from where I started). Lastly, the lack of a SPICE model for the on-chip op-amps meant that I couldn't really tune the filter circuit nicely to the op-amp performance and just kind of did things empiirically. I know I could do better even using the on-chip op-amps, but that's a project for another day. Ultimately, I was completely successful in what I was trying to do, which was to only use a CY8CKIT-049-42xx that I had (with a few external passive components) to drive an amplifier and little speaker with a short audio clip. In the context that I was using it, and with the audio clip I had, the sound coming out was entirely acceptable (even with whatever distortion it would have).

After looking at the code for the project I provided they said, "The code is certainly not trivial. My guess that most of the complexity comes from extracting the 11-bit audio from the 8-bit storage array. Is there any audio software capable of such packing or you had to post-process PCM data?"

So...

I just used open source software to get the data into a format where I could pack the 11-bit samples with my own code (into 8-bit bytes). As I wrote in my "article", I did it in two stages: the first little program took it from 16-bit signed PCM (in a RAW file format, that had already had its dynamic range squashed to 11-bits) and wrote it out to disk as a 11-bit samples packed together as a data stream (written out 8-bits at a time to disk), then another little program to convert the byte-stream into comma-separated ASCII for loading into the C compiler uint8_t array when it compiled.

I didn't post the code for the audio conversion at the time, but here it is in all its (lack of) glory for posterity. Very simple code, but tricky to get right.

First, compile "encode_raw.c" and "enc2dat.c" (filenames are links to C code files).

Follow the instructions in the article I wrote to get a RAW audio file (the instructions are relatively clear in my opinion). Then run the encode_raw program:

encode_raw filename.raw

This will generate a binary file filename.enc that contains the packed 11-bit PCM audio data. The run the enc2dat program:

enc2dat filename.enc

This will generate a text file filename.dat that contains the data for including in the final project code like so:

const uint8_t audio_data [] = {
#include filename.dat" // Put comma separated values audio samples file here
};


This initializes the uint8_t array with the audio data that the program's code will need to pull out as an 11-bit PCM stream (from the array of 8-bit values). I thought this was a fairly clever way of doing it as it allowed this arbitrary audio data to be programmed into Flash along with the program code. If more data space was needed (the chip I was using only had 32K of Flash for programs and data), then an externally connected Flash chip could be used.

And for anyone who scrolled by, here's a non-technobabble gift. Show 25 from Season 1... Note: this episode is Not Safe For Work (NSFW) and full of various naughty bits (every 25th show will be a collection of the naughtier songs and videos I have run across so they're all in one place and are easier to avoid and/or focus on).

pheloniusfriar: (Default)
I like PSoC processors, and I cannot lie. They were extremely innovative and the development tools are like nothing else in the industry. In specific, these are "system on a chip" chips that actually live up to their name: they have a CPU (either an 8051 variant or some flavour of ARM processor... the PSoC 4200 that I have been using often has a 48MHz ARM Cortex-M0+ CPU), a fairly complete set of often-used peripherals (e.g. Serial Communications Blocks that can be a UART, I2C, SPI, etc.), but then they have programmable and reconfigurable digital and analog circuitry! On the analog side, it comes with things like op-amps, comparators, multiple-input scanning ADCs, and DACs (some specialized current mode ones for use with capacitive touch sensing, another specialty of the PSoC processors), and the PSoC 1 had support for switched capacitor technologies (used for signal filters, etc.). But it was routable on the chip and could be connected to almost any pin (there were "associated" pins that used less resources, but it wasn't cast in stone that they had to be used)! For the digital side of things, they created something called Universal Digital Blocks (UDBs). I'm not going to lie... UDBs are hard to use and it takes a lot of work to wrap your brain around them... but, once (if?) you figure out how to use them... wow! Like seriously wow, these things are game changing! Where in most designs I would need to add all sorts of circuitry to a board to customize it to the application I want to use it for, with UDBs I could implement most smallish designs right on the PSoC chip itself without having to use any other chips on the printed circuit board to support the application. I can't emphasize too hard how spectacular this capability is. Without going into detail (I could go on and on, but won't), the UDBs each contain two PLDs (12C4 with 8 product terms (PTs)), a swiss army knife control and status block (so many different functions), all the digital and clock and reset programmable routing needed, and an 8-bit "datapath processor" (DP) that can be chained to adjacent DPs to form larger data-word processors (e.g. 32-bit). The microcode of the DP processor is normally controlled by the PLD logic... you can literally build your own custom processor out of programmable logic on the PSoC itself from UDBs. The DP contains an ALU, a register set, input and output FIFOs (to communicate with the CPU and optional DMA on some chips), and an 8 instruction microcode set (surprisingly powerful). UDBs can also be used to build things like " I2C, UART, SPI, SDI12 , OneWire, (Capture) Timer block, CAN, Manchester decoder, Quadrature decoder, Counter block, SmartIO, LFSR / CRC functionality, ShiftReg glitch filtering, State Machine functionality, and random number generation". Powerful, but hard to work with because of their configurability and layer upon layer of functionality. The PSoC chips contain zero to dozens of these UDBs, and the 4200 that I've gravitated to has 4.

Cypress, who made the PSoC family, was bought by Infineon, and I don't know what I'm seeing yet. Even before then, Cypress seemed to be moving away from the "system on chip" concept, that made them stand out in the crowded and competitive microcontroller field, towards more ultra high volume applications with hardcoded functionality on their processors rather than the configurable logic and analog capabilities that made PSoC different. In one of the forums, someone [Rolf_Nooteboom] said (before the Infineon buyout) "I am still worried Cypress is phasing out UDBs and that would be worst thing what could happen to PSoC imho (it would then be like any other microcontroller and lose a lot of the functionality for why one would choose PSoC over an other MCU)", to which someone [Len_CONSULTRON] answered "According to a Field rep for Cypress I spoke to, this appears to be the direction. It is my understanding that the reasoning behind this direction is that few designers using their product make use of all the UDB and routable analog features". By the very nature of having a reconfigurable digital and analog feature set, the functionality built onto the chip will always be a superset of what is used in any particular application (although I've come close to using every part of a PSoC in one application). This "wastage" means we're paying for circuitry on the chip that is not used. The cost/benefit equation is such that the hope is that extra cost is more than offset by speeding development (saving money on R&D directly, but also by getting to market faster which can easily be a 50% increase in profits) and reducing parts count on the printed circuit board (fewer components means less costly boards and lower board R&D costs, higher reliability, and lower inventory/stock requirements which can also be huge [especially in times of supply chain disruptions like we're seeing now]). This value proposition doesn't break down until very high volumes are achieved with product sales (like hundreds of thousands to millions of units of one design). The margins get slimmer for chip manufacturers as volumes increase, but so does the challenge of having to manage a complex product portfolio where a few models get chosen for a few high volume products and the rest end up in medium to low volume applications. Here we see another sickness caused by the MBA/CEO class: they're lazy and stupid and are obsessed with specific metrics that translate into short term success (where they fill their pockets) but not into long term company stability (if the horses they were betting on fail, there's nothing to fall back on... saw it at Nortel before it went bust... it's the same sort of people every time: they ditch the product lines growing at 5% a year in favour of the latest bubble growing at 100% per year, and when the bubble collapses, so does the whole company... but I digress).

Anyway, there are two reasons why I'm making this post. The first is that I'm working on a design that has ended up needing quite a bit of UDB functionality, and the second is that I commented on the above forum discussion with the following, which I wanted to preserve for myself (in case Infineon nukes the community forums or specific threads... although they do seem to be enhancing them rather than shutting them down, although there was a definite period of chaos that was quite concerning).

UDBs and analog routing are the reason why I've stuck with PSoC even though it's a more expensive chip in some cases: the per-unit cost is made up for by the integration, ease of use, and flexibility it offers me as a designer (not to mention the uniqueness of PSoC Creator!). The patents look like they're in place (depending on which one) for the next decade or so. If Infineon/Cypress does phase out UDBs, I hope someone licenses those patents to use them in their own chips (or that they sell at least some of the "before PSoC 6" families to another company). If not, in 2032 (presuming they're not abandoned earlier), someone could integrate them, or an upgraded version of them (I can think of some changes that would be great), into RISC-V based chips perhaps or as dedicated "configurable/programmable datapath" chips (in either case, the clock rates could probably be jacked up significantly).

The two main relevant patents I could find are:

Universal digital block with integrated arithmetic logic unit

Universal digital block interconnection and channel routing

I'd love to have the money to make an offer to buy the PSoC line (or at least some sub-technologies like the UDB), but I live from paycheque to paycheque (and not always reliably) like many people. So file the thought under "if wishes were fishes".

Anyway, more of a "note to self" than anything.

On an unrelated note, I managed to finish "Season 1" of "The Passionate Friar on YouTube" (Episode 26). It ends with a bang and not a whimper (intensity 11 out of 10), and I am doing some "housekeeping" before starting on "Season 2" (hopefully some time in the next 8 weeks).

pheloniusfriar: (Default)
I just got back from the two weeks in Shanghai, China and realized that is the first actual vacation I have had in four years (when I went to a friend's cottage for four days). There is no wonder I've been so burned out. I had a great time and really liked the place: it is dynamic and vibrant, a broad mix of influences, and was culturally diverse (meaning many Asian cultures and some Western cultures). Taking ground transportation (maglev) that hit 430km/h was mind blowing given the rather pedestrian speeds available on any ground transportation I've ever taken in Canada. The banking and financial sophistication there — right down to the most basic transactions with street food vendors (btw, zomg yummy!) — was also so far advanced over anything I've experienced before. Don't even get me started on social media: there, it facilitates in-person experiences rather than insulating from it and has features I've also never seen on this side of that pond to faciliate real-world communities. On a separate note, on my first outing with locals for dinner, it was inevitable: they ordered a "soup with two eggs", which was one of their favourite dishes (each person ordered a dish to share at the table). One egg was egg drop in the soup and the other was, of course, a century egg. Gotta say I was hoping to make it through my trip without having to face one, much less having it served in such a social situation. The verdict: it actually tastes good, and the texture wasn't as sketchy as I thought it would be :-). I would definitely have it again in a dish, but I can also say that I'm not going to rush out and buy a dozen to start tossing in ramen at home ;-). Baby steps. Next up? Probably chicken feet.

On my last evening there, I gave a presentation on the amazing $4 CY8CKIT-049-42xx Cypress PSoC development kit at the Xinchejian hacker space weekly open house. I use it in a number of projects I've been working on, and it's an order of magnitude more complicated (at least) than the Arduino processors that are in wide use, so I thought it might be of interest (and they did too as they invited me after I pitched the idea to them). Despite some A/V technical issues, the talk went well and there were quite a number of questions during and after (talks were given in both Chinese and English). The dev kit is also available on Taobao in China for nearly the same price (¥29.00), which is good. Hopefully more on that later, but I need to try to sleep again as I am jet lagged as fuck and need to adjust my schedule back to Ottawa time as soon as I can (I tried to sleep earlier as I was crazy tired, but I couldn't drift off, thus this post). I can't wait to go back and do some deeper exploration (and with more Mandarin language skill than I went with this time, which was effectively zero, if not less... but everyone was quite patient and we made it work by pointing and smiling to each other, or with the aid of a translator on one of our phones). Lots of other great stuff happened while I was there, but I'm going to stop here for this post. So... time to finish the series...

These short biographical essays were written as part of a 4th year Women's and Gender Studies seminar class I took in the winter/spring of 2017 called “Representations of Women’s Scientific Contributions” with Dr. Cindy Stelmackowich at Carleton University. Each of the essays required deep research into difficult to find historical and contemporary info-fragments and sometimes oblique references in order to find a coherent and accurate narrative. They also needed to be short (always a challenge for me).

Born in 1896 along the Bay of Fundy, “as a child she sailed around the world with her [sea captain] father” and growing up “often played by the shoreline, studying the tiny creatures in the water – the beginnings of her interest in fossil invertebrates” (Monteith, 1993). She earned a B.A. in general arts from McGill in 1919. However, after finishing her B.A., a field trip to Manitoba with Alice Wilson, whom she met at McGill, inspired her to follow a career in geology (Sherriff & Reuter, 1994). She went on to get her M.A. from the University of Toronto (UofT) in 1923, in 1926 became “the first woman in Canada to get a Ph.D. in geology/paleontology”, and further was “the only woman [in Canada] to have an academic position during the interwar period” in that field (Ainley, Rayner-Canham, & Rayner-Canham, 2012). She served as Associate Director and then Curator of Invertebrate Palaeontology of the Royal Ontario Museum (ROM) from 1936 to 1957, professor of paleontology in the Department of Geology of the UofT from 1956 to 1967, and then as professor emeritus in the Department of Geology at the UofT and Research Associate in the Department of Invertebrate Palaeontology in the ROM until her death in 1990 (aged 94) (Monteith, 1993). Regarding her association with Alice Wilson, it is important to note that in 1938, for her work at the Geological Survey of Canada, Wilson became the first woman to be elected a fellow of the Royal Society of Canada. In 1942, for her prolific and influential work on invertebrate fossils and her prowess as a curator and administrator, Fritz became the second woman to receive that honour (Friedland, 2013).

Fritz’s relationship to her mentor at the UofT, William A. Parks, is mentioned in nearly every article on her career. It is telling that even in the mid-1920s, Parks was willing to share credit with her. For instance, a mid-1920s US government index of geological work contained the following reference: “Parks, William A. 1711. (assisted by Madeleine Fritz). The stratigraphy and paleontology of Toronto and vicinity; Part III, Gastropoda, Cephalopoda, and Vermes: Ontario Dept. Mines, 31st Ann. Rept., vol. 31, pt. 9, 45 pp., 5 pls., 1923.” (Loughlin & Mansfield, 1926). In 1971, she wrote a biography of Parks (Fritz & Museum, 1971) in which she indicated a number of notable individuals to whom he was instrumental in launching the careers of; however, she does not number herself in that list, although she acknowledges his role in her own bio at the end. While Parks facilitated her advanced studies – she was the only woman graduate student at the UofT in the 1920s – and worked with her at the ROM, she indicated that she operated in an overall atmosphere of acceptance and encouragement, and commented “that she felt accepted by the men and that no one tried to discourage her” (Ainley et al., 2012). At the same time though, “aware of the difficulties married women faced in academe [...] chose to remain single and pursue graduate studies” (Ainley et al., 2012).

During her career, she published more than 70 academic papers on samples that she both received and collected from the west of Canada (Fritz, Unknown) to the east (Fritz, 1966) and points in between (Fritz, 1957), and was responsible for the discovery and naming of several new species (see, e.g., (Fritz, 1941)) and the re-classification of others (Fritz & Royal Ontario Museum, 1981). Her impact on the field of invertebrate paleontology cannot be understated as “she achieved world renown for her scientific papers on fossil Bryozoa”, and “so many Fritz-educated professors have taught in paleontology departments of universities around the world that she has been called ‘the great-grandmother of Paleozoic Bryozoa’” (Monteith, 1993). Despite direct opposition by the Geological Survey of Canada to women participating in field work (Ainley et al., 2012), she continued to engage in such endeavours through much of her career while also working as a researcher, administrator, and teacher. “Her three-pronged professional path was unique in the history of Candian women and science, because men dominated such positions in geology/paleontology, in both university and museum settings. [Other successful women] followed the more usual path of ‘surrogate mother’ as dean or warden for women” (Ainley et al., 2012). Fritz’s professional ambitions, determination, and resourcefulness stand out to this day as exceptional during the times in which she flourished (Prentice, 1991), and while she perhaps sacrificed her personal life to be allowed to work, opened opportunties to many that followed.

And the very useful references are here... )
pheloniusfriar: (Default)
Well, I am finally back up to a basic operational level with Verilog coding... only to find out that the project I will be working with has been done in VHDL. While one language versus another is usually no big deal for me (okay, I hate C++, but I've been using it since the 80s when I worked on what was, at the time, the largest C++ project in the world and I'm good at it, but that doesn't mean I have to like it), VHDL has its roots in the Ada programming language D:. Why the grumblings? Ada was developed by the U.S. Department of Defense and is one of the most notorious Bondage and Discipline languages in existence. While B&D might be fine, it needs to be consensual and nobody ever asked me if I wanted the flagellations VHDL/Ada will entail ;).

It does remind me of an interesting side path in processor technology development from way back when... the Intel iAPX 432 system. By any measure, this was a complete failure for Intel (and the industry as a whole), but it introduced a number of features that we now see in most modern processors. I'm not going to go into it here, except to say that it supported object oriented data access and security control models at the hardware level, supported explicit hardware fault tolerance and multi-dimensional data busses, had superscalar processing elements, and so many other features that were too far ahead of their time (and thus made the system intolerably slow and cumbersome, and thus uncompetitive). I remember that the instruction set was actually a bitstream read into the processor in 32-bit chunks and parsed, and that instructions could be anywhere from 4 to 111 bits in length! It really was an engineering masterpiece, but I often mused that the people that worked on it must have been locked up in the loony bin afterward en masse (I think one of them went on to be CEO of Intel or something... maybe the same thing? Heh). Anyway, why I bring this up is the 432 was never meant to be programmed in assembly language or even "system" languages like C, but rather was designed such that Ada was essentially its assembly language. Perhaps that is another reason (maybe even moreso) for its demise ;). Sadly, VHDL is widely used in the electronics design sector, so it was inevitable that Ada would eventually catch up with me... I took two textbooks on VHDL out of the Carleton library on Wednesday and have started reading them. I am determined to progress, if equally resigned to my fate.

I'll make sure to leave a tube of lube on my desk as I work... it might make the proceedings a little more comfortable to me ;).

On a completely separate note, I am currently listening the heck out of Floex's album "Zorya" (Floex is the project of Czech composer, musician, artist, producer, etc. Tomáš Dvořák, who also did the gorgeous soundtracks for the delightful games Machinarium, which is where I first heard his work, and Samorost). The music on this album successfully pulls from so many different styles: prog, classical, industrial, pop, etc. and puts them together into what I find a very pleasing whole, blending acoustic instruments/sounds with synthesizers and samples. In particular, on one track (Forget-Me-Not), he plays piano and a clarinet without a mouthpiece that I can listen to over and over again... melancholy and evocative, it really floats my boat right now. The clarinet played like a trumpet has a very distinctive sound (to say the least) that makes that song stand out for me. There are many different moods throughout the album and even within the songs that keeps it interesting all the way through. It also features the best Yes song not by Yes I've heard in a while ("Precious Creature" featuring the vocals of James Rone), heh. You can listen to it free on his Soundcloud page (or listen to and potentially buy it at his Bandcamp site):

https://soundcloud.com/floex/sets/zorya

(the Soundcloud page is nice because it talks about some of the intruments and credits the other people that performed on the album... just click on "Show more...")

Edit: I started reading Douglas L. Perry's book "VHDL Programming by Example", Fourth Edition, McGraw-Hill, ISBN 0-07-140070-2. It bills itself as "the hands-down favourite user's guide to VHDL"; but good lard, what a disaster! I made it as far as page 4 and had already picked out typos and plain wrong information... the cruftiness was continued on page 5... and I have given up and tossed the book aside (gently, it's a library book). On page 4, they refer to the "counter device described earlier", but the only thing described earlier is a multiplexer (there's nothing else earlier in the book, this is the start of the book!). On page 5, it reprints a fragment of code from page 4 and says it's from the "architecture behave" code, but the code it is referring to is clearly "architecture dataflow". What a crock of shit (and it hasn't helped my opinion of VHDL any either, I might add, ugh). There does not appear to be any errata for this hunka-hunka-burning-turds. Let's try the other book I got from the library, sigh.

Second edit: I am now digging in to Peter J. Ashenden's book "The Student's Guide to VHDL", Second Edition, Morgan Kaufmann, ISBN 978-1-55860-865-8. I now know one of the reasons why VHDL has always seemed somehow wrong to me (while Verilog seemed a sensible approach in contrast). Quoting from the Preface: one pervasive theme running through the presentation of this book is that modeling a system using a hardware description language is essentially a software design exercise. And there you have it... VHDL became popular because it views hardware design as an exercise in software design. Since there are so many programmers in the world (thousands per hardware designer), it is a seductive statement that anyone who can write a program can design an integrated circuit. However, that is like saying that giving someone a Digital Audio Workstation (DAW) will allow them to effectively compose good music. Yeah, anyone using looping composition software can create something quite pleasing and often interesting, but it is not crafted in a way a trained composer or musician can do it. It is also much harder to innovate (music or hardware design) without deep training in the art in question. I find it interesting as well to note that there are thousands of folk musicians for every trained musician (I consider most rock, etc. kinds of folk music... and before you think I'm being snooty, I only do "folk" music myself in one form or another, and I have no pretentions about where my music fits into the spectrum of musical sophistication). I have done both serious hardware and software development (and I can do me a mess o' software... I've been programming complex and sometimes mission critical software for decades and I'm very good at it), but the two skillsets are radically different. Anyone with a VHDL compiler in one hand and an FPGA in the other can probably get something to work that'll do the job, but it is going to be sub-optimal in many potentially important ways (if not subtly buggy). This explains a lot of what I have seen lately with a number of ASICs, hmmm. The medium (VHDL) is the message.

I am starting to regret that I wasn't telling the truth when I said I'd keep lube by my side as I worked...
pheloniusfriar: (Default)
As anyone who knows me knows, I'm something of a bithead (kind of a gearhead too... probably a poohead, but I'll let you decide on that one). Earlier last year, I ordered in some Cypress PSoC 4200 development kits to experiment with. Why? Well, I was trying to get up to speed on modern FPGA development (still a work in progress), and my Verilog language skills were beyond rusty (I think I was fully in the “I'd forgotten more than I ever knew” territory by that point).

There are two very interesting things about the development kits I ordered: firstly, despite it being a very humble device, the PSoC 4200 has configurable digital functionality that can be programmed using Verilog (an extremely unique situation from my experience... as a note, the PSoC 4100 does not have these configurable digital blocks); and secondly, the full development kit, the CY8CKIT-049-42xx (follow the link to the page), costs a whopping $4US and includes a USB programming module, the processor on a PCB with prototyping connections, a button and LED and some support electronics for other available functions on the chip, and a full and innovative development software kit called PSoC Creator. I say "kits" because at $4... why not order a bunch to play with? The PSoC 4200 not only has a Cortex M0 ARM CPU (up to 48MHz, with nested interrupt controller, etc.) and the configurable digital logic (which they call Universal Digital Blocks or UDBs), but it also has configurable analog electronics (op amps, comparators, two low resolution current-mode IDACs, a 12-bit 1Msps ADC, a powerful multi-channel capacitive touch and proximity sensing module, and analog multiplexers that let you dynamically connect them to any I/O pin on the device), a nice handful of useful on-chip peripherals (timer/counter/PWMs; and Serial Communication Blocks that can be used for I2C, SPI, LIN, I2S, and other protocols), LCD driving capabilities, up to 32K of Flash and 4K of SRAM, and an epic Digital Systems Interconnect (DSI) fabric that can connect pretty much anything to anything on the chip. The one thing the PSoC 4200 doesn't have is a Direct Memory Access (DMA) controller, so interrupts and the CPU must be used instead (some of the members of the 4200 family have DMA, but not the one on this kit). Given that in the applications I've written so far that the CPU is pretty much in standby mode most of the time waiting for short interrupts to service, the lack of DMA has not been an issue in the slightest for me so far. I also wanted to say that the fact the development kit just needs to be plugged into a USB to be programmed (sadly, PSoC Creator only runs on Windoze, but I'm willing to dual boot to that OS from Linux to run it, it's just that spiff!), is both a brilliant marketing move and a show of technical prowess that can't be ignored.

I've already built an invention that I've been trying to get to for over a decade using one of these little development kits, and as the saying goes “I've used every part of the buffalo”... from the CPU to the programmable logic (UDBs using Verilog) and the configurable analog, to the on-chip peripherals (well, the PWMs, I didn't need a serial communications port) and just about all of the Flash for data (not much RAM was needed though). The last piece I'm working on is a proximity sensing capability that starts the invention up when someone gets close enough to it (don't worry, it's nothing malevolent, heh... it just saves the batteries and encourages its use). The capacitive touch/proximity sensing uses the analog multiplexing capability and the two IDACs, but I didn't really have much more than a loop of wire to play with and it didn't really behave as well as I had hoped. I've since ordered a development kit peripheral from Cypress that has a proper printed circuit board and such for testing out proximity sensing designs. I'll be playing with that over the next few months I think (I wish I could say weeks, but I know I'm going to be super busy with school starting Thursday... ugh... it's my last semester as an undergraduate though, so there is that at least). I am rather amazed at what I have been able to accomplish with just one really, really inexpensive PSoC chip! As a further note to anyone who has ever used an Arduino or its ilk... while the PSoC development software seems to be aimed at all levels of expertise (from the expert developer to the novice hobbyist), it has more of a learning cliff than a learning curve and it's the kind of thing that is very easy to learn if someone shows you how (maybe at a Maker Faire or meetup?) but hard to pick up on your own unless you know what you're doing. The effort is worth it, but plan to spend weeks learning how to wrangle the thing, not the days needed to master Arduino development. As a final note, the PSoC Creator development suite allows you to enter schematics of the hardware you want to use on the chip (it synthesizes it for you, so you don't need to know Verilog or anything like that), and you program the CPU in the C language (like on the Arduino, for instance). There are lots of online tutorial videos and example projects to get started with as well, but even I found it all a bit overwhelming given the flexibility and power of these little chips (the "hello world" of blinking an LED on the development kit is described in the setup and test instructions for the kit... you can read it by going to the link above and downloading the “CY8CKIT-049-4xxx PSoC 4 Prototyping Kit Guide”).

Anyhow, I am going to be keeping a journal of the work that I have been doing because I know how hard it was for me to pick up the subtleties that were needed to make a professional-grade product using the PSoC platform. Of particular interest for others is perhaps that I was able to use the PWM (Pulse-Width Modulation) capabilities of the PSoC to play back an audio clip from Flash memory: the PWM digital output's pulse width was modulated by the value of the digital audio sample, then that was fed into a 4th order Chebychev low pass filter (in a Sallen-Key configuration with a 4kHz cutoff frequency ... it gives roughly the same audio bandwidth as a telephone conversation) built using the on-chip op amps and a few off-chip resistors and capacitors, and then into a little audio amplifier I bought locally as a kit. Apparently it had not been done before with this particular chip or kit since I could find no hint of it anywhere on the Intertubes, so it is something that I will be describing in a future post (including a photo of the resistor/capacitor network that was my first prototype... a mess of a 3D sculpted mass of wires and parts if there ever was one... the final version is on a prototyping board and is a study in elegance by comparison). I also took a public workshop that taught me how to develop PSoC-based Bluetooth applications (some of their processors have that built-in as an option... their BLE technology), so that's kind of hanging in the wings as well as a thing to get around to. I am also working on an embedded network protocol and am again pushing the PSoC to its outermost limits of capability (deliberately, and as part of a much larger research project I am working on that might result in a fun little educational product). The past few days I took a step back from the larger project to try a bunch of experiments with the UDBs, clock routing, and CPU interrupts done in non-standard ways. I finally got that working and have some lovely blinking lights on my desk, and am one step closer to a really funky “zero additional components” embedded communications mesh. There are at least two real-time operating systems for the PSoC family (some take as little as 1K of Flash, it's mind blowing!), and I might try to wrap it as an inter-processor message-passing mechanism in one or more of those frameworks. Obviously, more to come on this, but I will be presenting my little sub-experiments because they show a lot of techniques that are not discussed anywhere from what I can see.

If you are interested, you can watch a bunch of training videos here:

http://www.cypress.com/training/free-online-video-training-and-tutorials-cypress

If you need a giggle about corporate types trying too hard to be hip, you can check out this video (although it does provide a good teaser on the development tools and capabilities):

Cypress: You dream it, we’ll help you make it

If you do not have epilepsy or a sensitivity to blinking lights, you can see the real thing here...



(some of the smaller text needs to freeze-framed, but it often quite funny... overall, I think it's a brilliant production! Full screen it if you can handle it...)
pheloniusfriar: (Default)
It has been a long and twisty road to get to this point — it was a journey that began almost 40 years ago when a nerdy young teenager read an advertisement in Radio Electronics magazine talking about the über cool (and surprisingly affordable) modular synthesizer gear made by this upstart company called PAiA Electronics. I sent away for the catalogue (which I still have in a box of keepsakes in the basement as I have grown up to be a nerdy old man). I drooled over the stuff in that booklet for years, but could neither afford to buy nor justify purchasing anything from them.

Years came and went, and during the 80s, analogue synthesizers and related equipment fell out of favour to most (not to me, but I was otherwise occupied at the time). Through the 90s, the limitations of digital technologies were slowly being charted out, and there was a revival of analogue electronics for certain tasks. In particular, it was the nearly unlimited flexibility of digital synthesizers that presented the problem: the capabilities exceeded the abilities of anyone to master. Another problem with digital synthesizers was, ironically, limitations with their interface and of control. With an analogue system, you could (had to, really) "tune" the experience in microscopic increments; but with a digital system, by necessity, there were only certain discrete values that you could set a control to, and that limited the possibilities for subtleties in the sound. The advantage of digital systems was (and remains) that once you had a setting you liked, you could call it back (presuming you were smart enough to have saved it...) at whim and it would be exactly like the last time you used it — exactly like the last time, and the next time. And that was another limitation of digital: life is change and a digital patch was static and unchaging... it mimicked life, but was not alive. Analogue synthesizers and equipment are never the same way twice and will generally even drift a bit during a single performance (like a guitar going out of tune as the humidity or temperature changes)... it really has a life of its own and that's where it is an instrument that can be part of a performance instead of being a computer that just cranks out a sound at command. I have a lot of digital equipment, and I love the heck out of it, but there is something to be said for having organic components (in the metaphorical as well as literal sense) in a performance.

In late August of 2014, I was finally able to "justify" the purchase of a piece of equipment I have wanted for a long time by the simple virtue that I had (barely) enough money to do so, and had decided unilaterally that I had displayed sufficiently notable restraint thus far — thirty-six years is a long time to wait, and enough was enough! I ordered a PAiA model 6710 Vocoder kit (with the optional front panel cutout, but no power supply... a detail that will become important later in the story). Last year was pretty much absolute hell for me and was a non-linear slide into full burnout by the end of it. I did a lot of really cool stuff related to physics and my academics, but my actual academics definitely suffered as a result and I ended up getting extremely ill in April and through much of May (picked up some nasty flu virus or something and it laid me flat for six weeks... might even have been viral pneumonia, but the doctors I saw never really figured out what was going on with me [but that was one wild-ass guess they made]... gave me antibiotics that did nothing, thus my supposition that it was viral whatever it was). I actually failed a critical class and I now don't know whether it's going to take me one year or two to finish my degree(s)... not a great feeling, but I'll make the best of it either way, just like I always do. All that to say that it should come as no surprise that I didn't finish assembling the kit until my break from school in December 2014. It was a pretty gnarly assembly job (there were so many wires!) but I only made one assembly mistake (a polarized capacitor put in backwards), and I caught it with a close visual inspection as part of the assembly process. Overall, it was good to be soldering stuff again, I truly enjoy doing that sort of thing with my hands!

Now remember that power supply thing I was mentioning earlier? Yeah... that. I have spent much of my life around electronics and power supplies and whatnot, so I didn't bother ordering PAiA's power supply kit. To be honest, I just don't like the looks of it with its wall barnacle and open board (and $50US price tag). I figured I would just go out and buy a nice little +/–15VDC power linear supply locally, or just pick up the parts and do it myself. Let me rephrase that, I mistakenly figured I would just buy one or the parts. A lot has changed since I last made a +/–15VDC power supply... like everything has changed and it's literally impossible to get the parts locally anymore to do that sort of thing. There are companies like Digikey that will ship components to Canada, and they are quite reasonably priced, so there was always that to fall back on (the shipping will kill you though... I remain convinced the package delivery service in Canada is run by the mob, or at least some sort of monopolistic, price fixing, conspiracy... when it's cheaper to ship something from Bangalore, India to here than from Toronto (Canada), you know there's a problem... but that's another story I guess). I went to one of the few remaining "electronics" stores in the city (Active Electronics) and discovered that they didn't really sell electronics anymore, or at least not any of the components I needed. What they did do was sell Arduino and Raspberry Pi boards and their ilk and related kits and shields (which they do very well, for what it's worth). I did manage to pick up a little hobby box from them though and decided that I would just recycle an old +/–15VDC power supply that I had designed and built many decades ago (if it still worked).

Well, that job took me forever to get to and even after I found it in my boxes and boxes of boxes of boxes in my basement, I just didn't have the energy or willpower to actually sit down and test it until sometime in May 2015. Long story short, it did work just fine still, and would fit nicely in the box I bought. Short story long? Anything by Dickens. The problems of moving forward and actually putting the power supply properly into the box were legion though, and involved many dozens of hours sorting through things in my basement to find the tools and parts I needed to complete the job. This is something I'm working on anyway, so the work is all part of a longer project, but it does mean that I was not ready to actually start the assembly of the power supply until about mid-June. Sigh. The good news is that most of my tools and bits of hardware are now in known locations to me instead of being spread around in dozens of hidey-holes and boxes and chests and cabinets and rooms. It still probably took me 40 hours of effort to actually machine the enclosure, wire and assemble the electronics into it, and finally test it... which is too long for a job like that, imho. Did you know that the LM7815's case is ground, but the LM7915's case is input so if you don't have thermally conductive but electrically insulative pads and hardware with which to mount them to the chassis for heat dissipation you short the output of the transformer to the electrical ground and fry everything? Uh, huh... I was wondering why I had used those pads on the original design... good thing I double checked and repeated the procedure, and triple checked with an ohm-meter before turning anything on (I'm pretty good, and very careful, at this stuff and most of what I build works the first time). I finally got it all together two days ago and solved one little stability issue with the negative supply output yesterday (all it needed was a 10µF tantalum capacitor on the output) and it was the most beautiful and quiet (from an electrical perspective) linear power supply you'll ever set eyes or oscilloscope on (very low electrical noise is critical for analogue electronics because any power supply noise will usually appear as a signal on its output... which is why I could not [or at least would not] just pick up a switching +/–15VDC power supply... they're just too noisy electrically).

Once the power supply was assembled and tested, I finally added power wires to the assembled vocoder and installed the integrated circuits into their sockets on it (I had kept them safe in a bag until I was ready to do the testing). It's funny how little techniques learned decades ago and not practiced in many, many years come back to mind. Here, in specific, I'm referring to the technique of pressing the sides of the integrated circuits onto a flat surface to bend the pins from the angle they are shipped with to the straight up and down position that is needed to insert them into sockets. I guess it's like falling off a bicycle: you never forget how. I powered on the vocoder and no smoke poured out of anything, so far so good! Since there are no indicators or anything on the unit, the only way to test it was to actually hook it up and give it a whirl. To get a good effect, you need a raspy/grumbly sound as the "instrument" and I hooked up the little Yamaha digital synthesizer I have (it has many, many preset sounds that would serve perfectly). I also got out one of my crappy microphones and hooked that in as the control signal (the power envelope of the control modulates the sound of the instrument being used, and that's how you get the "vocoder" effect). The output went into a little guitar amp I have and with a little tweaking of the knobs... it worked! I finally have my very own vocoder and I am very, very happy (and now I sound really cool too)!

Here's the assembled vocoder kit itself (ugly as sin inside with all those wires):

Picture of my assembled PAiA 6710 Vocoder kit

Here's the guts of the power supply I designed, built, redesigned, and rebuilt:

Picture of my custom assembled +/–15VDC power supply

And here's a photo of my test setup for the vocoder, it works like a charm!

Picture of my little test setup for the vocoder

I will be playing with it a little more today (and into the evening), but then it and all the related equipment, tools, parts, and such will be moved into the basement to wait for when I am ready to set it up in the recording studio space I'm setting up in the basement (that's part of that longer-term project I mentioned above). I am so looking forward to getting my dining room table back, and I know Beep and Happy can't wait to see my shit gone from there as well! Going forward, I will eventually have room in the basement to do this kind of work and won't need to repeat the "middle of the main living area workspace" experience again (or at least not as often or as drawn out timewise... but sometimes working on stuff in a social environment is better than putting away in a cave). Anyway, I'm off to make more cool noises and learn some of the techniques needed to get optimal and interesting sounds out of the thing (the one page operations description that came with the kit suggested a week or so of farting around with it should provide a sufficient basis to use it competently as a real instrument... the secret, apparently, is the sounds you feed it (both as instrument and control... using synth drums as control instead of voice was one thing suggested that sounds really, really cool), and learning how to play with the various levels to get the effect that's right for what you want). It also has an effects send/receive loop that I can use to add other effects on the control (e.g. my voice) to the mix, so I will be playing with that as well eventually.

Now, back to working on my differential equations homework (I have a test on Wednesday) and studying vocabulary words and grammar (last Thursday, I started my class on the Anishinaabewin [Eastern Ojibwe] language for beginners I'm taking as well this summer).

Profile

pheloniusfriar: (Default)
pheloniusfriar

May 2025

S M T W T F S
    123
45678 910
11121314151617
18192021222324
25262728293031

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 23rd, 2025 10:11 am
Powered by Dreamwidth Studios