aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hwdef-Noctigon_K9.3.h82
1 files changed, 48 insertions, 34 deletions
diff --git a/hwdef-Noctigon_K9.3.h b/hwdef-Noctigon_K9.3.h
index feb49e6..15f93cb 100644
--- a/hwdef-Noctigon_K9.3.h
+++ b/hwdef-Noctigon_K9.3.h
@@ -1,16 +1,16 @@
-#ifndef HWDEF_NOCTIGON_KR4_H
-#define HWDEF_NOCTIGON_KR4_H
+#ifndef HWDEF_NOCTIGON_K93_H
+#define HWDEF_NOCTIGON_K93_H
-/* Noctigon KR4 / D4V2.5 driver layout (attiny1634)
+/* Noctigon K9.3 driver layout (attiny1634)
*
* Pin / Name / Function
- * 1 PA6 FET PWM (direct drive) (PWM1B)
+ * 1 PA6 2nd LED PWM (linear) (PWM1B)
* 2 PA5 R: red aux LED (PWM0B)
* 3 PA4 G: green aux LED
* 4 PA3 B: blue aux LED
- * 5 PA2 button LED (D4V2.5 only)
- * 6 PA1 (none)
- * 7 PA0 (none)
+ * 5 PA2 button LED
+ * 6 PA1 Opamp 2 enable (2nd LEDs)
+ * 7 PA0 Opamp 1 enable (main LEDs)
* 8 GND GND
* 9 VCC VCC
* 10 PC5 (none)
@@ -18,12 +18,12 @@
* 12 PC3 RESET
* 13 PC2 (none)
* 14 PC1 SCK
- * 15 PC0 (none) PWM0A
+ * 15 PC0 main LED PWM (FET) (PWM0A)
* 16 PB3 main LED PWM (linear) (PWM1A)
- * 17 PB2 MISO / e-switch (PCINT10)
+ * 17 PB2 MISO
* 18 PB1 MOSI / battery voltage (ADC6)
- * 19 PB0 Opamp power
- * 20 PA7 (none)
+ * 19 PB0 (none)
+ * 20 PA7 e-switch (PCINT7)
* ADC12 thermal sensor
*
* Main LED power uses one pin to turn the Opamp on/off,
@@ -40,30 +40,31 @@
#define ATTINY 1634
#include <avr/io.h>
-#define PWM_CHANNELS 2
+#define PWM_CHANNELS 2 // 3 actually, but only 2 for main LEDs
#define PWM_BITS 10 // 0 to 1023 at 4 kHz, not 0 to 255 at 16 kHz
#define PWM_TOP 1023
-#define SWITCH_PIN PB2 // pin 17
-#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt
-#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8]
-#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8]
-#define SWITCH_PORT PINB // PINA or PINB or PINC
-#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8]
-
-// the button tends to short out the voltage divider,
-// so ignore voltage while the button is being held
-//#define NO_LVP_WHILE_BUTTON_PRESSED
-
+#define SWITCH_PIN PA7 // pin 20
+#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt
+#define SWITCH_PCIE PCIE0 // PCIE1 is for PCINT[7:0]
+#define SWITCH_PCMSK PCMSK0 // PCMSK1 is for PCINT[7:0]
+#define SWITCH_PORT PINA // PINA or PINB or PINC
+#define PCINT_vect PCINT0_vect // ISR for PCINT[7:0]
#define PWM1_PIN PB3 // pin 16, Opamp reference
#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3
-#define PWM2_PIN PA6 // pin 1, DD FET PWM
-#define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6
+#define PWM2_PIN PC0 // pin 15, DD FET PWM
+#define PWM2_LVL OCR0A // OCR0A is the output compare register for PC0
+
+#define PWM3_PIN PA6 // pin 1, 2nd LED Opamp reference
+#define PWM3_LVL OCR1B // OCR1B is the output compare register for PA6
-#define LED_ENABLE_PIN PB0 // pin 19, Opamp power
-#define LED_ENABLE_PORT PORTB // control port for PB0
+#define LED_ENABLE_PIN PA0 // pin 7, Opamp power
+#define LED_ENABLE_PORT PORTA // control port for PA0
+
+#define LED2_ENABLE_PIN PA1 // pin 6, Opamp power
+#define LED2_ENABLE_PORT PORTA // control port for PA1
#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened
@@ -113,20 +114,21 @@
// ... so just hardcode it in each hwdef file instead
inline void hwdef_setup() {
// enable output ports
- // Opamp level and Opamp on/off
- DDRB = (1 << PWM1_PIN)
- | (1 << LED_ENABLE_PIN);
- // DD FET PWM, aux R/G/B, button LED
- DDRA = (1 << PWM2_PIN)
+ DDRC = (1 << PWM2_PIN);
+ DDRB = (1 << PWM1_PIN);
+ DDRA = (1 << PWM3_PIN)
| (1 << AUXLED_R_PIN)
| (1 << AUXLED_G_PIN)
| (1 << AUXLED_B_PIN)
| (1 << BUTTON_LED_PIN)
+ | (1 << LED_ENABLE_PIN);
+ | (1 << LED2_ENABLE_PIN);
;
// configure PWM
// Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter
// pre-scale for timer: N = 1
+ // Linear opamp PWM for both main and 2nd LEDs (10-bit)
// WGM1[3:0]: 0,0,1,1: PWM, Phase Correct, 10-bit (DS table 12-5)
// CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6)
// COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4)
@@ -139,9 +141,21 @@ inline void hwdef_setup() {
| (0<<WGM13) | (0<<WGM12) // phase-correct PWM (DS table 12-5)
;
+ // FET PWM (8-bit; this channel can't do 10-bit)
+ // WGM0[2:0]: 0,0,1: PWM, Phase Correct, 8-bit (DS table 11-8)
+ // CS0[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 11-9)
+ // COM0A[1:0]: 1,0: PWM OC0A in the normal direction (DS table 11-4)
+ // COM0B[1:0]: 1,0: PWM OC0B in the normal direction (DS table 11-7)
+ TCCR0A = (0<<WGM01) | (1<<WGM00) // 8-bit (TOP=0xFF) (DS table 11-8)
+ | (1<<COM0A1) | (0<<COM0A0) // PWM 0A in normal direction (DS table 11-4)
+ //| (1<<COM0B1) | (0<<COM0B0) // PWM 0B in normal direction (DS table 11-7)
+ ;
+ TCCR0B = (0<<CS02) | (0<<CS01) | (1<<CS00) // clk/1 (no prescaling) (DS table 11-9)
+ | (0<<WGM02) // phase-correct PWM (DS table 11-8)
+ ;
+
// set up e-switch
- //PORTB = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC?
- PUEB = (1 << SWITCH_PIN); // pull-up for e-switch
+ PUEA = (1 << SWITCH_PIN); // pull-up for e-switch
SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt
}
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.