I thought building a “code learner" for infrared remote controls is an easy job; well, it is not. I started by constructing a code learner function in my brainwave appliance controller project that I built using the PSoC5LP as I described in my previous blog post. That project uses a PSoC5LP on a Schmartboard, which is a small evaluation board very self-contained, comes with a boot loader application, and has almost all I/O pins routed to connectors. I really like that board. But while that Schmartboard is very attractive for an application that works, it did not prove very useful to my application that did not work. Yes, the lack of visibility of what happens inside PSoC5LP during program execution and the lack of a debugging access made all my tentative attempts to troubleshoot my program very difficult. So after a few iterations of program "blind" troubleshooting I realized that continuing to work with this Schmartboard only prolongs the misery. So I decided to develop the infrared remote code learner on a Cypress CY8CKIT-001 evaluation kit and when I am confident that the program works to port it on the Schmartboard. The Cypress evaluation kit is absolutely awesome. It includes a motherboard and three modules, one with a PSoC1 chip, one with a PSoC3 chip, and one with a PSoC5LP chip, and it came also with a MiniProg3 programmer and debugger. But what I like the most is the LCD display has two rows of 16 characters each. I can use this display to "communicate" with my program running in the PSoC5LP chip, so as the program reaches various points in execution it displays specific messages on this LCD screen.
My first step was to get familiar with how to use this CY8CKIT-001 kit, and I started with the getting started document and the user guide. These documents and the code examples that came on the disk made me put together a short program and load it into the PSoC5LP in less than 30 minutes. This perhaps is not such an accomplishment for most of you, but it definitely was a good accomplishment for me since I do not have a background in digital design. Next I started to use the debugger; I have some debugging experience from previous software programming I've done in Visual Basic, but also I do not have a software background either, so I was a little scared of using the debugger.
Learning how to use the debugger went smoothly since it looks very similar to the debugger I used in Visual Basic. I am impressed how the debugger actually controls the program execution inside the PSoC5LP and reads back the values of variables and registers. This is an awesome tool that really helps in troubleshooting the code.
After getting familiar with the Cypress evaluation kit I resumed my work on the brainwaves appliance controller. I connected the infrared sensor to one of the pins of the PSoC5LP kit and on the little breadboard I constructed a push button that pulls high to 3.3V another pin, as I am showing in the figure below.
On the left side of the PCB there are two infrared sensors, one with a decoder, which I connected to an oscilloscope and I use for reference, and one that provides the raw signal including the carrier, which I connected to PSoC5LP. When I push the button the program enters into code learning mode. In this mode I need to implement two functions: 1. Measure the infrared carrier frequency and 2. Decode the infrared signal into a sequence of logic high and logic low pulses and to store that information. So far I was able to make the first function work. Here is the schematic of the blocks inside PSoC5LP.
The infrared transmitted signal starts with a preamble square wave signal at the carrier frequency. I take this signal through pin 2 and I divide it by 4 in order to average four periods and increase the accuracy of my measurement. There are at least six pulses of the preamble signal over all infrared transmission protocols that I saw so far, so I am safe to average the first four. I then use the rising edge of the divided signal to trigger a counter that runs at a bus speed of 24MHz and the falling edge to capture the count value. The counter starts from a predefined value of 35535 and decrements it on each rising edge of the 24MHZ clock. On the falling edge of the measured signal I set the counter on sleep mode and I read the count value. I then subtract this count value from the starting value and I compute the frequency of the infrared carrier signal.
Here is an example of how it works: (I press the push button to enable the learning mode and then I point the infrared remote control to the sensor and I press a button; the program inside PsoC5LP computes the carrier frequency and displays it on the screen)
So I made my program able to determine the carrier frequency. My next task is to decode the signal and store the information. This is what I will be working on now and I will come back with an update as I get more work done. Until then all my best wishes to all of you.