You are here

Tips - A Safe Alternative to Schematic Copy-Paste | Cypress Semiconductor

Tips - A Safe Alternative to Schematic Copy-Paste

One of the really nice features of the PSoC Creator schematic editor is the ability to copy-paste parts of the design to replicate functionality. When you copy a component instance all the parameter settings come along for the ride and so you can set things up once and use the metaphorical cookie-cutter as often as you like. The tool even renames everything to avoid name space collisions. It is a feature I use all the time.

Copy-and-paste components

Until it goes wrong. This happens when I decide that I need to change a parameter and start making the edits in copied components. Then someone roams up to my desk and asks a difficult question (such as "ready for lunch?"). One extra-large burrito and a bucket of chips later I have forgotten which components I had edited and the whole system stops working! As a result this I always look for alternatives to making multiple copies of components and a hobby project of mine illustrates a good example of how to do that.

When not eating burritos or writing articles for the PSoC Creator Start Page I often play with a PSoC-powered robot car. I can drive it from my phone because it has a Bluetooth module on-board, and I can set it up as either an automated line follower or maze solver. It happens to be the fastest line follower in the company by the way but that is probably more an indication of my lack of article writing than my skills as an embedded programmer. Anyway… the front of the car has a row of 5 reflectance sensors, connected to PSoC pins, that I use to detect the presence and position of the car relative to a line on the floor. The photodiodes are always powered on and the resistance of the phototransistor side varies according to the reflectance of the surface it is facing. By repeatedly charging up a capacitor and timing how long it takes to decay through the transistor I can detect a black line on a white surface (or vice versa). And it is 100% digital so I am not being forced into the kind of mathematical gymnastics I abandoned a long time ago!

Here is a picture of the circuit to handle one sensor. I am using a 2-output PWM to drive the pin's output enable terminal high, which charges up the capacitor (cap_charge). Then I disable the output and wait a "while" for it to decay. A second pulse (sensor_sample) copies the state of the pin through a flip-flop into a status register. I can read the register at any time and the flip-flop ensures the data is always good.

PWM driving a reflectance sensor

As you can imagine, making 5 copies of this circuit is dangerous. In my time I have messed up the PWM frequencies, the drive modes and initial states of the pins, the reset state of the flip-flop and, well, pretty much everything else! Here is a part of the full design showing just two of the five sensors.

Snapshot of 5-sensor design

While this design works fine, every time I edit it I manage to make a mistake. The wiring between the PWM and the status register gets complex and it is easy to make a parameter change in some, but not all, components. The fix is to use just one PWM for all the pins (pretty obvious I know) and use the other component's "size" parameter. Starting with the pin, you open the parameter editor dialog and set the "Number of pins" to 5 and, on the Mapping tab, select "Display as bus". The wire from the component becomes thick to indicate that it is a 5-bit bus rather than just a single wire. Notice how there is is just one Output Enable terminal so I can control all the pins with one PWM signal. Then you do basically the same thing with the flip-flop and the status register - give them a size of 5 and display their terminals as buses.

Driving five sensors with single components for the pins, flip-flops and status register

Et voila! Using buses allows me to compress the whole design into the minimum number of components and wiring. Best of all I can make parameter changes to all pins with just a single edit. I have a 5-sensor implementation that helps make my car super-fast but is barely more complex than the single sensor version. Best of all, it is really easy to maintain, regardless of all my burrito-fueled distractions!

Blog: 

Comments

335643789_1905541's picture

Hi, I bought a CY8CKIT-002 PSoc MiniProg3 Program and Debug Kit and want to ask questions about CY8CKIT-002 PSoc miniProg3 programmer. You know about it whether there were any API or SDK development kit? I can use them on the Mac OSX.

본 사이트의 모든 컨텐츠와 자료는 "있는 그대로" 제공됩니다. CYPRESS SEMICONDUCTOR와 해당 공급자는 그 목적에 관계 없이 이러한 자료의 적합성에 대한 표현을 하지 않으며 상업성, 특정 목적에의 적합성, 권리 및 제3자 지적 재산권의 비침해에 대한 모든 묵시적 보증과 조건을 포함하여(이에 제한되지 않음) 이러한 자료와 관련한 모든 보증과 조건을 부인합니다. CYPRESS SEMICONDUCTOR에서는 명시적 또는 묵시적으로 금반언이나 여타의 다른 방법으로 라이센스를 부여하지 않습니다. 이 사이트의 정보를 사용하려면 제3자의 라이센스 또는 CYPRESS SEMICONDUCTOR에서 제공하는 라이센스가 필요할 수 있습니다.

이 사이트의 컨텐츠에는 특정 사용 지침이나 제한이 포함되거나 그러한 제한이 적용될 수 있습니다. 모든 게시물과 이 사이트 컨텐츠 사용에는 사이트 약관이 적용됩니다. 이 컨텐츠를 사용하는 제3자는 제한 또는 지침을 따르고 이 사이트의 약관을 준수할 것이라는 데 동의합니다. Cypress Semiconductor와 그 공급자는 컨텐츠와 자료, 그 제품, 프로그램 및 서비스를 언제든 수정, 삭제, 개조, 개선, 향상 및 기타 변경하거나 예고 없이 컨텐츠, 제품, 프로그램 또는 서비스를 이동 또는 중단할 수 있는 권리를 보유합니다.