contraption

Members
  • Content Count

    2
  • Joined

  • Last visited

  1. Awesome, MODE1 worked! Thanks. That'll teach me that code I find on the internet isn't always correct! (example used MODE3)
  2. Hi, I've been trying to get the PMOD DA2 (just Channel 1 for now) working on a fleet of Arduino Leonardos via the ICSP header. I'm getting bizarre (jumpy, non-monotonic) voltages out of it and I'm stumped. Things get particularly squirrely around outputting 2048 counts (half scale) - I do believe that my upper/lower byte math is correct, so i think the issue is with the SPI writing/sequencing. Has anyone had any luck putting a DA2 on a Leonardo via ICSP? I've attached my (not working) test sketch. Any idea what's wrong? I poked around the web and this forum, but can't seem to find any working examples or advice. This is my first attempt at using the ICSP port, so it's possible that I've not done it properly. For a moment I did think that specifically defining MSBFIRST would fix it, but it didn't. I'm also not 100% sure about the clock phase and polarity settings (SPI_MODE3) - what you see in the code is from an example that I found (here: https://www.hackster.io/56141/using-the-pmod-da2-with-arduino-uno-e47768 - but that doesn't seem to work for me either). /************************************************************************ * FILENAME: PMOD_DA2 * * Leonardo Pins: * * Chip Select (CS): Leonardo DIO Pin 10 (to DA2 pin 1) * Serial Clock (SCK): Leonardo ICSP Pin 3 (to DA2 pin 4) * MOSI (Data): Leonardo ICSP Pin4 (to DA2 pin 2) * ************************************************************************/ Ideas or suggestions? Where'd I go wrong? Bruce PMOD_DA2.ino EDIT: I've attached a scope trace of the output when I use the following code (snippet) - ramping to 4000 counts in 250 count increments: // OUTPUT & RAMP VARIABLES const int AnalogMaxValue = 4000; // hardcoded max DAC value, proportional to FLOW RATE (motor velocity), range is 0 to 4095 const int AnalogStepSize = 250; const int StepDelayTime = 10; // [milliseconds] delay between analog updates during ramp-up, milliseconds const int SPI_write_delay = 5 ; // [milliseconds] (delay after writing data, before asserting ChipSelect) int upper_byte = 0x00; // upper byte of speed command, to be sent via SPI port to PMOD_DA2 int lower_byte = 0x00; // lower byte of speed command, to be sent via SPI port to PMOD_DA2 int i = 0; // test variable void setup() { // set up pin definitions pinMode(PMOD_CS_Pin, OUTPUT); // PMOD chip select (for Channel #1, Channel #2 is not being used) // set up SPI port SPI.begin(); // initialization of SPI port SPI.setDataMode(SPI_MODE3); // configuration of SPI communication in mode 3 SPI.setClockDivider(SPI_CLOCK_DIV16); // configuration of clock at 1MHz SPI.setBitOrder(MSBFIRST); Write_To_DAC(0); // write zero to the DAC via SPI to initialize } void loop() { for(i=0; i<=AnalogMaxValue; i=i+AnalogStepSize){ Write_To_DAC( i ); // write the Analog value to the DAC via SPI delay(StepDelayTime); } }