0
\$\begingroup\$

I have set up 2 AtTiny45 setup like this (The left one is also connected to power): from which one (the left one) is generating a signal which is (when measured) looking like this: The second one now runs this code to just pass the signal through from an input to an output:

int inPin = 3;
int outPin = 4;

void setup() {
  pinMode(inPin, INPUT);
  digitalWrite(inPin, HIGH);
  pinMode(outPin, OUTPUT);
}

void loop() {
  digitalWrite(outPin, digitalRead(inPin));
}

But instead of looking like the original it is looking like this:

The tinys are both running at 8Mhz speed.

\$\endgroup\$
16
  • \$\begingroup\$ The second one is also connected to the power line I just forgot it... \$\endgroup\$
    – Busti
    May 2, 2015 at 23:51
  • \$\begingroup\$ Have you tried accessing the registers directly? \$\endgroup\$ May 2, 2015 at 23:56
  • \$\begingroup\$ No, I will have a look into it. \$\endgroup\$
    – Busti
    May 2, 2015 at 23:58
  • \$\begingroup\$ you could set up a pin-change interrupt on that pin (or a pin which supports it) and have it edge triggered, then just output the value of the input pin at that moment. \$\endgroup\$
    – KyranF
    May 3, 2015 at 0:00
  • \$\begingroup\$ another thing is, why is the input pin set to HIGH, that enables the pull up resistors yes? \$\endgroup\$
    – KyranF
    May 3, 2015 at 0:01

2 Answers 2

0
\$\begingroup\$

Based on the code, I am guessing you are using the Arduino libraries?

If so, then looking at your breadboard and your code, it looks like you might just have your pins reversed.

In Arduino-land on an ATTINY 45, the "pin" as used for for pinMode() and readDigital() does not correspond to the actual physical numbered pins on the device...

enter image description here

(from this helpful site)

Maybe try swapping the pin values in your code to this...

int inPin = 4;
int outPin = 3;

void setup() {
  pinMode(inPin, INPUT);
  digitalWrite(inPin, HIGH);
  pinMode(outPin, OUTPUT);
}

void loop() {
  digitalWrite(outPin, digitalRead(inPin));
}

...and attach your scope to physical pin #2 (Arduino pin #3) on the device and see what you get.

Also note that the digitalRead() and digitalWrite() functions in thew Arduino library are notoriously slow, so depending on how fast the signal that you are trying to duplicate changes, you might want to look into the DigitalWriteFast library or direct port manipulation.

\$\endgroup\$
6
  • \$\begingroup\$ Yes I am using the Arduino IDE. Sadly it doesn't support the library so I can't test that. The Signal is about 600ns per send bit with a minimum of 200ns. Your code sadly does the exact same as the old one but the ports are swapped, so I will be having a look into port manipulation now. Also does everyone seem to forget that the Tinys have a third PWM pin (Pin 4, Physical 3) \$\endgroup\$
    – Busti
    May 4, 2015 at 14:38
  • \$\begingroup\$ What would this code look like using port manipulation? I tried this: void setup() { DDRB = B00001000; PORTB = B00001000; } void loop() { bitWrite(PORTB, 4, bitRead(PINB, 3)); } GIST: gist.github.com/Busti/82859493178cb16ab8fd \$\endgroup\$
    – Busti
    May 4, 2015 at 15:55
  • \$\begingroup\$ If you are running at the default clock of 8MHz, then a single instruction will take at least 125ns. Even in pure optimized assembly, for each bit you will need to (1) read the bit, (2) shift to new position, (3) write the bit, (4) jump to 1. There is no way to do all this in time to reliably repeat a 200ns (or even 600ns) window. Keep in mind that you need to sample the input at twice the maximum frequency (Nyquist). \$\endgroup\$
    – bigjosh
    May 4, 2015 at 16:28
  • \$\begingroup\$ I thought that when I generate it with an AtTiny I can also read it using one... \$\endgroup\$
    – Busti
    May 4, 2015 at 17:33
  • \$\begingroup\$ Could it work when I set the tiny to 16MHZ? \$\endgroup\$
    – Busti
    May 4, 2015 at 17:34
0
\$\begingroup\$

Try adding a "proper reset circuitry":

schematic

simulate this circuit – Schematic created using CircuitLab

You dont mention from where you are powering your board, there may be to much noise and its reseting your MCU. By adding a stronger pull-up and a capacitor you're filtering out the noise that may appear on your power-supply or RESET line.

\$\endgroup\$
8
  • \$\begingroup\$ I added the circuitry but still no change. \$\endgroup\$
    – Busti
    May 3, 2015 at 13:39
  • \$\begingroup\$ I also added a large capacitor (330nF) between 5V and GND \$\endgroup\$
    – Busti
    May 3, 2015 at 13:40
  • \$\begingroup\$ I suggest you try to do as KyranF suggested, using a pin-change interrupt, and see if you get any output at all. \$\endgroup\$
    – Golaž
    May 3, 2015 at 13:42
  • \$\begingroup\$ I am on it right now. I basically want to decode the WS2811 driver signal. \$\endgroup\$
    – Busti
    May 3, 2015 at 13:43
  • \$\begingroup\$ I am now done testing the Pin change Interrupt but still the same outcome. \$\endgroup\$
    – Busti
    May 3, 2015 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.