热度 19
2014-11-12 16:55
2626 次阅读|
0 个评论
In my previous blog , I briefly tackled the Programmable System-on-Chip (PSoC) devices from Cypress Semiconductor. The PSoC devices offer varying amounts of programmable analog and programmable digital fabric and memory. Members of the PSoC 1 family also include Cypress's proprietary 8-bit M8C processor core; members of the PSoC 3 family include an 8-bit 8051 core; members of the PSoC 4 family include a 32-bit ARM Cortex-M0 core; and members of the PSoC 5 family boast a 32-bit ARM Cortex-M3 core. For my current project, I decided that a PSoC 4 would be able to offer all the capabilities and functions I require. With the aid of the PSoC 4 Pioneer Kit (Arduino shield compatible), I quickly established that the PSoC 4200 would meet my needs. Since this project was a rush job, I quickly committed to a PCB so that it could be produced in parallel with the rest of the development. For maximum configurability, PSoC devices contain reconfigurable logic blocks called Universal Digital Blocks (UDBs). The PSoC 5 has up to 24 of these UDBs while the PSoC 4200 has 4 (the PSoC 4100 has none). In the PSoC 4, some of these UDBs are replaced with components that are not as configurable. In some cases, the I/O pins are proscribed, nudging this approach closer to a normal microcontroller. When comparing the PSoC 4 to the PSoC 5, in addition to the differences between the ARM Cortex M0 and M3, there are also differences with regards to the clock frequency, Flash, SRAM, and the speed of the peripherals like the ADC (analog-to-digital converter). As a starting point for my project, I required a two-channel ADC. You can see its placement on the device schematic in Figure 1. Figure 1. The ADC component has been placed and the input pins named and attached. Part of the configuration of the ADC options is shown here. My initial thought was that the IP block for the ADC on the PSoC 4 would be nominally the same as on the PSoC 5 (which I used for a previous project), but this was not the case. Cypress has rethought this and created the ADC block with quite a few nice touches. Even though there is only one ADC, it can be configured with up to four differential channels that will automatically sequence through their conversions (you can set delays on each conversion). Furthermore, you can build in averaging automatically, thereby saving you writing the code. Other IP components in the device show a similar flair. In order to drive my bi-colored LEDs (as discussed in my previous blog) I needed a PWM controller, but I wanted to use a single PWM for both the red and green since I wasn't varying the shade of orange. I added a few logic gates as illustrated in Figure 2, and I had the functionality that I was looking for. You can't do that on many micros! Figure 2. The output of the PWM is conditioned by the addition of two AND gates and a control register so that I can have blank, red, green, or orange, with the brightness being controlled by the PWM ratio. The second bi-color LED has another PWM controller configured in exactly the same way. After I had realized this approach, I was looking at the different components (in the form of IP configurations) and came across a device called a PrISM (Precision Illumination Signal Modulation) which had two PWM outputs and the ability to independently control them, which is pretty much had what I had set up. It also has a pseudo random PWM variation to reduce EMI noise. Unfortunately, this is where I bumped into having laid out the PCB beforehand. There weren't enough resources to allow me to use the PriSM and the SPI controller and some other components that I had selected. If I had laid out the PCB for the fixed output pin version of the SPI, everything would have been fine. It would have been nice to use the PrISM, but not using it wasn't a show-stopper. Amongst the multitude of "components" that are provided, there is also a switch de-bouncer, which makes coding and debugging even easier. There are also gates, flip-flops, counters, timers, quadrature decoders, and registers to name but a few, as well as the "CapSense" touch button ability. An additional benefit is that you can bring out the internal nets by wiring them to unused pins, and I would say that making sure you keep a couple of pins free is good design practice when using a PSoC. On the downside, I am not impressed with the watchdog timer and there are some elements of the development environment that irritate me. I have worked with many different emulators and there are some aspects to this one that seem a little petty. I can live with only four hardware breakpoints (I think it used to be three -- it looks like they have added one), but what really irritates me is that when the process hits a breakpoint, you have to clear that breakpoint to continue. Apparently this is because if you have a pending interrupt -- and who doesn't have a tick interrupt? -- the next instruction executed will be in the interrupt routine, after which it will return to the breakpoint and stop, so you never progress. Let me explain this a little more. Assume you hit the breakpoint and you haven't quite figured out what the problem is. You want the program to run through the "loop" and then break at the same point, but you have to clear the breakpoint to continue. The only way round this is to set a new breakpoint an instruction or two later in the code, turn off the current breakpoint, run to the new breakpoint, renew the original breakpoint, turn off the temporary breakpoint, and then continue. This is time-consuming and mouse-intensive. Single-stepping has much the same issue and I hardly use it. No other emulator that I have used has this problem, but then those also stop the clock to the peripherals, so no interrupt would occur anyway.The emulator also seems to have a bug that it locks up in some circumstances. I am told that the latest version, Creator 3.0SP1, solves this. And I have a word of general caution for all compiler users. The Keil compiler uses the paradigm of a debug and release mode when it comes to the output .hex file. Unfortunately, the two results don't have the same optimization settings. I had coded a bit-banging SPI to use with a test jig and it worked fine when I was debugging, but in the "release" version it would not work. It turned out the compiler had optimized away the dummy memory accesses (like cDummy++;) that I had used for set up delay and the like, and possibly even the bit toggles. The end result was that 24 clock pulses were merged into a single clock pulse and, of course, the receiving shift register did not work. Once I had adjusted some of the optimization settings, the problem was resolved. Figure 3. The finished product. There are also two SOIC8s and a few resistors on the underside. Working with a PSoC, you can really configure everything to your heart's content. This is great fun, which is why I like to work with these parts. If there is a problem, you can change your approach in a flash (pun unintended) without changing the PCB. My final configuration for this project has two PWMs (with additional gating), a dual-channel, single-ended 12-bit ADC (with scanning and averaging), four de-bounced inputs, an SPI master, and two op-amps. Just so you know, I have no affiliation whatsoever with Cypress Semiconductor -- I just like using their PSoCs. How about you -- have you used these devices, or are you thinking about doing so? If you are interested in discovering more, you might want to take a look at the PSoC 4 CY8CKIT-049 4xxx Prototyping Kits, which are an amazing bargain at only $4 each. Aubrey Kagan is engineering Manager at Emphatec .