Teensy 3.6: using analogWrite() on second DAC while other is triggered by DMA

Status
Not open for further replies.

jajanizer

Member
Hi all,

A (hopefully) quick question. I have my 3.6 outputting signals from DAC0 (pin A21), coming from the DMA buffer and being triggered by the PDB. This is working fine, but when I try to use a simple analogWrite() to output something from DAC1 (pin A22), nothing happens (voltage stays fixed at 1.2V). I was wondering if anyone knew offhand if there was some sort of conflict between the two, due maybe to the DMA(?). Or, have I fried the pin somehow? I couldn't find any references to the two output methods being mutually exclusive.

Thanks! :)
 
you cannot use audio library and analogRead/Write at the same time. (I recall it is written on the right side of the audio GUI)
 
Yeah, indeed I'm not using the audio library. I set up the DAC0 and DMA with the PDB based on examples I found in other threads here:
Code:
dma.begin(true); //allocate dma channel
  SIM_SCGC2 |= SIM_SCGC2_DAC0; // enable DAC clock
  DAC0_C0 = DAC_C0_DACEN | DAC_C0_DACRFS; // enable the DAC module, 3.3V reference
  // slowly ramp up to DC voltage, approx 1/4 second
  for (int16_t i=0; i<2048; i+=8) {
    *(int16_t *)&(DAC0_DAT0L) = i;
    delay(1);
  }

  // set the programmable delay block to trigger DMA requests
  SIM_SCGC6 |= SIM_SCGC6_PDB; // enable PDB clock
  PDB0_IDLY = 0; // interrupt delay register
  //PDB0_MOD = PDB_PERIOD; // modulus register, sets period
  PDB0_MOD = 14;
  PDB0_SC = PDB_CONFIG | PDB_SC_LDOK; // load registers from buffers
  PDB0_SC = PDB_CONFIG | PDB_SC_SWTRIG; // reset and restart
  PDB0_CH0C1 = 0x0101; // channel n control register?

  dma.sourceBuffer(table, sizeof(table));
  dma.destination(*(volatile uint16_t *)&(DAC0_DAT0L));
  dma.triggerAtHardwareEvent(DMAMUX_SOURCE_PDB);

  dma.enable();

and then tried to use the second DAC channel as follows:

Code:
analogWrite(dcoutput, A22);

Which I thought should work fine?
 
First, your Syntax is wrong, it should be analogWrite(pin, val)

Try with analogWrite(A22, dcoutput) which definitively should work. Afterwards you owe $5 to the "I didn't study thoroughly the documentation and reference" piggy bank.
 
Wow, that's embarrassing. Thank you :)

At least, I'm happy it was simple silliness on my part and not a broken teensy!
 
Status
Not open for further replies.
Back
Top