Skip to content

Commit

Permalink
More precise delays (issue #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
wagiminator committed Nov 19, 2023
1 parent 07a32bf commit 1252417
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 62 deletions.
Binary file modified picoAVR_Programmer/software/picoavr.bin
Binary file not shown.
32 changes: 16 additions & 16 deletions picoAVR_Programmer/software/src/delay.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// ===================================================================================
// Delay Functions for CH551, CH552 and CH554
// Delay Functions for CH551, CH552 and CH554 * v1.1 *
// ===================================================================================

#include "delay.h"
#include "ch554.h"

// ===================================================================================
// Delay in Units of us
Expand All @@ -22,40 +21,40 @@ void DLY_us(uint16_t n) { // delay in us
#endif

while(n) { // total = 12~13 Fsys cycles, 1uS @Fsys=12MHz
SAFE_MOD++; // 2 Fsys cycles, for higher Fsys, add operation here
__asm__("inc _SAFE_MOD"); // 2 Fsys cycles, for higher Fsys, add operation here
#ifdef F_CPU
#if F_CPU >= 14000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 16000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 18000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 20000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 22000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 24000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 26000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 28000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 30000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 32000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#endif
n--;
--n;
}
}

Expand All @@ -64,7 +63,8 @@ void DLY_us(uint16_t n) { // delay in us
// ===================================================================================
void DLY_ms(uint16_t n) { // delay in ms
while(n) {
DLY_us(1000);
n--;
while(!(TKEY_CTRL & bTKC_IF));
while(TKEY_CTRL & bTKC_IF);
--n;
}
}
3 changes: 2 additions & 1 deletion picoAVR_Programmer/software/src/delay.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// ===================================================================================
// Delay Functions for CH551, CH552 and CH554
// Delay Functions for CH551, CH552 and CH554 * v1.1 *
// ===================================================================================

#pragma once
#include <stdint.h>
#include "ch554.h"

void DLY_us(uint16_t n); // delay in units of us
void DLY_ms(uint16_t n); // delay in units of ms
Binary file modified picoISP_Programmer/software/picoasp/picoasp.bin
Binary file not shown.
27 changes: 13 additions & 14 deletions picoISP_Programmer/software/picoasp/src/delay.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// ===================================================================================
// Delay Functions for CH551, CH552 and CH554
// Delay Functions for CH551, CH552 and CH554 * v1.1 *
// ===================================================================================

#include "delay.h"
#include "ch554.h"

// ===================================================================================
// Delay in Units of us
Expand All @@ -22,39 +21,39 @@ void DLY_us(uint16_t n) { // delay in us
#endif

while(n) { // total = 12~13 Fsys cycles, 1uS @Fsys=12MHz
SAFE_MOD++; // 2 Fsys cycles, for higher Fsys, add operation here
__asm__("inc _SAFE_MOD"); // 2 Fsys cycles, for higher Fsys, add operation here
#ifdef F_CPU
#if F_CPU >= 14000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 16000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 18000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 20000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 22000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 24000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 26000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 28000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 30000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 32000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#endif
n--;
--n;
}
}
3 changes: 2 additions & 1 deletion picoISP_Programmer/software/picoasp/src/delay.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// ===================================================================================
// Delay Functions for CH551, CH552 and CH554
// Delay Functions for CH551, CH552 and CH554 * v1.1 *
// ===================================================================================

#pragma once
#include <stdint.h>
#include "ch554.h"

void DLY_us(uint16_t n); // delay in units of us
Binary file modified picoISP_Programmer/software/picoisp/picoisp.bin
Binary file not shown.
27 changes: 13 additions & 14 deletions picoISP_Programmer/software/picoisp/src/delay.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// ===================================================================================
// Delay Functions for CH551, CH552 and CH554
// Delay Functions for CH551, CH552 and CH554 * v1.1 *
// ===================================================================================

#include "delay.h"
#include "ch554.h"

// ===================================================================================
// Delay in Units of us
Expand All @@ -22,39 +21,39 @@ void DLY_us(uint16_t n) { // delay in us
#endif

while(n) { // total = 12~13 Fsys cycles, 1uS @Fsys=12MHz
SAFE_MOD++; // 2 Fsys cycles, for higher Fsys, add operation here
__asm__("inc _SAFE_MOD"); // 2 Fsys cycles, for higher Fsys, add operation here
#ifdef F_CPU
#if F_CPU >= 14000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 16000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 18000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 20000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 22000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 24000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 26000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 28000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 30000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 32000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#endif
n--;
--n;
}
}
3 changes: 2 additions & 1 deletion picoISP_Programmer/software/picoisp/src/delay.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// ===================================================================================
// Delay Functions for CH551, CH552 and CH554
// Delay Functions for CH551, CH552 and CH554 * v1.1 *
// ===================================================================================

#pragma once
#include <stdint.h>
#include "ch554.h"

void DLY_us(uint16_t n); // delay in units of us
Binary file modified picoISP_Programmer/software/picostk/picostk.bin
Binary file not shown.
27 changes: 13 additions & 14 deletions picoISP_Programmer/software/picostk/src/delay.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// ===================================================================================
// Delay Functions for CH551, CH552 and CH554
// Delay Functions for CH551, CH552 and CH554 * v1.1 *
// ===================================================================================

#include "delay.h"
#include "ch554.h"

// ===================================================================================
// Delay in Units of us
Expand All @@ -22,39 +21,39 @@ void DLY_us(uint16_t n) { // delay in us
#endif

while(n) { // total = 12~13 Fsys cycles, 1uS @Fsys=12MHz
SAFE_MOD++; // 2 Fsys cycles, for higher Fsys, add operation here
__asm__("inc _SAFE_MOD"); // 2 Fsys cycles, for higher Fsys, add operation here
#ifdef F_CPU
#if F_CPU >= 14000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 16000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 18000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 20000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 22000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 24000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 26000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 28000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 30000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#if F_CPU >= 32000000
SAFE_MOD++;
__asm__("inc _SAFE_MOD");
#endif
#endif
n--;
--n;
}
}
3 changes: 2 additions & 1 deletion picoISP_Programmer/software/picostk/src/delay.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// ===================================================================================
// Delay Functions for CH551, CH552 and CH554
// Delay Functions for CH551, CH552 and CH554 * v1.1 *
// ===================================================================================

#pragma once
#include <stdint.h>
#include "ch554.h"

void DLY_us(uint16_t n); // delay in units of us

0 comments on commit 1252417

Please sign in to comment.