0

Just want to create signal in gnuradio and send him in Arduino Due with ethernet shield w5100 using TCP protocol, that will be generate signal on DAC0 pin. But I'm stuck more over three days trying resolve this. GRC project has Signal source block (type - byte, frequency - 100Hz, waveform - sine, sampl rate 32000Hz) connected to TCP sink block. Arduino receive signal, but signal from pin DAC looks like square wave. What's wrong? And second question, how is possible to convert 32 bit value to 12 bit in arduino sketch (if choose in gnuradio signal source block float type)?

Arduino sketch:

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 137, 10);
EthernetServer server(8788);

void setup() {
analogWriteResolution(8); // set DAC resolution to 8 bits
Ethernet.begin(mac, ip);
server.begin();
}

void loop() {
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
  if (client.available()) {
    byte val = client.read();
    analogWrite(DAC0, val); // generate signal on DAC0 pin
   }
  }
client.stop();
 }
}
Vasil992
  • 3
  • 1

1 Answers1

-1

This arduino sketch seems more than questionable – instead of waiting for data to be available, you fetch it (spinlocking if there's no packet available); and instead of having a timer that copies values to the DAC at regular intervals, you just write them as quickly as possible. Sadly, that can't work, since data arrives in packets. When there's a new packet, your while() will have a lot of bytes to quickly write out. As soon as the packet is consumed, there's nothing to write anymore.

So, you need to rearchitect your Arduino side:

  • you need instruct your microcontroller to do a DMA transfer on a regular interval,
  • you need to copy the first incoming data packet to the input buffer of that DMA buffer
  • you need to instruct the DMA controller to take the next input buffer once the first runs empty

I have no idea how one does that under Arduino, I'm afraid.

And second question, how is possible to convert 32 bit value to 12 bit in arduino sketch (if choose in gnuradio signal source block float type)?

By multiplying with an appropriate constant, and casting to a 16 bit integer, probably; then use just the 12 bit relevant to the DAC. But: you would never want to do that. Do your floating point processing in GNU Radio on your host computer, convert to 12bit-in-16bit integer there, and send the prepared data over the ethernet. No sense in wasting bandwidth and compute power sending 32 bit of which you only need 12!

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94