Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
v1.0.1 for up to 64 PWM channels
Browse files Browse the repository at this point in the history
### Release v1.0.1

1. Make `MAX_NUMBER_CHANNELS` configurable to max **64 PWM channels**
2. Remove debug codes possibly causing hang
3. Improve debug to use `Serialx` port automatically according to boards
  • Loading branch information
khoih-prog committed Aug 25, 2022
1 parent c67b7f2 commit fd34060
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void setup()

### Example [ISR_8_PWMs_Array_Complex](examples/ISR_8_PWMs_Array_Complex)

https://github.com/khoih-prog/Dx_Slow_PWM/blob/101fff1255ed660cc1f038ce81fe7e3cb1d2b48e/examples/ISR_8_PWMs_Array_Complex/ISR_8_PWMs_Array_Complex.ino#L16-L497
https://github.com/khoih-prog/Dx_Slow_PWM/blob/c67b7f2fc34fc176788b283e72d4860edadd97d3/examples/ISR_8_PWMs_Array_Complex/ISR_8_PWMs_Array_Complex.ino#L16-L512


---
Expand Down
4 changes: 3 additions & 1 deletion examples/ISR_Modify_PWM/ISR_Modify_PWM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
// These define's must be placed at the beginning before #include "megaAVR_Slow_PWM.h"
// _PWM_LOGLEVEL_ from 0 to 4
// Don't define _PWM_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define _PWM_LOGLEVEL_ 1#if defined(__AVR_AVR128DA48__)
#define _PWM_LOGLEVEL_ 1

#if defined(__AVR_AVR128DA48__)
#define SerialDebug Serial1
#elif defined(__AVR_AVR128DB48__)
#define SerialDebug Serial3
Expand Down
20 changes: 10 additions & 10 deletions src/Dx_Slow_PWM_ISR.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ typedef void (*timer_callback_p)(void *);
#define INVALID_MEGA_AVR_PIN 255

#if !defined(MAX_NUMBER_CHANNELS)
// maximum number of PWM channels
#define MAX_NUMBER_CHANNELS 16
// maximum number of PWM channels
#define MAX_NUMBER_CHANNELS 16
#else
#if (MAX_NUMBER_CHANNELS > 64)
#undef MAX_NUMBER_CHANNELS
#define MAX_NUMBER_CHANNELS 64
#warning Reset too big MAX_NUMBER_CHANNELS to 64
#endif
#endif
#if (MAX_NUMBER_CHANNELS > 64)
#undef MAX_NUMBER_CHANNELS
#define MAX_NUMBER_CHANNELS 64
#warning Reset too big MAX_NUMBER_CHANNELS to 64
#endif
#endif

//////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -200,7 +200,7 @@ class DX_SLOW_PWM_ISR
period = (uint32_t) (1000.0f / frequency);
#endif
PWM_LOGDEBUG1(F("Frequency = "), frequency);
}
else
{
Expand Down
34 changes: 17 additions & 17 deletions src/Dx_Slow_PWM_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,22 @@ typedef enum TCB_CNTMODE_enum
// No TCB_CLKSEL_CLKTCA_gc in DXCore ???
// Don't use 250KHz now
#elif USING_250KHZ
// Optional, but for clarity
// Use Timer A as clock (prescaler 64) => 250KHz
#define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKTCA_gc
#define CLOCK_PRESCALER 64
#error Not OK now. Do not use
// Optional, but for clarity
// Use Timer A as clock (prescaler 64) => 250KHz
#define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKTCA_gc
#define CLOCK_PRESCALER 64
#error Not OK now. Do not use
#else
// Use prescaler 2 => 8MHz
#if (_PWM_LOGLEVEL_ > 2)
#warning Using prescaler 2 => 8MHz
#endif
#define TCB_CLKSEL_VALUE TCB_CLKSEL_DIV2_gc
#define CLOCK_PRESCALER 2
// Use prescaler 2 => 8MHz
#if (_PWM_LOGLEVEL_ > 2)
#warning Using prescaler 2 => 8MHz
#endif
#define TCB_CLKSEL_VALUE TCB_CLKSEL_DIV2_gc
#define CLOCK_PRESCALER 2
#endif

#define CLK_TCB_FREQ ( F_CPU / CLOCK_PRESCALER )
Expand Down Expand Up @@ -583,7 +583,7 @@ void TimerInterrupt::resumeTimer()
TCB4.INTFLAGS = TCB_CAPT_bm;
}

#endif //#ifndef TIMER3_INSTANTIATED
#endif //#if USE_TIMER_3
#endif //#ifndef TIMER4_INSTANTIATED
#endif //#if USE_TIMER_4

#endif // DX_SLOW_PWM_IMPL_H

0 comments on commit fd34060

Please sign in to comment.