PSoC 4 generating sine wave, output to speaker, need some help, please | Cypress Semiconductor
PSoC 4 generating sine wave, output to speaker, need some help, please
I'm trying to generate a simple sine wave on my CY8CKIT-049-42XX and output it to a 8 Ohm 0.5 Watt speaker.
I managed to produce a clean sine wave, but I'm failing to connect the speaker correctly and output any sound. So I'd appreciate any help with that.
A little background (to be skipped by the impatient): I'm a hobbyist, a (non-electronics) software developer by profession, with some digital/microcontroller experience (Atmel AVR, TI MSP430), but little analog knowledge - not much more than high school level physics). I recently discovered the Cypress psoc (4) platform and find the CY8CKIT-049-4XXX an amazing little development board. I want to get to know the psoc platform not only for electronics hobbyist reasons but also because I'm fascinated by the integrated design and programming approach of the PSoC Creator software, which is currently a hot topic in high-level (non-electronics) software development as well. I hope to pick up some good ideas for graphical software development and code generation for my day job.
Here's what I have so far. I roughly followed http://www.cypress.com/?docID=33597 ("Generate Sine Wave by LUT method in PSoC1") and http://www.cypress.com/?id=2401 ("Introduction to Interrupts for PSoC 4 Hardware Blocks"). I use an IDAC, a counter, and an ISR implemented in C that looks up sine values in a static array and writes them to the IDAC. I tried to do as much as possible in hardware as I believe this is the beauty of the psoc idea to be able to seamlessly mix powerful hardware blocks with only tiny bits of software "sugar".
Here's the schematic:
I deliberately chose not to use PWM on a digital output pin since I wanted to try out a DAC. I believe that on a psoc 4 there is no VDAC (correct me if I'm mistaken) so I'm deriving my sine voltage from an IDAC with an external resistor (I tried 4.7k and 10k) to GND. IDAC_1 is configured for positive polarity (source), 8-bit resolution, 0-612 uA (2.4 uA/bit) range. TCPWM_1 is configured for a period of 3125 (at 24 MHz clock) and interrupt at terminal count, which should give me roughly 120 Hz.
Here's the code:
This setup seems to be working, the waveform looks good to me on the scope:
although the voltage span seems too low, at least less than what I was expecting from my calculations:
Umax = 4.7 kOhm * 612 uA ~ 2.8 V
but I'm only seeing a little over 800mV (please correct me if I'm wrong, I'm a beginner with oscilloscopes as well). Any idea why?
Now the problem starts when I hook up an 8 Ohm 0.5 Watt speaker to the output pin 1 (configured for analog). As I said I don't know much about analog circuits, but I have learned that I should eliminate any DC current to the speaker by using a coupling capacitor in series (+ a series resistor to limit the current). So my breadboard setup looks like this:
There's no sound from the speaker, and when I look at the signal at the speaker with the scope it's a flat line. So I assume I'm doing something fundamentally wrong. Either the speaker's impedance is too low or the voltage level of my "makeshift VDAC" is too low. For the lack of better ideas and the experience building analog circuits, I tried a couple of variations, like omitting R_1 and/or R_2 and/or C_1, and even adding an Opamp (configured as follower) after the IDAC (I've tried both routing the output of the IDAC to the Opamp input internally and connecting IDAC and Opamp via the external pin 1/R_1), all to no avail.
I have also seen other approaches (for example https://sites.google.com/site/impedancetester/projectsummary) that construct a "virtual ground" at 2.5 V and use the IDAC in alternating positive (source) and negative (sink) modes so that the signal is all AC, swinging around 0V. I don't believe that's necessary to make my speaker work, is it?
Anyone out there with psoc analog output knowledge who can help me?
Thanks for bearing with such basic beginner's questions.