Skip to content

Commit

Permalink
Fixing timing problems
Browse files Browse the repository at this point in the history
  • Loading branch information
NeroReflex committed Jun 26, 2018
1 parent 789fe33 commit 2e978ef
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
2 changes: 2 additions & 0 deletions cores/freertos/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,6 @@ to exclude the API function. */
#define INCLUDE_xTaskGetCurrentTaskHandle 0
#define INCLUDE_uxTaskGetStackHighWaterMark 1

#define configTICK_RATE_HZ 66

#endif /* FREERTOS_CONFIG_H */
43 changes: 15 additions & 28 deletions cores/freertos/FreeRTOSVariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,21 @@
extern "C" {
#endif

#ifndef configTICK_RATE_HZ
#if defined ( portUSE_WDT )
/* Watchdog period options:
WDTO_15MS
WDTO_30MS
WDTO_60MS
WDTO_120MS
WDTO_250MS
WDTO_500MS
*/
// System Tick - Scheduler timer
// Use the Watchdog timer, and choose the rate at which scheduler interrupts will occur.
#define portUSE_WDTO WDTO_15MS // portUSE_WDTO to use the Watchdog Timer for xTaskIncrementTick


// xxx Watchdog Timer is 128kHz nominal, but 120 kHz at 5V DC and 25 degrees is actually more accurate, from data sheet.
#define configTICK_RATE_HZ ( (TickType_t)( (uint32_t)128000 >> (portUSE_WDTO + 11) ) ) // 2^11 = 2048 WDT scaler for 128kHz Timer
#elif defined ( portUSE_TIMER3 )
// portUSE_TIMER3 to use 16 bit Timer3
#define configTICK_RATE_HZ ( ( TickType_t ) 500 ) // Use 500Hz for TIMER3
// Use 1000Hz to get mSec timing.
#elif defined ( portUSE_TIMER0 )
// portUSE_TIMER0 to use 8 bit Timer0
#define configTICK_RATE_HZ ( ( TickType_t ) 200 ) // Use 200Hz for TIMER0 and 400Hz for TIMER1
// Use 1000Hz to get mSec timing.
#else
#error "Undefined configTICK_RATE_HZ macro, please, define HERE your own"
#endif
#if !defined( configTICK_RATE_HZ ) && defined ( portUSE_WDT )
/* Watchdog period options:
WDTO_15MS
WDTO_30MS
WDTO_60MS
WDTO_120MS
WDTO_250MS
WDTO_500MS
*/
// System Tick - Scheduler timer
// Use the Watchdog timer, and choose the rate at which scheduler interrupts will occur.
#define portUSE_WDTO WDTO_15MS // portUSE_WDTO to use the Watchdog Timer for xTaskIncrementTick

// xxx Watchdog Timer is 128kHz nominal, but 120 kHz at 5V DC and 25 degrees is actually more accurate, from data sheet.
#define configTICK_RATE_HZ ( (TickType_t)( (uint32_t)128000 >> (portUSE_WDTO + 11) ) ) // 2^11 = 2048 WDT scaler for 128kHz Timer
#endif // configTICK_RATE_HZ

/*-----------------------------------------------------------*/
Expand Down
3 changes: 3 additions & 0 deletions cores/freertos/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@

#endif

#if !defined( configTICK_RATE_HZ )
#error "Tick-rate must be defined"
#endif
/*-----------------------------------------------------------*/

/* We require the address of the pxCurrentTCB variable, but don't want to know
Expand Down
4 changes: 2 additions & 2 deletions cores/freertos/portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
#define PORTABLE_H

#if !defined( portUSE_TIMER0 ) && !defined( portUSE_TIMER1 ) && !defined( portUSE_TIMER2 ) && !defined( portUSE_TIMER3 ) && !defined( portUSE_WDT )
#if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
#define portUSE_TIMER3 1
#if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined (__AVR_ATmega328__)
#define portUSE_TIMER0 1
#else
#define portUSE_WDT 1
#endif
Expand Down

0 comments on commit 2e978ef

Please sign in to comment.