1k 程序空间,64 字节 RAM。可以进行1线通信吗?
(如果您懒惰,请参阅TL;DR的底部)
您好,我计划构建一个处理物理计算的新(原型)项目。基本上,我有电线。这些电线都需要同时读取其电压。每根电线的读数之间超过几百微秒的差异将彻底搞砸。 Arduino 大约需要 114 微秒。因此,在延迟影响读数准确性之前,我最多可以读取 2 或 3 条线。
所以我的计划是让 Arduino 作为一系列 ATTinys 的“主人”。 arduino 的空间相当狭窄,但与微小的相比,它是一个巨大的游乐场。 ATtiny13A 有 1k 的闪存 ROM(程序空间)、64 字节的 RAM 和 64 字节的(不耐用且慢速)EEPROM。 (我选择这个是因为价格和尺寸)
我系统中的 ATtinys 不会做太多事情。基本上,他们要做的就是等待来自主机的信号,然后读取 1 或 2 根电线的电压并将其存储在 RAM 中(或者可能是 EEPROM,如果它太拥挤的话)。然后仅使用 1 根数据线将其发送给主机。(没有空间容纳更多数据!)。
到目前为止,我所要做的就是实现简单的电压读取代码(使用内置 ADC)。但我对这种沟通有点担心。您认为通信协议(仅使用 1 根线!)可以在这样的限制下实现吗?
TL;DR:在不到 1k 的程序空间和 64 字节的 RAM(以及 64 字节的 EEPROM)中,您认为有可能实现 1 线通信协议吗?我需要进行组装才能使其适合吗?
我知道目前我链接到 Wiring 库的 Arduino 程序超过 8k,所以我有点担心。
(If your lazy see bottom for TL;DR)
Hello, I am planning to build a new (prototype) project dealing with physical computing. Basically, I have wires. These wires all need to have their voltage read at the same time. More than a few hundred microseconds difference between the readings of each wire will completely screw it up. The Arduino takes about 114 microseconds. So the most I could read is 2 or 3 wires before the latency would skew the accuracy of the readings.
So my plan is to have an Arduino as the "master" of an array of ATTinys. The arduino is pretty cramped for space, but it's a massive playground compared to the tinys. An ATTiny13A has 1k of flash ROM(program space), 64 bytes of RAM, and 64 bytes of (not-durable and slow) EEPROM. (I'm choosing this for price as well as size)
The ATTinys in my system will not do much. Basically, all they will do is wait for a signal from the Master, and then read the voltage of 1 or 2 wires and store it in RAM(or possibly EEPROM if it's that cramped). And then send it to the Master using only 1 wire for data.(no room for more than that!).
So far then, all I should have to do is implement trivial voltage reading code (using built in ADC). But this communication bit I'm worried about. Do you think a communication protocol(using just 1 wire!) could even be implemented in such constraints?
TL;DR: In less than 1k of program space and 64 bytes of RAM(and 64 bytes of EEPROM) do you think it is possible to implement a 1 wire communication protocol? Would I need to drop to assembly to make it fit?
I know that currently my Arduino programs linking to the Wiring library are over 8k, so I'm a bit concerned.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
由于您只需要发送数据(这比接收更简单)并且可以选择自己的协议,因此将代码放入可用内存空间应该不成问题。
我曾经为工业控制面板创建过软件,其中包含 8x14 段 LCD 显示屏、一些 LED、一些按钮、串行 (I2C) EEPROM 和主机串行接口。使用 4 位处理器。该设备没有任何串行接口,因此RS232C接口和I2C总线都必须用软件实现。最重要的是,还有 Modbus 协议(除其他外,它需要 CRC 计算某些精确的时序)和应用程序。
该器件具有约 128 x 4 位 RAM 和 1kW、2kW、3kW 或 4kW ROM(每个字 10 位)。最终程序的大小约为 1100 个字,因此不太适合最小的设备。当然,我使用了汇编器。
但是,您可以考虑使用硬件解决方案,而不是使用多个微控制器。
您可以使用采样和保持电路。为此,您需要一系列模拟开关和电容器,也许还需要运算放大器。只需发出一个触发器即可将所有电压锁存到电容器中。然后,您可以根据需要使用尽可能多的时间来使用主处理器读取电压。
更新:忘记提及,有现成的采样保持放大器需要很少的外部组件或不需要外部组件。这可能是最简单的解决方案。
Since you only need to send data (which is simpler than receiving) and you can select your own protocol, it should not be a problem to fit the code in the available memory space.
I once created software for an industrial control panel that contained 8x14 segment LCD display, some LEDs, some buttons, a serial (I2C) EEPROM, and serial interface to the host. A 4 bit processor was used. The device did not have any serial interface, so both the RS232C interface and I2C bus had to be implemented in software. On top of that, there was Modbus protocol (which among other things requires CRC calculations some exact timing), and the application program.
The device had some 128 x 4 bits of RAM and 1kW, 2kW, 3kW or 4kW of ROM (10 bits per word). The size of the final program was about 1100 words, so it did not quite fit in the smallest device. I used Assembler, of course.
However, instead of using multiple microcontrollers, you could consider using a hardware solution.
You could use a sample and hold circuit. For that, you need an array of analog switches and capacitors and perhaps op-amps. Just issue a trigger to latch all the voltages into the capacitors. Then you can use as much time as you need to read the voltages with your master processor.
Update: Forgot to mention that there are ready-made sample-and-hold amplifiers that need very little or no external components. This is probably the easiest solution.
考虑到您的协议只需要复杂到足以在触发时发送单个整数,1k 的程序空间应该足够了。查看曼彻斯特编码。
1k of program space should be plenty, considering that your protocol only needs to be complicated enough to send a single integer when tickled. Look into Manchester Encoding.
您可能可以使用针对该体系结构的 C 编译器,但您必须创建自己的运行时环境,而不是依赖于编译器提供的环境。这是可行的,但我不确定创建自己的迷你操作系统所需的额外工作是否超过使用 C 语言而不是汇编程序所带来的生产力优势。
You can probably get away with using a C compiler that targets this architecture, but you'll have to create your own runtime environment and not rely on the one supplied with the compiler. That's doable, but I'm not sure if the additional work to essentially create your own mini-OS outweighs the productivity benefit of using C over assembler.
我已经在类似的限制下完成了嵌入式编程。我在这个微型模型中使用了 Borland Turbo C(那是很久以前的事了),并且获得的代码并不比我在汇编程序中完成的代码大,而且花费了一小部分的精力。我的意思是:使用C作为高级汇编程序是非常可行和明智的。
不过,就像我一样,您将面临为 C 提供(微小)运行时环境的问题。理想情况下,您只需要设置堆栈和一些寄存器。此外,您没有足够的空间来容纳 C 库,因此您需要自己编写任何所需的函数。
I've done embedded programming in similar constraints. I used Borland Turbo C (it was a long time ago) in the tiny model and obtained code that was hardly bulkier than I could have done in assembler, with a fraction of the effort. What I'm saying is: It's quite feasible and sensible to use C as a high level assembler.
Just like me, though, you will be facing the problem of providing C with a (tiny) runtime environment. Ideally, you will only need to set up the stack and a few registers. Also, you won't have room for the C library, so you will need to program any needed functions yourself.
是的,可能,但如果你非常了解你的编译器,你可能能够摆脱 c 的困扰。
您可以做的是使用编译器基于 C 代码发出您需要的任何独立函数,然后将它们与您自己的一些代码粘合在一起。 (您当然必须自己进行 c 运行时设置 - 堆栈等。)
Yes, probably, though if you know your compiler very well you might be able to get away with c.
What you could do, is use a compiler to emit any standalone functions you need based on c code, then glue them together with a little of your own. (You'll certainly have to do the c runtime setup yourself - stacks etc.)
您可以考虑升级到 ATTiny25。它是功能更强大的 8 针 AVR,包括 Atmel 的通用串行接口。只需几个字节的软件,它就能够在硬件中进行 1 线串行通信。
You may consider upgrading to the ATTiny25. It is a more capable 8-pin AVR that includes Atmel's Universal Serial Interface. It is capable of doing 1-wire serial comms in hardware, given only a few bytes of software.
为什么不只使用采样保持硬件,而不是一堆微控制器?
Why wouldn't you just use sample-and-hold hardware, rather than a pile of microcontrollers?
我最近使用AT90USB646主设备和ATtiny85从设备设计了一个主从系统。显然,我有更多的内存可以在从站上使用,但我想与您分享的是:
关于您的通信协议,请记住 ATtiny13 上未经校准的内部振荡器的精度为 +/- 10%。这意味着您将无法使用 RS-232 通信等功能。
我在系统中使用了 Dallas 1-Wire 协议的一个变体。包括对从机枚举等的完全支持,C源代码编译为1626字节。
编辑:哎呀,没有意识到这个问题是如此古老。希望这仍然有一些帮助。
I designed a master-slave system recently using an AT90USB646 master and ATtiny85 slaves. Obviously I had a lot more memory to work with on the slaves, but what I wanted to share with you is this:
With regard to your communication protocol, bear in mind that the uncalibrated internal oscillator on the ATtiny13 has an accuracy of +/- 10%. This means you won't be able to use, e.g., RS-232 communications.
I used a variant of the Dallas 1-Wire protocol in my system. Including full support for slave enumeration etc., the C source code compiles into 1626 bytes.
Edit: Whoops, didn't realize the question is so old. Hopefully this may still be of some help.