Skip to content

Commit a574946

Browse files
author
Tim Essig
committed
Added 1kHz Timer0
1 parent 8bba9f0 commit a574946

18 files changed

+737
-144
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.map
2+
*.hex
3+
*.lss
4+
*.elf
5+
*.eep
6+
*.sym
7+
obj/**
8+
.dep/**

.vscode/c_cpp_properties.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"includePath": [
6+
"/usr/include",
7+
"/usr/local/include",
8+
"/usr/lib/avr/include",
9+
"${workspaceRoot}"
10+
],
11+
"defines": [],
12+
"intelliSenseMode": "clang-x64",
13+
"browse": {
14+
"path": [
15+
"/usr/include",
16+
"/usr/local/include",
17+
"${workspaceRoot}"
18+
],
19+
"limitSymbolsToIncludedHeaders": true,
20+
"databaseFilename": ""
21+
},
22+
"macFrameworkPath": [
23+
"/System/Library/Frameworks",
24+
"/Library/Frameworks"
25+
]
26+
},
27+
{
28+
"name": "Linux",
29+
"includePath": [
30+
"/usr/include/c++/6",
31+
"/usr/include/x86_64-linux-gnu/c++/6",
32+
"/usr/include/c++/6/backward",
33+
"/usr/lib/gcc/x86_64-linux-gnu/6/include",
34+
"/usr/local/include",
35+
"/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed",
36+
"/usr/include/x86_64-linux-gnu",
37+
"/usr/include",
38+
"/usr/lib/gcc/avr/4.9.2/include",
39+
"${workspaceRoot}"
40+
],
41+
"defines": [],
42+
"intelliSenseMode": "clang-x64",
43+
"browse": {
44+
"path": [
45+
"/usr/include/c++/6",
46+
"/usr/include/x86_64-linux-gnu/c++/6",
47+
"/usr/include/c++/6/backward",
48+
"/usr/lib/gcc/x86_64-linux-gnu/6/include",
49+
"/usr/local/include",
50+
"/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed",
51+
"/usr/include/x86_64-linux-gnu",
52+
"/usr/include",
53+
"/usr/lib/gcc/avr/4.9.2/include",
54+
"${workspaceRoot}"
55+
],
56+
"limitSymbolsToIncludedHeaders": true,
57+
"databaseFilename": ""
58+
}
59+
},
60+
{
61+
"name": "Win32",
62+
"includePath": [
63+
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
64+
"${workspaceRoot}"
65+
],
66+
"defines": [
67+
"_DEBUG",
68+
"UNICODE"
69+
],
70+
"intelliSenseMode": "msvc-x64",
71+
"browse": {
72+
"path": [
73+
"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*",
74+
"${workspaceRoot}"
75+
],
76+
"limitSymbolsToIncludedHeaders": true,
77+
"databaseFilename": ""
78+
}
79+
}
80+
],
81+
"version": 3
82+
}

.vscode/settings.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"files.associations": {
3+
"io.h": "c",
4+
"delay.h": "c",
5+
"*.ipp": "cpp",
6+
"enc28j60.h": "c",
7+
"array": "c",
8+
"functional": "c",
9+
"dmx.h": "c",
10+
"enc28j60_defs.h": "c"
11+
}
12+
}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ OBJDIR = obj
7878

7979

8080
# List C source files here. (C dependencies are automatically generated.)
81-
SRC = $(TARGET).c
81+
SRC = $(TARGET).c display.c enc28j60.c dmx.c artnet.c udp.c
8282

8383

8484
# List C++ source files here. (C dependencies are automatically generated.)

artnet.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "artnet.h"
2+
#include "dmx.h"
3+
4+
5+
volatile uint8_t universeFPS[DMX_NUM_UNIVERSES];
6+
volatile uint8_t universeFPSCounter[DMX_NUM_UNIVERSES] = {0};
7+
8+
uint8_t getUniverseFPS(uint8_t universe) {
9+
if(universe < DMX_NUM_UNIVERSES) {
10+
return universeFPS[universe];
11+
} else {
12+
return 0;
13+
}
14+
}
15+
16+
void universeReceivedTMP(uint8_t universe) {
17+
if(universe < DMX_NUM_UNIVERSES) {
18+
universeFPSCounter[universe]++;
19+
}
20+
}
21+
22+
void doTimerStuff1Hz(void) {
23+
PORTA.DIRTGL = 0x03;
24+
25+
for(uint8_t i=0; i < 4; i++) {
26+
universeFPS[i] = universeFPSCounter[i];
27+
universeFPSCounter[i] = 0;
28+
}
29+
}

artnet.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef _ARTNET_H
2+
#define _ARTNET_H 1
3+
4+
#include <avr/io.h>
5+
6+
7+
extern uint8_t getUniverseFPS(uint8_t universe);
8+
9+
extern void universeReceivedTMP(uint8_t universe);
10+
11+
extern void doTimerStuff1Hz(void);
12+
13+
#endif

display.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ void writeInt(uint8_t value) {
4646
writeStr(str);
4747
}
4848

49+
void writeIntWidth(uint8_t value, uint8_t width) {
50+
char str[4];
51+
52+
itoa(value, str, 10);
53+
54+
if(width >= 3 && value < 100) {
55+
write(' ');
56+
}
57+
58+
if(width >= 2 && value < 10) {
59+
write(' ');
60+
}
61+
62+
writeStr(str);
63+
}
64+
4965

5066
void write(uint8_t value) {
5167
send(value, Rs);

display.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ extern void setupTWI(void);
6060
extern void twiWrite(unsigned char byte);
6161
extern void writeStr(char* value);
6262
extern void writeInt(uint8_t value);
63+
extern void writeIntWidth(uint8_t value, uint8_t width);
6364
extern void write(uint8_t value);
6465

6566
extern void setupDisplay(void);

dmx.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ uint8_t* getUniverseBuffer(uint8_t universe) {
1414
}
1515

1616

17+
1718
enum DMX_STATE {
1819
DMX_IDLE,
1920
DMX_BREAK,
@@ -45,13 +46,21 @@ void setupDMXPort(USART_t* uart) {
4546
uart->CTRLA = USART_TXCINTLVL_gm; // TX Highest INT Level
4647
uart->CTRLC = USART_SBMODE_bm | USART_CHSIZE_8BIT_gc; //2 StopBits, 8 DataBits
4748

48-
4949
uart->CTRLB = USART_TXEN_bm; //Enable TX
5050
}
5151

5252
void setupDMX(void) {
53+
//DMX 1
54+
PORTC.DIRSET = PIN3_bm; // Pin 3 -> UART 0 TX
55+
PORTC.PIN3CTRL = PORT_INVEN_bm;
56+
setupDMXPort(&USARTC0);
57+
58+
//DMX 2
59+
PORTC.DIRSET = PIN7_bm; // Pin 3 -> UART 0 TX
60+
PORTC.PIN7CTRL = PORT_INVEN_bm;
61+
setupDMXPort(&USARTC1);
62+
5363

54-
5564
//DMX 3
5665
PORTD.DIRSET = PIN3_bm; // Pin 3 -> UART 0 TX
5766
PORTD.PIN3CTRL = PORT_INVEN_bm;
@@ -64,22 +73,17 @@ void setupDMX(void) {
6473
}
6574

6675

67-
void startDMX_TX(void) {
68-
76+
void startDMX_TX(void) {
6977
if(dmx0state == DMX_IDLE) {
70-
PORTA.OUTSET = 0x01;
71-
7278
//Set Baud
7379
UART0.BAUDCTRLA = DMX_BAUD_RESET_BSEL;
7480
UART0.BAUDCTRLB = DMX_BAUD_BSCALE << 4;
7581

7682
//Send Break Byte
77-
while (!( UART0.STATUS & USART_DREIF_bm));
7883
UART0.DATA = 0x00;
7984

8085
dmx0state = DMX_START;
8186
}
82-
8387
}
8488

8589
ISR(USARTD0_TXC_vect) //Transimission complete
@@ -100,16 +104,12 @@ ISR(USARTD0_TXC_vect) //Transimission complete
100104

101105
break;
102106
case DMX_RUN:
103-
PORTA.OUTSET = 0x02;
104-
105107
UART0.DATA = dmxBuffer[0][dmx0ch++];
106108

107109
if(dmx0ch >= 512) {
108110
dmx0state = DMX_IDLE;
109-
PORTA.OUTCLR = 0x03;
110-
//_delay_ms(500);
111111
}
112112
break;
113113

114114
}
115-
}
115+
}

0 commit comments

Comments
 (0)