arms22 / SoftModem

Audio Jack Modem Library for Arduino
BSD 3-Clause "New" or "Revised" License
191 stars 37 forks source link

Support other microcontrollers than ATmega328p #5

Open rmeister opened 8 years ago

rmeister commented 8 years ago

e.g. ATtiny85, ATmega32u4.

We already began doing some stuff in this direction: publiclab/webjack#17

I managed to get the library sending on the ATtiny with Timer0. The problem with receiving is, that Timer0 uses the same pins as the analog comparator.

A solution could be the ADC multiplexer, which allows to replace AIN1 with an arbitrary ADC input pin. The downside of this solution is, that none of the other ADC pins can be used then, as the ADC has to be disabled. It would be perfect if Timer1 can be used instead of Timer0. But I did not have the time yet to look closely at the differences between the timers.

For the ATmega32u4 the ADC definitively has to be switched off, otherwise it can only use the internal bandgap reference as negative comparator input.

arms22 commented 8 years ago

Would you like to add a transistor? like this http://cyberworks.cocolog-nifty.com/blog/files/modem_mono.pdf

rmeister commented 8 years ago

I think I did not understand your question. Will a transistor help in supporting other µCs?

arms22 commented 8 years ago

Yes. An analog comparator becomes unnecessary. There should be an interrupt pin for reception and a general-purpose pin for transmissions.

rmeister commented 8 years ago

Ah I see, thanks for the hint. This circuit also has the benefit that it does not need a pin for reference voltage. Would be great to get this working, hope I can build the circuit this week.

Unfortunately there is also a downside: this will break compatibility with existing shields/boards ( I could not find any with transistor built-in). Meaning this probably would require some documentation and a new major release.

jywarren commented 8 years ago

I got SoftModem onto the Leonardo (ATmega32u4), and sending, but not receiving (as noted) using @rmeister's https://github.com/rmeister/SoftModem/tree/attiny-support.

What would it take to get receiving working? I'd like to contribute but am not sure exactly where to start. Thank you!

arms22 commented 8 years ago

I think that additional circuitry is necessary to support SoftModem.

https://github.com/arms22/SoftModem/issues/5#issuecomment-240717423

arms22 commented 8 years ago

ATmega32U4 has Analog Comparator.

AIN+ can be connected either to the AIN0 (PE6) pin, or to the internal Bandgap reference. AIN- can only be connected to the ADC multiplexer.

If analogRead is unnecessary, make the following connection. AIN+ AIN0 AIN- AIN1

If you need analogRead, make the following connection. AIN+ AIN0 AIN- Bandgap ref

For more detail see 2.3 Analog Comparator http://www.atmel.com/ja/jp/Images/Atmel-7766-8-bit-AVR-ATmega16U4-32U4_Datasheet.pdf

jywarren commented 7 years ago

Thanks! I'm not familiar enough with electronics to help on a circuitry change at this point, but I looked up what an analog comparator is, which was a good first step for me:

http://www.instructables.com/id/Girino-Fast-Arduino-Oscilloscope/step11/How-the-Analog-Comparator-works/

gyunaev commented 7 years ago

Just wanted to let you know that I have implemented the circuit shown above http://cyberworks.cocolog-nifty.com/blog/files/modem_mono.pdf and it worked fine on Atmega328. The only exception is that a 100R resistor was replaced by 1K resistor. Analog comparator interrupt handler is replaced by a regular interrupt triggered on RISING.

However SoftModem currently does not work on attiny85, at least on 16Mhz using internal PLL oscillator. Sending kind of works after I replaced timer output with manual port switching and _delay_us(), but with sync errors: sending anything longer than five characters is impossible as the sequence gets corrupted. With default timers it doesn't work at all, even though it sounds like normal. And receiving doesn't work at all, even though the same softmodem works on 328P (with transistor).