Compare commits
7 Commits
ec757f57f8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 3973ed17de | |||
| 7c9500f690 | |||
| 9c26592d38 | |||
| 9c6079bdee | |||
| 192913a95b | |||
| 029cb594cb | |||
| 0ba716fb3e |
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 |
35
code/main.c
35
code/main.c
@@ -1,5 +1,6 @@
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
#include <stdint.h>
|
||||
#include <util/delay.h>
|
||||
#include "modbus.h"
|
||||
|
||||
@@ -7,12 +8,9 @@
|
||||
|
||||
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,22 +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;
|
||||
}
|
||||
}
|
||||
@@ -96,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