Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

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

  1. #1
    Junior Member
    Join Date
    Jan 2018
    Posts
    11

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

    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!

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,914
    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)

  3. #3
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,997
    jajanizer did not write that he was using the audio library, that’s why I refrained from replying exactly that...

  4. #4
    Junior Member
    Join Date
    Jan 2018
    Posts
    11
    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?

  5. #5
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    1,997
    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.

  6. #6
    Junior Member
    Join Date
    Jan 2018
    Posts
    11
    Wow, that's embarrassing. Thank you

    At least, I'm happy it was simple silliness on my part and not a broken teensy!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •