Skip to content

Commit 20e150e

Browse files
authored
Add atmega328pb (#34)
1 parent 1926d17 commit 20e150e

File tree

7 files changed

+307
-5
lines changed

7 files changed

+307
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Application to configure and visualise timers. All your changes are stored in th
1111
## Supported microcontrollers:
1212

1313
- Atmel atmega328p (e.g Arduino Uno, Nano, Pro-mini)
14+
- Atmel atmega328pb (newer, some times found in pro-minis)
1415
- Logic Green lgt8f328p [checkout this core](https://github.com/dbuezas/lgt8fx)
1516
- If people uses this, I can add more (e.g attiny)
1617

@@ -19,7 +20,8 @@ Application to configure and visualise timers. All your changes are stored in th
1920
- Timer0
2021
- Timer1
2122
- Timer2
22-
- Timer3
23+
- Timer3 (lgt8f328p and atmega328pb)
24+
- Timer4 (atmega328pb)
2325

2426
## Supported modes (all!)
2527

@@ -54,7 +56,7 @@ Application to configure and visualise timers. All your changes are stored in th
5456
- A custom constraint solver finds out what values are possible for each of the other variables and the rest is disabled in the UI (note that tables are interconnected when they share variables)
5557
- Given the user selection, a suggestion for all other variables is created one by one by:
5658
- Computing the viable values of a variable
57-
- Picking the first viable value for that variable
59+
- Picking the first viable value for that variable
5860
- Repeating until all variables have only one viable value
5961
- Finally the values of variables are used to run the simulation (plot) and write the code & comments.
6062
- The code output is generared by iterating over each regiser and picking the bits that are set to one.

src/data/atmega328pb/index.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// @ts-expect-error
2+
import timer0 from '../atmega328p/timer0.tsv'
3+
// @ts-expect-error
4+
import timer1 from '../atmega328p/timer1.tsv'
5+
// @ts-expect-error
6+
import timer2 from '../atmega328p/timer2.tsv'
7+
// @ts-expect-error
8+
import timer3 from './timer3.tsv'
9+
// @ts-expect-error
10+
import timer4 from './timer4.tsv'
11+
import { tsv, tsvConstraints } from '../timers'
12+
13+
const timers = [tsv(timer0), tsv(timer1), tsv(timer2), tsv(timer3), tsv(timer4)]
14+
15+
timers.forEach((t) =>
16+
t.configs.push(
17+
tsvConstraints(`
18+
FCPU FCPU_UI
19+
16000000 16Mhz
20+
20000000 20Mhz
21+
8000000 8Mhz
22+
4000000 4Mhz
23+
2000000 2Mhz
24+
1000000 1Mhz
25+
`)
26+
)
27+
)
28+
export default timers

src/data/atmega328pb/timer3.tsv

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//REGISTERS
2+
TCCR3A TCCR3B TCCR3C TIMSK3 DTR3 TIFR3 DDRD
3+
COM3A1 ICNC3 FOC3A - - - DDD0
4+
COM3A0 ICES3 FOC3B - - - DDD1
5+
COM3B1 - - ICIE3 - ICF3 DDD2
6+
COM3B0 WGM33 - - - - DDD3
7+
- WGM32 - - - - DDD4
8+
- CS32 - OCIE3A - OCF3B DDD5
9+
WGM31 CS31 - OCIE3B - OCF3A DDD6
10+
WGM30 CS30 - TOIE3 - TOV3 DDD7
11+
12+
//CONSTRAINTS
13+
timerNr timerBits counterMax
14+
1 16 65535
15+
16+
WGM3 WGM33 WGM32 WGM31 WGM30 timerMode topValue updateOcrMoment setTovMoment
17+
0 0 0 0 0 Normal 0xFFFF immediate MAX
18+
1 0 0 0 1 PCPWM 0x00FF TOP BOTTOM
19+
2 0 0 1 0 PCPWM 0x01FF TOP BOTTOM
20+
3 0 0 1 1 PCPWM 0x03FF TOP BOTTOM
21+
4 0 1 0 0 CTC OCR3A immediate MAX
22+
5 0 1 0 1 FPWM 0x00FF BOTTOM TOP
23+
6 0 1 1 0 FPWM 0x01FF BOTTOM TOP
24+
7 0 1 1 1 FPWM 0x03FF BOTTOM TOP
25+
8 1 0 0 0 PFCPWM ICR3 BOTTOM BOTTOM
26+
9 1 0 0 1 PFCPWM OCR3A BOTTOM BOTTOM
27+
10 1 0 1 0 PCPWM ICR3 TOP BOTTOM
28+
11 1 0 1 1 PCPWM OCR3A TOP BOTTOM
29+
12 1 1 0 0 CTC ICR3 immediate MAX
30+
13 1 1 0 1 reserved - - -
31+
14 1 1 1 0 FPWM ICR3 TOP TOP
32+
15 1 1 1 1 FPWM OCR3A TOP TOP
33+
34+
COM3A COM3A1 COM3A0 timerMode CompareOutputModeA WGM3 CompareOutputModeB
35+
0 0 0 Normal disconnect * *
36+
1 0 1 Normal toggle * *
37+
2 1 0 Normal clear * *
38+
3 1 1 Normal set * *
39+
0 0 0 CTC disconnect * *
40+
1 0 1 CTC toggle * *
41+
2 1 0 CTC clear * *
42+
3 1 1 CTC set * *
43+
0 0 0 FPWM disconnect * *
44+
1 0 1 FPWM toggle 15 disconnect
45+
2 1 0 FPWM clear-on-match, set-at-max * *
46+
3 1 1 FPWM set-on-match, clear-at-max * *
47+
0 0 0 PCPWM disconnect * *
48+
1 0 1 PCPWM toggle 11 disconnect
49+
2 1 0 PCPWM clear-up, set-down * *
50+
3 1 1 PCPWM set-up, clear-down * *
51+
0 0 0 PFCPWM disconnect * *
52+
1 0 1 PFCPWM toggle 9 disconnect
53+
2 1 0 PFCPWM clear-up, set-down * *
54+
3 1 1 PFCPWM set-up, clear-down * *
55+
56+
COM3B COM3B1 COM3B0 timerMode CompareOutputModeB
57+
0 0 0 Normal disconnect
58+
1 0 1 Normal toggle
59+
2 1 0 Normal clear
60+
3 1 1 Normal set
61+
0 0 0 CTC disconnect
62+
1 0 1 CTC toggle
63+
2 1 0 CTC clear
64+
3 1 1 CTC set
65+
0 0 0 FPWM disconnect
66+
1 0 1 FPWM disconnect
67+
2 1 0 FPWM clear-on-match, set-at-max
68+
3 1 1 FPWM set-on-match, clear-at-max
69+
0 0 0 PCPWM disconnect
70+
1 0 1 PCPWM disconnect
71+
2 1 0 PCPWM clear-up, set-down
72+
3 1 1 PCPWM set-up, clear-down
73+
0 0 0 PFCPWM disconnect
74+
1 0 1 PFCPWM disconnect
75+
2 1 0 PFCPWM clear-up, set-down
76+
3 1 1 PFCPWM set-up, clear-down
77+
78+
CS3 CS32 CS31 CS30 clockPrescalerOrSource ExternalClockInput
79+
1 0 0 1 1 N/A
80+
2 0 1 0 8 N/A
81+
3 0 1 1 64 N/A
82+
4 1 0 0 256 N/A
83+
5 1 0 1 1024 N/A
84+
6 1 1 0 external clock falling edge E3
85+
7 1 1 1 external clock rising edge E3
86+
0 0 0 0 disconnect N/A
87+
88+
OCIE3A interruptA interruptVectorCodeA
89+
0 off //nocode
90+
1 on ISR(TIMER3_COMPA_vect) {\n /* on OCR3A match */\n}
91+
92+
OCIE3B interruptB interruptVectorCodeB
93+
0 off //nocode
94+
1 on ISR(TIMER3_COMPB_vect) {\n /* on OCR3B match */\n}
95+
96+
97+
TOIE3 InterruptOnTimerOverflow interruptVectorCodeOVF
98+
0 off //nocode
99+
1 on ISR(TIMER3_OVF_vect) {\n /* on overflow */\n}
100+
101+
ICIE3 InterruptOnInputCapture interruptVectorCaptureCode
102+
0 off //nocode
103+
1 on ISR(TIMER3_CAPT_vect) {\n /* on input capture */\n}
104+
105+
ICNC3 InputCaptureNoiseSupression
106+
0 off
107+
1 on
108+
109+
ICES3 InputCaptureEdgeSelect
110+
0 falling
111+
1 rising
112+
113+
OCnB_OutputPort
114+
D2
115+
116+
OCnA_OutputPort
117+
D0
118+
119+
CompareOutputModeA OCnA_OutputPort DDD0
120+
disconnect * 0
121+
!disconnect D0 1
122+
123+
CompareOutputModeB OCnB_OutputPort DDB2
124+
disconnect * 0
125+
!disconnect D2 1
126+
127+
ICR3
128+
*
129+
130+
OCR3A
131+
*
132+
133+
OCR3B
134+
*

src/data/atmega328pb/timer4.tsv

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
//REGISTERS
2+
TCCR4A TCCR4B TCCR4C TIMSK3 DTR3 TIFR3 DDRD
3+
COM4A1 ICNC4 FOC4A - - - DDD0
4+
COM4A0 ICES4 FOC4B - - - DDD1
5+
COM4B1 - - ICIE4 - ICF4 DDD2
6+
COM4B0 WGM43 - - - - DDD3
7+
- WGM42 - - - - DDD4
8+
- CS42 - OCIE4A - OCF4B DDD5
9+
WGM41 CS41 - OCIE4B - OCF4A DDD6
10+
WGM40 CS40 - TOIE4 - TOV4 DDD7
11+
12+
//CONSTRAINTS
13+
timerNr timerBits counterMax
14+
1 16 65535
15+
16+
WGM4 WGM43 WGM42 WGM41 WGM40 timerMode topValue updateOcrMoment setTovMoment
17+
0 0 0 0 0 Normal 0xFFFF immediate MAX
18+
1 0 0 0 1 PCPWM 0x00FF TOP BOTTOM
19+
2 0 0 1 0 PCPWM 0x01FF TOP BOTTOM
20+
3 0 0 1 1 PCPWM 0x03FF TOP BOTTOM
21+
4 0 1 0 0 CTC OCR4A immediate MAX
22+
5 0 1 0 1 FPWM 0x00FF BOTTOM TOP
23+
6 0 1 1 0 FPWM 0x01FF BOTTOM TOP
24+
7 0 1 1 1 FPWM 0x03FF BOTTOM TOP
25+
8 1 0 0 0 PFCPWM ICR4 BOTTOM BOTTOM
26+
9 1 0 0 1 PFCPWM OCR4A BOTTOM BOTTOM
27+
10 1 0 1 0 PCPWM ICR4 TOP BOTTOM
28+
11 1 0 1 1 PCPWM OCR4A TOP BOTTOM
29+
12 1 1 0 0 CTC ICR4 immediate MAX
30+
13 1 1 0 1 reserved - - -
31+
14 1 1 1 0 FPWM ICR4 TOP TOP
32+
15 1 1 1 1 FPWM OCR4A TOP TOP
33+
34+
COM4A COM4A1 COM4A0 timerMode CompareOutputModeA WGM4 CompareOutputModeB
35+
0 0 0 Normal disconnect * *
36+
1 0 1 Normal toggle * *
37+
2 1 0 Normal clear * *
38+
3 1 1 Normal set * *
39+
0 0 0 CTC disconnect * *
40+
1 0 1 CTC toggle * *
41+
2 1 0 CTC clear * *
42+
3 1 1 CTC set * *
43+
0 0 0 FPWM disconnect * *
44+
1 0 1 FPWM toggle 15 disconnect
45+
2 1 0 FPWM clear-on-match, set-at-max * *
46+
3 1 1 FPWM set-on-match, clear-at-max * *
47+
0 0 0 PCPWM disconnect * *
48+
1 0 1 PCPWM toggle 11 disconnect
49+
2 1 0 PCPWM clear-up, set-down * *
50+
3 1 1 PCPWM set-up, clear-down * *
51+
0 0 0 PFCPWM disconnect * *
52+
1 0 1 PFCPWM toggle 9 disconnect
53+
2 1 0 PFCPWM clear-up, set-down * *
54+
3 1 1 PFCPWM set-up, clear-down * *
55+
56+
COM4B COM4B1 COM4B0 timerMode CompareOutputModeB
57+
0 0 0 Normal disconnect
58+
1 0 1 Normal toggle
59+
2 1 0 Normal clear
60+
3 1 1 Normal set
61+
0 0 0 CTC disconnect
62+
1 0 1 CTC toggle
63+
2 1 0 CTC clear
64+
3 1 1 CTC set
65+
0 0 0 FPWM disconnect
66+
1 0 1 FPWM disconnect
67+
2 1 0 FPWM clear-on-match, set-at-max
68+
3 1 1 FPWM set-on-match, clear-at-max
69+
0 0 0 PCPWM disconnect
70+
1 0 1 PCPWM disconnect
71+
2 1 0 PCPWM clear-up, set-down
72+
3 1 1 PCPWM set-up, clear-down
73+
0 0 0 PFCPWM disconnect
74+
1 0 1 PFCPWM disconnect
75+
2 1 0 PFCPWM clear-up, set-down
76+
3 1 1 PFCPWM set-up, clear-down
77+
78+
CS4 CS42 CS41 CS40 clockPrescalerOrSource ExternalClockInput
79+
1 0 0 1 1 N/A
80+
2 0 1 0 8 N/A
81+
3 0 1 1 64 N/A
82+
4 1 0 0 256 N/A
83+
5 1 0 1 1024 N/A
84+
6 1 1 0 external clock falling edge E1
85+
7 1 1 1 external clock rising edge E1
86+
0 0 0 0 disconnect N/A
87+
88+
OCIE4A interruptA interruptVectorCodeA
89+
0 off //nocode
90+
1 on ISR(TIMER4_COMPA_vect) {\n /* on OCR4A match */\n}
91+
92+
OCIE4B interruptB interruptVectorCodeB
93+
0 off //nocode
94+
1 on ISR(TIMER4_COMPB_vect) {\n /* on OCR4B match */\n}
95+
96+
97+
TOIE4 InterruptOnTimerOverflow interruptVectorCodeOVF
98+
0 off //nocode
99+
1 on ISR(TIMER4_OVF_vect) {\n /* on overflow */\n}
100+
101+
ICIE4 InterruptOnInputCapture interruptVectorCaptureCode
102+
0 off //nocode
103+
1 on ISR(TIMER4_CAPT_vect) {\n /* on input capture */\n}
104+
105+
ICNC4 InputCaptureNoiseSupression
106+
0 off
107+
1 on
108+
109+
ICES4 InputCaptureEdgeSelect
110+
0 falling
111+
1 rising
112+
113+
OCnB_OutputPort
114+
D2
115+
116+
OCnA_OutputPort
117+
D1
118+
119+
CompareOutputModeA OCnA_OutputPort DDD0
120+
disconnect * 0
121+
!disconnect D1 1
122+
123+
CompareOutputModeB OCnB_OutputPort DDB2
124+
disconnect * 0
125+
!disconnect D2 1
126+
127+
ICR4
128+
*
129+
130+
OCR4A
131+
*
132+
133+
OCR4B
134+
*

src/data/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import lgt328p from './lgt328p'
22
import atmega328p from './atmega328p'
3+
import atmega328pb from './atmega328pb'
34
import { MicroControllers } from '../helpers/types'
45
// Timer tables: https://docs.google.com/spreadsheets/d/1VDKsVMj4c5aOxKWu2UroWFAeODwbeVwksYxhjtuEopI/edit#gid=1264839381
56
const timers = {
67
[MicroControllers.LGT8F328P]: lgt328p,
7-
[MicroControllers.ATMEGA328P]: atmega328p
8+
[MicroControllers.ATMEGA328P]: atmega328p,
9+
[MicroControllers.ATMEGA328PB]: atmega328pb
810
}
911

1012
export default timers

src/data/timers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ export const valueDescriptions: Record<string, Record<string, string>> = {
9292
},
9393
topValue: {
9494
ICR1: 'If ICR1 is not used as top, the input capture pin (ICP1) is PB0.\nIf ICR1 is used as top, ICP1 is disconnected. The input compare register is not double-buffered so it will be updated immediatly (and not on TOP or BOTTOM like OCRs). This may make the timer lose a match if changed near it.',
95-
ICR3: 'If ICR3 is not used as top, the input capture pin (ICP3) is PF4.\nIf ICR3 is used as top, ICP3 is disconnected. The input compare register is not double-buffered so it will be updated immediatly (and not on TOP or BOTTOM like OCRs). This may make the timer lose a match if changed near it.'
95+
ICR3: 'If ICR3 is not used as top, the input capture pin (ICP3) is PF4.\nIf ICR3 is used as top, ICP3 is disconnected. The input compare register is not double-buffered so it will be updated immediatly (and not on TOP or BOTTOM like OCRs). This may make the timer lose a match if changed near it.',
96+
ICR4: 'If ICR4 is not used as top, the input capture pin (ICP4) is PE0.\nIf ICR4 is used as top, ICP4 is disconnected. The input compare register is not double-buffered so it will be updated immediatly (and not on TOP or BOTTOM like OCRs). This may make the timer lose a match if changed near it.'
9697
},
9798
OCnA_OutputPort: {
9899
'E4+C0': 'Both at the same time',

src/helpers/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ export enum PanelModes {
2727
}
2828
export enum MicroControllers {
2929
LGT8F328P = 'LGT8F328P',
30-
ATMEGA328P = 'ATMEGA328P'
30+
ATMEGA328P = 'ATMEGA328P',
31+
ATMEGA328PB = 'ATMEGA328PB'
3132
}

0 commit comments

Comments
 (0)