2015-11-12 11:21 AM
I am generating music using STM32L152RC.
I have DAC configured the same for both channels DAC_OUT1/2 using PA4/PA5.RCC->APB1ENR |= RCC_APB1ENR_DACEN;
// Enable DAC
RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
// enable GPIOA
// PA4/5 Analog
GPIOA->MODER |= 0x00000F00;
// Enable DAC channel1 output buffer
DAC->CR &= ~(DAC_CR_BOFF1 | DAC_CR_BOFF2);
// Select TIM4 TRGO as trigger
DAC->CR |= (DAC_CR_TEN1 | DAC_CR_TEN2);
// Enable DAC channel 1 & 2 Trigger
DAC->CR &= ~(DAC_CR_TSEL1 | DAC_CR_TSEL2);
DAC->CR |= (DAC_CR_TSEL1_2 | DAC_CR_TSEL1_0);
// 101 = TIM4_TRGO
DAC->CR |= (DAC_CR_TSEL2_2 | DAC_CR_TSEL2_0);
// 101 = TIM4_TRGO
// Enable DAC
DAC->CR |= (DAC_CR_EN1 | DAC_CR_EN2);
// DAC channel 1 & 2 enable
I write to the DAC thus:
static
uint32_t ch2out, ch1out;
............
ch2out = (y << 16);
ch1out = (y);
DAC->DHR12RD = ch2out | ch1out;
............
So here's the problem. When I connect PA5 to my speaker setup (an LM386 opamp), it sounds exactly as expected.
But when I disconnect PA5 and connect PA4 to the same exact setup, changing nothing else, the output is inaudible.
From the code, you can see that PA4/PA5 , DAC_OUT1/DAC_OUT2 are configured exactly the same, and exactly the same signal is being written to each channel.
When I disconnect both PA4/5 from the circuit and used an oscilloscope with my code running, they both show exactly the same output. Yet somehow connecting PA4 to an actual circuit is not working. Also, I tried the program on a second board, and got the same results.
I'm not really sure what to make of it. How are PA4 and PA5 different? What am I missing?
2015-11-12 09:40 PM
And when the amplifier is connected to PA4, what does the oscilloscope show?
JW2015-11-13 11:26 AM
The waveform is the same as before.
2015-11-13 01:55 PM
If the output waveform of one channel is the same as of the other channel, when you connect the amplifier, then you didn't actually connect the amplifier. Follow the wires with the oscilloscope up to the very end, i.e. the speaker; compare wafeforms to the case when connected to the other channel.
JW