0
\$\begingroup\$

Some background: I am putting together a display to teach children about how neural circuits work. I am making a group of 'blocks' (each of which contains an ATTiny85, an indicator LED, and input/output wires) that can be connected in different configurations to represent different circuit motifs.

The problem: I am trying to use PWM to communicate between the ATTiny85s. My original idea, simply reading input PWM signals with analogRead and generating a PWM output with analogWrite, worked fine while all the ATTiny85s were running off a 5V power supply from an Arduino. However, now that I've switched to using a 4.5V battery pack for each ATTiny85, the PWM communication no longer works.

I expected the PWM outputs to change somewhat (given that HIGH is now limited to 4.5V), but what I am finding is that the output values (when read into an Arduino using analogRead OR pulseIn) now jump around hugely (e.g. pulseIn read out between 50 and 15000 from PWM output analogWrite(250)). Even averaging over up to 1000 pulses doesn't do much to smooth out the value.

Am I missing something?

\$\endgroup\$
  • 1
    \$\begingroup\$ PWM is digital (analogWrite is badly named since there is nothing analogue about it). You'll need to filter (e.g. RC low pass) the PWM signal to get an analogue voltage. \$\endgroup\$ – Tom Carpenter Jun 14 '17 at 9:52
  • \$\begingroup\$ I don't need an actual analog voltage, I just need some way for the ATTiny85s to communicate in different configurations. The analogRead to get the PWM input was a bit of a cheat, but I'm having the same problem using pulseIn. \$\endgroup\$ – fminl Jun 14 '17 at 9:55
  • 1
    \$\begingroup\$ You will have to explain your signal protocol better. Do you just want to detect whether there's a PWM output or not, or does the PWM actually contain data? If so, how is it encoded? \$\endgroup\$ – Dampmaskin Jun 14 '17 at 10:38
  • 1
    \$\begingroup\$ Have you got a shared ground between all your nodes? Ie negative of all batteries shorted. If each ATTiny has its own battery they will all have different ADC references based on their battery state. \$\endgroup\$ – Colin Jun 14 '17 at 11:32
  • 1
    \$\begingroup\$ As Tom Carpenter said, you should low pass filter the PWM so that it becomes a stable voltage. The ADC can't make sense of raw PWM, and I have no idea why it seemed to work for you at 5V. \$\endgroup\$ – Dampmaskin Jun 14 '17 at 12:03
-2
\$\begingroup\$

The analog read should yield the same adv number if the reference is set to vdd.

Pulsein should also give the same results.

The issue is likely your code or wiring.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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