Showing posts with label Output. Show all posts
Showing posts with label Output. Show all posts

Thursday, 16 March 2017

Urg Negative Output from Positive Input Voltage


There are some applications, such as double-ended sensors and audio amplifiers that require a negative voltage for operation. With limited space on today’s system boards, creating a dedicated negative supply rail would add to the cost and space of the PCB. Hence, it makes sense to generate the required negative voltage from existing positive supply rails in the system.


One such solution using a traditional synchronous step-down regulator is provided by Texas Instruments in an application note entitled “Creating an Inverting Power Supply Using a Synchronous Step-Down Regulator”1. It shows you how to generate a negative voltage from a positive input voltage to the synchronous buck regulator. [ ]

Readmore → Urg Negative Output from Positive Input Voltage

Saturday, 4 March 2017

PIC32 DMA SPI DAC Analog output synthesis with zero CPU overhead


I have previously shown how to use the PIC32 SPI module to use the 12-bit DAC MCP4822: http://www.blogspot.com/2016/10/pic32-spi-using-mcp4822-12-bit-serial.html. While that does allow you to generate analog outputs as desired, it requires you to use CPU cycles to process the timer interrupt and accordingly drive the SPI module.

Since the PIC32 contains DMA channels, the process can be completely offloaded from the CPU. For an idea of the PIC32 DMA module, refer to my previously written article: http://www.blogspot.com/2016/05/simple-pic32-dma-example.html

Fig. 1 - The generated sine wave at fpwm = 400kHz and 32 elements in the sine table

So, the simple way of offloading the SPI update to the DMA module would be to let the DMA channel transfer data to the SPI buffer. The SPI module is configured for 16-bit data transfer (since the MCP4822 write command requires 2 bytes). This means that the cell size for the DMA channel has been set to 2 (2 bytes to transfer once triggered). The DMA transfer is triggered by a timer interrupt. Unlike the previous example where I used Timer 1 and its interrupt for the SPI transfer, here I use Timer 2. The reason for this is that, if I want the entire process to be offloaded from the CPU, the SS (Slave Select) or CS (Chip Select) also has to be done entirely in hardware. For that I used the Output Compare 1 module. To use the OC1 module, either Timer 2 or Timer 3 (or the combined 32-bit timer) has to be used. So, I just went with Timer 2.

Configuring the DMA module for transferring data to the SPI buffer was the simple part. I found the configuration of the SS/CS pin the more challenging part. The idea here was to use the OC module in "dual compare mode continuous output pulses" mode. The OC module in this mode generates continuous pulses - the output pin OC1 - which I used as CS/SS - is set high one PBCLK (peripheral bus clock) after the Timer value reaches OC1R; the OC1 pin is cleared one PBCLK after the Timer value reaches OC1RS. Since SS/CS is active low, I set ( (period register) - 4) to be OC1RS and a variable CSlength to be OC1R. CSlength was chosen to be 80% of the period register. What this meant was that. One PBCLK after the Timer reached the (period register - 4), the OC1 pin went low (CS/SS went low) "selecting" the DAC. After about 0.80*(period register) from there, the OC1 pin went high. This means that the CS pin is low for 80% of the period - it goes low a small time right before the DMA transfer happens and is raised high late enough, after the DMA transfer occurs. I determined that 80% the period was enough time since that is higher than the time required to shift out 16 bits of data at 20MHz SPI clock. See Fig. 2 below for an illustration of the operation of the output compare module in the "dual compare mode continuous output pulses" mode:

 Fig. 2 - Output Compare module in Dual Compare Mode: Continuous Output Pulse mode (taken from PIC32 reference manual, figure 16-16)

Beyond that, the idea is simple. There is a sine table that is the DMA source. The key thing to remember here is that the 12-bit data must be OR-ed with 0x3000 since that is required for the DAC (to set gain=1, shutdown = 0 and channel = A):

void generateTables(void){
    uint8_t i;
    for (i = 0; i<TABLE_SIZE; i++){
        sineTable[i] = (short) (2047.0 * sin(6.2832*((float)i)/(float)TABLE_SIZE));
        sineTable[i] = sineTable[i] + 2047;

        sineTable[i] = 0x3000 | sineTable[i];
    }
}

Since the entries in the sine table are of "short" data type (each element occupies two bytes), the source size (in bytes) is twice the number of elements. The destination source size is two bytes since I'm transferring two bytes to the SPI buffer register. The cell size is two bytes since the DMA channel has to transfer two bytes (16 bits) at a time to the SPI buffer register. The DMA configuration is:

    DmaChnOpen(0, 3, DMA_OPEN_AUTO);
    // (ch, ch priority, mode)
    DmaChnSetTxfer(0, sineTable, &SPI1BUF, TABLE_SIZE*2, 2, 2);
    // (ch, start virtual addr, dest virtual addr, source size, dest size, cell size)
    DmaChnSetEventControl(0, DMA_EV_START_IRQ(_TIMER_2_IRQ));
    // (ch, trigger irq)
    DmaChnEnable(0);

A point of note is that, the DmaChnSetTxfer( ) takes in the virtual addresses of the source and destination, not the physical addresses. The virtual-to-physical address conversion is done by the function itself as opposed to it being required manually when doing register level operations (as done in my previous DMA example article).

To demonstrate that the DAC control is done with no CPU overhead, in the main( ) function, I have an infinite loop that is just toggling RA0. The output is checked on an oscilloscope:

Fig. 3 - RA0 toggle being demonstrated

Observe that the frequency of the square wave is 4.0MHz - the same that would be observed if all the PIC was doing was the pin toggling.

This also gave better performance than my previous experiment where I did not use DMA. The output sine wave has a higher frequency than observed before and this matches exactly as expected: 400kHz/32 = 12.5kHz as seen (see Fig. 1).

The rest should be very easy to understand and self-explanatory. If you have any questions or suggestions, feel free to comment!

Here are the source and header files:
config.h: https://drive.google.com/file/d/0B4SoPFPRNziHcmlxMmg2Si0zWjQ/view?usp=sharing
main.c: https://drive.google.com/file/d/0B4SoPFPRNziHcmlxMmg2Si0zWjQ/view?usp=sharing
Readmore → PIC32 DMA SPI DAC Analog output synthesis with zero CPU overhead

Monday, 12 December 2016

STK4050 Audio Amplifier with 200W Output


The project is based around the hybrid integrated circuit STK4050 manufactured by Sanyo to build a low noise mono audio amplifier with complete high quality. The project has a maximum output power of 200W while incorporating a volume control. The power supply used in the circuit is an on-board type and because of this, only a center tapped transformer is needed for the powering of the circuit. The sound has a very good quality and it can be proven when used in home theaters, in computers, and other audio equipments which can also be used as subwoofer amplifier. For thin-type audio sets, it can be considered as a compact package.

STK4050 Audio Amplifier with 200W Output

The heat generated in thin-type audio sets is being dispersed easily with a good heatsink design. There may be case where a shock noise may be encountered especially during switch ON and switch OFF. This can be reduced by providing a constant current circuit. The design of the circuit can be tailored for reducing occurrence of thermal shutdown, short circuit protection for loads, shock noise muting from external power supply. The load resistance should have 8 Ohms value with 55K Ohms input impedance.

Readmore → STK4050 Audio Amplifier with 200W Output

Saturday, 26 November 2016

Symmetric Output for USB Audio DAC


This simple adapter circuit is specially intended for use with the USB Audio DAC published in this website elsewhere. With an easily implemented modification, it is possible to make the output of the D/A converter pseudo-symmetric, so that it can be connected to professional equipment having XLR line inputs. This will do even more justice to the high quality of the USB Audio DAC. The modification actually amounts to just adding a single resistor (R11a) and changing the value of the existing resistor at the output of the audio DAC (R11) from 100 Ωto 68Ω. Components C14 and R12 remain unchanged. It is not difficult to make this change on the printed circuit board of the audio DAC, but a bit of improvisation is necessary. After replacing R11 with a 68-Ω version, unsolder R12 and connect R11a in series with it. Bring out the junction of these two resistors to act as the signal return connection (pin 3 of the XLR socket). The same operation must also be carried out on the right channel, where the affected resistors are labelled R16, R16a and R17.



Readmore → Symmetric Output for USB Audio DAC