From ccda11dced208ffa9c9b065210c1264dcf1bcfbd Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 12 Aug 2021 03:07:17 -0600 Subject: changed Noctigon KR4 from fixed to dynamic PWM TOP value, for later use --- hwdef-Noctigon_KR4.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'hwdef-Noctigon_KR4.h') diff --git a/hwdef-Noctigon_KR4.h b/hwdef-Noctigon_KR4.h index feb49e6..58492ac 100644 --- a/hwdef-Noctigon_KR4.h +++ b/hwdef-Noctigon_KR4.h @@ -62,6 +62,10 @@ #define PWM2_PIN PA6 // pin 1, DD FET PWM #define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6 +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM +#define PWM2_TOP ICR1 // holds the TOP value for for variable-resolution PWM + #define LED_ENABLE_PIN PB0 // pin 19, Opamp power #define LED_ENABLE_PORT PORTB // control port for PB0 @@ -131,14 +135,17 @@ inline void hwdef_setup() { // 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) // COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4) - TCCR1A = (1< #define PWM_CHANNELS 2 -#define PWM_BITS 10 // 0 to 1023 at 4 kHz, not 0 to 255 at 16 kHz -#define PWM_TOP 1023 +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed #define SWITCH_PIN PB2 // pin 17 #define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt @@ -58,13 +59,13 @@ #define PWM1_PIN PB3 // pin 16, Opamp reference #define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase #define PWM2_PIN PA6 // pin 1, DD FET PWM #define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6 // PWM parameters of both channels are tied together because they share a counter #define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM -#define PWM2_TOP ICR1 // holds the TOP value for for variable-resolution PWM #define LED_ENABLE_PIN PB0 // pin 19, Opamp power #define LED_ENABLE_PORT PORTB // control port for PB0 @@ -144,7 +145,7 @@ inline void hwdef_setup() { ; // set PWM resolution - PWM1_TOP = 1023; + PWM1_TOP = PWM_TOP; // set up e-switch //PORTB = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC? -- cgit v1.2.3