Skip to content

Commit a72cfc3

Browse files
committed
Fixed analogWrite() when writing on both DACs. Thanks to smay4finger
for providing the patch. http://code.google.com/p/arduino/issues/detail?id=1092 http://arduino.cc/forum/index.php/topic,129765.msg980913.html
1 parent 0f23634 commit a72cfc3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

hardware/arduino/sam/cores/arduino/wiring_analog.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
206206
EAnalogChannel channel = g_APinDescription[ulPin].ulADCChannelNumber;
207207
if (channel == DA0 || channel == DA1) {
208208
uint32_t chDACC = ((channel == DA0) ? 0 : 1);
209-
if ((dacc_get_channel_status(DACC_INTERFACE) & (1 << chDACC)) == 0) {
209+
if (dacc_get_channel_status(DACC_INTERFACE) == 0) {
210210
/* Enable clock for DACC_INTERFACE */
211211
pmc_enable_periph_clk(DACC_INTERFACE_ID);
212212

@@ -228,20 +228,22 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
228228
*/
229229
dacc_set_timing(DACC_INTERFACE, 0x08, 0, 0x10);
230230

231-
/* Disable TAG and select output channel chDACC */
232-
dacc_set_channel_selection(DACC_INTERFACE, chDACC);
233-
234-
/* Enable output channel chDACC */
235-
dacc_enable_channel(DACC_INTERFACE, chDACC);
236-
237231
/* Set up analog current */
238232
dacc_set_analog_control(DACC_INTERFACE, DACC_ACR_IBCTLCH0(0x02) |
239233
DACC_ACR_IBCTLCH1(0x02) |
240234
DACC_ACR_IBCTLDACCORE(0x01));
241235
}
242236

237+
/* Disable TAG and select output channel chDACC */
238+
dacc_set_channel_selection(DACC_INTERFACE, chDACC);
239+
240+
if ((dacc_get_channel_status(DACC_INTERFACE) & (1 << chDACC)) == 0) {
241+
dacc_enable_channel(DACC_INTERFACE, chDACC);
242+
}
243+
243244
// Write user value
244245
ulValue = mapResolution(ulValue, _writeResolution, DACC_RESOLUTION);
246+
while ((dacc_get_interrupt_status(DACC_INTERFACE) & DACC_ISR_TXRDY) == 0);
245247
dacc_write_conversion_data(DACC_INTERFACE, ulValue);
246248
return;
247249
}

0 commit comments

Comments
 (0)