Compare commits
11 Commits
2a3de0d746
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3973ed17de | |||
| 7c9500f690 | |||
| 9c26592d38 | |||
| 9c6079bdee | |||
| 192913a95b | |||
| 029cb594cb | |||
| 0ba716fb3e | |||
| ec757f57f8 | |||
| 105b208bed | |||
| 17ad372e86 | |||
| f01c38fa7c |
85
README.md
Normal file
85
README.md
Normal file
@@ -0,0 +1,85 @@
|
||||
# Wägetransmitter Modbus
|
||||
|
||||
Ein Steuergerät zum Auslesen einer Wägezelle, angebunden über Modbus RTU.
|
||||
Die Wandlung des analogen Wägezellen-Signals basiert auf dem HX711 IC;
|
||||
auf einem Atmel AVR (ATmega328p) ist der Modbus-Slave implementiert.
|
||||
|
||||
|||
|
||||
|:---:|:---:|
|
||||
|
||||
### Schnittstellenparameter RS485/Modbus RTU
|
||||
|
||||
| Parameter | Wert |
|
||||
|----------------|--------|
|
||||
| Baudrate | 115200 |
|
||||
| Datenbits | 8 |
|
||||
| Parität | none |
|
||||
| Stopbits | 1 |
|
||||
| Modbus Adresse | 1 |
|
||||
|
||||
Das Gerät stellt den 24-bit ADC Wert in 2er-Komplement Darstellung über zwei
|
||||
Holding-Register bereit. Somit ergibt sich ein 32-bit signed Integer Datentyp.
|
||||
|
||||
| Register Adresse | Wert |
|
||||
|------------------|-----------|
|
||||
| 0 | ADC[0:15] |
|
||||
| 1 | 8xADC[23],ADC[22:16]|
|
||||
|
||||
#### Beispiel:
|
||||
Abfragen des Wertes mit dem Tool modpoll (https://www.modbusdriver.com/modpoll.html)
|
||||
```
|
||||
user@pc:~$ modpoll -b 115200 -p none -t4:int /dev/ttyUSB0
|
||||
modpoll 3.10 - FieldTalk(tm) Modbus(R) Master Simulator
|
||||
Copyright (c) 2002-2021 proconX Pty Ltd
|
||||
Visit https://www.modbusdriver.com for Modbus libraries and tools.
|
||||
|
||||
Protocol configuration: Modbus RTU, FC3
|
||||
Slave configuration...: address = 1, start reference = 1, count = 1
|
||||
Communication.........: /dev/ttyUSB0, 115200, 8, 1, none, t/o 1.00 s, poll rate 100 ms
|
||||
Data type.............: 32-bit integer, output (holding) register table
|
||||
|
||||
-- Polling slave... (Ctrl-C to stop)
|
||||
[1]: -242457
|
||||
-- Polling slave... (Ctrl-C to stop)
|
||||
[1]: -242440
|
||||
```
|
||||
|
||||
### HX711
|
||||
|
||||
Über den Jumper `JP1` kann eine Samplerate von 10Hz oder 80Hz gewählt werden.
|
||||
|
||||
### LEDs
|
||||
|
||||
| LED | Signal |
|
||||
|-----|--------|
|
||||
| D1 | Bus Error |
|
||||
| D2 | Bus Transmission |
|
||||
| D3 | 5V Rail |
|
||||
|
||||
### Klemmenbelegung
|
||||

|
||||
|
||||
#### J1
|
||||
| Klemme | Signal |
|
||||
|--------|--------------------------------|
|
||||
| 24V | Spannungsversorgung 9V bis 24V |
|
||||
| GND | Masse (Bus und Versorgung) |
|
||||
| A+ / B-| RS485 Bus Leitungen |
|
||||
| LEDn+ | Externe LED Anode (selbes Signal, wie intern)|
|
||||
| LEDn- | Externe LED Kathode |
|
||||
|
||||
#### J4
|
||||
| Klemme | Signal |
|
||||
|--------|--------------------------------|
|
||||
| E+ | Spannungsversorgung Wägezelle |
|
||||
| E- | Masse |
|
||||
| INA- | Messsignal 1 |
|
||||
| INA+ | Messsignal 2 |
|
||||
|
||||
### Schaltplan
|
||||

|
||||
|
||||
### Mechanische Dimensionen
|
||||

|
||||
|
||||
|
||||
BIN
board/pics/3d-board.png
Normal file
BIN
board/pics/3d-board.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 208 KiB |
3222
board/pics/board-fab.svg
Normal file
3222
board/pics/board-fab.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 229 KiB |
4041
board/pics/board.svg
Normal file
4041
board/pics/board.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 327 KiB |
BIN
board/pics/picture.png
Normal file
BIN
board/pics/picture.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 784 KiB |
21832
board/pics/schematic.svg
Normal file
21832
board/pics/schematic.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 395 KiB |
Binary file not shown.
@@ -1,120 +0,0 @@
|
||||
:100000000C9434000C9451000C9451000C94510049
|
||||
:100010000C9451000C9451000C9451000C9451001C
|
||||
:100020000C9451000C9451000C9451000C9451000C
|
||||
:100030000C9451000C9451000C9451000C945100FC
|
||||
:100040000C9488030C9451000C9419010C948901B0
|
||||
:100050000C94CB010C9451000C9451000C94510061
|
||||
:100060000C9451000C94510011241FBECFEFD8E026
|
||||
:10007000DEBFCDBF11E0A0E0B1E0ECE5F7E002C0EB
|
||||
:1000800005900D92A230B107D9F722E0A2E0B1E0CD
|
||||
:1000900001C01D92A431B207E1F70E9473030C94D2
|
||||
:1000A000AC030C94000080910F0120910E0190E0B0
|
||||
:1000B000922B909304018093030180910D0186306F
|
||||
:1000C00079F080910D01853059F0809111012091D6
|
||||
:1000D000100190E0922B9093060180930501089502
|
||||
:1000E00081E090E09093060180930501089580914E
|
||||
:1000F0000B010895809302010895CF93DF93EC01E3
|
||||
:100100006F5F09F43EC0FC01A62FB0E0BC016A0F8E
|
||||
:100110007B1F2FEF3FEF9081292798E0A9014170C5
|
||||
:10012000552736952795452B21F081E0282780EA31
|
||||
:100130003827915099F73196E617F70761F7A9012B
|
||||
:100140005527632F7727FE01EA0FFB1F808190E080
|
||||
:100150004817590749F01196AC0FBD1F20836C93C7
|
||||
:1001600080E0DF91CF910895AD014F5F5F4FDE01D9
|
||||
:10017000A40FB51F8C9190E08617970779F781E05F
|
||||
:10018000F0CF6FEF70E04FEF50E02FEF3FEFA0E0C8
|
||||
:10019000B0E0D9CF80910B0185FF19C08091090192
|
||||
:1001A00090910A01019690930A0180930901809130
|
||||
:1001B0000B0181FF0DC08091090190910A01079701
|
||||
:1001C00009F18091090190910A01429769F008951F
|
||||
:1001D0008091090190910A014097C9F780910B0124
|
||||
:1001E000816080930B01089590910C018091020130
|
||||
:1001F000981771F080E280930B0110920A0110921F
|
||||
:100200000901089580910B01806480930B0108958A
|
||||
:10021000609107017091080163508CE091E00E94A9
|
||||
:100220007D00882339F30E94530088E080930B01FE
|
||||
:1002300008951F920F920FB60F9211242F933F93A0
|
||||
:100240008F939F93EF93FF939091C60010920A01B2
|
||||
:100250001092090180910B0183FD04C080910B0174
|
||||
:1002600084FF2AC080910B0183FD1BC080910B018C
|
||||
:1002700084FD17C080910B0182FD13C080910B019A
|
||||
:1002800081FD0FC080910B0180FF0BC090930C018A
|
||||
:1002900082E280930B0181E090E0909308018093CB
|
||||
:1002A0000701FF91EF919F918F913F912F910F90B7
|
||||
:1002B0000FBE0F901F90189580910B0182FDD2CF39
|
||||
:1002C00080910B0181FFCECF80910B0180FDCACFC1
|
||||
:1002D00020910701309108012F3F310549F040F08E
|
||||
:1002E00080E280930B0110920A0110920901D9CF8C
|
||||
:1002F000E0910701F0910801E45FFE4F9083809147
|
||||
:1003000007019091080101969093080180930701DD
|
||||
:10031000C8CF1F920F920FB60F9211242F933F93C5
|
||||
:100320008F939F93EF93FF9380910B018F7E809328
|
||||
:100330000B0180910B01846080930B01E091070118
|
||||
:10034000F0910801E45FFE4F80818093C6008091A8
|
||||
:10035000070190910801019690930801809307018D
|
||||
:1003600080910001209107013091080190E00196F1
|
||||
:100370008217930729F48091C1008F7D8093C1007B
|
||||
:10038000FF91EF919F918F913F912F910F900FBE11
|
||||
:100390000F901F9018951F920F920FB60F92112475
|
||||
:1003A0008F935A9880E280930B0110920A01109269
|
||||
:1003B00009018F910F900FBE0F901F90189510920A
|
||||
:1003C000C5008BE38093C40082E08093C00086E088
|
||||
:1003D0008093C20088ED8093C100529A5A9880E2BF
|
||||
:1003E00080930B01089592E0980F90930001682F7D
|
||||
:1003F0008CE091E00E947D0080910B0180618093F0
|
||||
:100400000B0110920801109207015A9AE1ECF0E0FA
|
||||
:1004100080818062808380910B01877F80930B01B4
|
||||
:100420000895ECE0F1E0918190689183828382E00D
|
||||
:100430000C94F301CF93DF932091030130910401D9
|
||||
:100440002617370778F1E0910501F0910601209118
|
||||
:10045000030130910401460F571F2E0F3F1F421713
|
||||
:10046000530700F120910D01233059F120910D0126
|
||||
:10047000243039F120910D01203139F020910D0106
|
||||
:10048000263009F459C080E019C040911201209132
|
||||
:1004900005013091060150E0220F331F4217530728
|
||||
:1004A00008F065C080910D01806880930D0183E0A4
|
||||
:1004B00080930E0182E00E94F30180E0DF91CF91F2
|
||||
:1004C00008952091050130910601220F331F2C3F22
|
||||
:1004D000310540F72091050130910601220F20934C
|
||||
:1004E0000E012091050130910601422F2091030158
|
||||
:1004F00030910401261B370B220F331F442399F040
|
||||
:10050000DC01A20FB31FE0E1F1E080E0EF012197F1
|
||||
:100510002D913C91119738832D913D9120838F5FD0
|
||||
:1005200032964813F3CF80910E018E5F0E94F30143
|
||||
:1005300081E0DF91CF910895A0910301B091040172
|
||||
:10054000A61BB70BAA0FBB1FA80FB91F80911001E4
|
||||
:100550002091110190E0982F8827820F911D11960C
|
||||
:100560009C938E9385E00E94F30181E0A7CF409198
|
||||
:10057000070150910801209112014950510930E0C2
|
||||
:100580004217530708F48ECF2091050130910601E0
|
||||
:10059000422FA0910301B0910401A61BB70BAA0F33
|
||||
:1005A000BB1F2223F9F2E4E1F1E0A80FB91F90E0AC
|
||||
:1005B000EF0121972881808130E0322F2227280FF8
|
||||
:1005C000311D11963C932E9312969F5F32964913DC
|
||||
:1005D000EFCFC8CFCF92DF92EF92FF9221E030E0D1
|
||||
:1005E000F90102C0EE0FFF1F8A95E2F7CF017E2FBF
|
||||
:1005F000E62F682F609558E180E090E0DC0125B19E
|
||||
:10060000272B25B926E02A95F1F700006C017D0122
|
||||
:10061000CC0CDD1CEE1CFF1C23B130E00E2E02C002
|
||||
:10062000359527950A94E2F7C90181709927092E1B
|
||||
:10063000000CAA0BBB0B8C299D29AE29BF2925B123
|
||||
:10064000262325B926E02A95F1F700005150B9F686
|
||||
:10065000403229F1403401F5E3E0F0E030E025B12B
|
||||
:10066000272B25B926E02A95F1F7000025B126238E
|
||||
:1006700025B926E02A95F1F700003F5F432F50E0AF
|
||||
:100680004E175F0764F3A7FDBF6FBC01CD01FF905C
|
||||
:10069000EF90DF90CF900895E1E0F0E0DFCFE2E06F
|
||||
:1006A000F0E0DCCF0E94770083FF1CC080910D0139
|
||||
:1006B000833019F081E00C941102419A40E864E023
|
||||
:1006C0000E94EA0270930D0260930C0290930F0255
|
||||
:1006D00080930E0244E050E060E070E08CE092E035
|
||||
:1006E0000C941A02089587B1836087B9239A81E038
|
||||
:1006F0000E947A000E94DF01789485B5826085BDF2
|
||||
:1007000080916E00816080936E000E945203FDCF45
|
||||
:100710001F920F920FB60F9211242F933F934F9376
|
||||
:100720005F936F937F938F939F93AF93BF93EF9359
|
||||
:10073000FF930E94CA00FF91EF91BF91AF919F91EB
|
||||
:100740008F917F916F915F914F913F912F910F907A
|
||||
:0C0750000FBE0F901F901895F894FFCF7B
|
||||
:02075C00070094
|
||||
:00000001FF
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
TARGET = main
|
||||
SRCS := $(shell find -name '*.c')
|
||||
FILES = $(SRCS:%.c=%) #main uart avrIOhelper/io-helper #uart#hier alle c-Datein reinschreiben, trennung durch " " und ohne .c-Endung
|
||||
FILES = $(SRCS:%.c=%)
|
||||
MCU = atmega328p
|
||||
PROGC = m328p
|
||||
CC = avr-gcc
|
||||
@@ -10,7 +10,7 @@ TOOL = atmelice_isp
|
||||
|
||||
BUILDDIR = Builds
|
||||
|
||||
DEFINES = -I . -IInternet/MQTT -I Internet/MQTT/MQTTPacket/src -I Ethernet/W5500 -I Ethernet -DF_CPU=18432000UL -D_WIZCHIP_=W5100
|
||||
DEFINES = -DF_CPU=18432000UL
|
||||
|
||||
CFLAGS =-mmcu=$(MCU) -O2 -Wall -Wpedantic $(DEFINES) -std=c99 -ffunction-sections -fdata-sections
|
||||
LDFLAGS =-mmcu=$(MCU) -Wl,--gc-sections
|
||||
@@ -45,11 +45,3 @@ size: $(BUILDDIR)/$(TARGET).elf
|
||||
clean:
|
||||
rm -rf $(BUILDDIR)
|
||||
|
||||
|
||||
#Fuse m1284p external Osz. Long startuptime
|
||||
# avrdude -c usbasp-clone -p m1284p -U lfuse:w:0xff:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
|
||||
|
||||
#Fuse m1284p internal Osz. Long startuptime
|
||||
# avrdude -c usbasp-clone -p m1284p -U lfuse:w:0xe2:m -U hfuse:w:0xd9:m -U efuse:w:0xff:m
|
||||
|
||||
|
||||
|
||||
7
code/compile_flags.txt
Normal file
7
code/compile_flags.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
-D
|
||||
__AVR_ATmega328P__
|
||||
-D
|
||||
F_CPU=18432000UL
|
||||
-I
|
||||
/usr/lib/avr/include
|
||||
|
||||
40
code/main.c
40
code/main.c
@@ -1,18 +1,16 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdint.h>
|
||||
#include <util/delay.h>
|
||||
#include "modbus.h"
|
||||
|
||||
#define HIGH_LOW_CYCLE_TIME 1
|
||||
#define HIGH_LOW_CYCLE_TIME 10
|
||||
|
||||
uint16_t holdingRegisters[4];
|
||||
|
||||
void timer0100us_start(void) {
|
||||
TCCR0B|=(1<<CS01); //prescaler 8
|
||||
TIMSK0|=(1<<TOIE0);
|
||||
}
|
||||
volatile uint32_t led_on_timer[3];
|
||||
|
||||
//Return raw ADC data
|
||||
// return raw ADC data
|
||||
uint32_t HX711_get_data(uint8_t clk_PIN, uint8_t data_PIN, uint8_t gain_for_next_conv){
|
||||
uint32_t data = 0;
|
||||
for(uint8_t i = 0; i < 24; i++){ //Start 24bit transmission
|
||||
@@ -67,19 +65,21 @@ void modbusGet(void) {
|
||||
{
|
||||
switch(rxbuffer[1]) {
|
||||
case fcReadHoldingRegisters:
|
||||
PORTC |= 1 << 1;
|
||||
// _delay_ms(10);
|
||||
// PORTC &= ~(1 << 1);
|
||||
PORTC |= 1 << 0;
|
||||
led_on_timer[0]=1000;
|
||||
|
||||
while(PINB & (1<<4)); // wait for data ready
|
||||
|
||||
uint32_t tmp = HX711_get_data(3, 4, 128);
|
||||
//int32_t tmp = -1000;
|
||||
holdingRegisters[0] = tmp & 0xFFFF;
|
||||
holdingRegisters[1] = (tmp>>16) & 0xFFFF;
|
||||
holdingRegisters[2] = led_on_timer[1];
|
||||
modbusExchangeRegisters(holdingRegisters,0,4);
|
||||
break;
|
||||
|
||||
default: {
|
||||
default:
|
||||
PORTC |= 1 << 1;
|
||||
led_on_timer[1]=1000;
|
||||
modbusSendException(ecIllegalFunction);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -93,16 +93,22 @@ int main(void){
|
||||
modbusInit();
|
||||
sei();
|
||||
|
||||
timer0100us_start();
|
||||
/* modbus tick timer */
|
||||
TCCR0B|=(1<<CS01);
|
||||
TIMSK0|=(1<<TOIE0);
|
||||
|
||||
while(1){
|
||||
modbusGet();
|
||||
//PORTC ^= 1 << 0;
|
||||
//_delay_ms(100);
|
||||
//PORTC &= ~(1 << 1);
|
||||
}
|
||||
}
|
||||
|
||||
ISR(TIMER0_OVF_vect) { //this ISR is called 9765.625 times per second
|
||||
modbusTickTimer();
|
||||
|
||||
for(uint8_t i=0; i<2; i++){
|
||||
if(led_on_timer[i]>0)
|
||||
led_on_timer[i]--;
|
||||
else
|
||||
PORTC &= ~(1<<i);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user