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

Thread: teensy3.6 frezzes qhen acessing the dac registers

Hybrid View

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    1

    teensy3.6 frezzes qhen acessing the dac registers

    I'm trying to code the DACs in the Teensy 3.6 to a synthesizer.

    The problem is that when I write in any of the registers to control the DAC module, the Teensy just stops responding!

    Does anyone know if it is needed to initialize something before accessing the registers?

    The example code is below:
    Code:
    void setDACPos(byte pos){ DAC0_C2 = (pos << 4 )| 15 ; } generateDacBuffer(); void setup() { DAC0_DAT0L = 0; Serial.println("asdasd"); generateDacBuffer(); setDACPos(0); DAC0_C1 = 1 | 1 <<6; DAC0_C0 = 1<<6 | 1 << 5 | 1 << 4; } int counter = 0; void loop() { setDACPos(counter); // selects the value to output from the buffer at counter position counter++; if(counter == 16){ counter = 0; } delay (1000); } void generateDacBuffer(){ short deltaValue = 100; short startValue= 200; short* regs =(short*) 0x400CC000; // adress to the first buffer register = DAC0_DAT0L // also craches if i use variable DAC0_DAT0L short value = startValue; for(int i = 0; i < 16; i++){ // crashes below *regs = holder;// also craches if i use variable DAC0_DAT0L . example : DAC0_DAT0L = 255; value += deltaValue; regs++; } }
    Thancks in advance
    Last edited by Frank B; 02-13-2021 at 12:36 PM. Reason: Added [code] [/code]tags

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,288
    Quote Originally Posted by wonderways View Post
    I'm trying to code the DACs in the Teensy 3.6 to a synthesizer.
    Why don't you use the audio library?

    As with almost all periphals, you need to enable it before use:
    Code:
        SIM_SCGC2 |= SIM_SCGC2_DAC0;
    

    Some code is here:
    https://github.com/PaulStoffregen/Au...output_dac.cpp

  3. #3
    Quote Originally Posted by wonderways View Post
    Does anyone know if it is needed to initialize something before accessing the registers?
    Pretty much every I/O module has clock control that must be enabled before using that module. Those bits are in the SIM_SCGCx registers. The DAC also has to be initialized with things like your choice of Vref.

Posting Permissions

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