#9710 - Domovoi - Thu Aug 14, 2003 5:32 pm
Hmmm... I'm trying to use a count-up timer to scroll a background one pixel every second. The way I figured is setting timer 0 to the F/256 prescaler, and setting timer 1 to countup. That should make timer 1 increment almost every second, right?
It's not going well... I get the feeling I can't zero these timers, or something. Here's what I'm doing:
This should be working, for all I can figure out. However, the background immediately starts scrolling at tremendous speed. I guess REG_TM1CNT_L, for some reason, is never 0, so that it scrolls -every- iteration. But why? It should work like a charm, according to all the docs... What am I missing?
Here's my #defines for the timer registers, just to be sure:
#define REG_TM0CNT_L *(volatile unsigned short*)0x4000100
#define REG_TM0CNT_H *(unsigned short*)0x4000102
#define REG_TM1CNT_L *(volatile unsigned short*)0x4000104
#define REG_TM1CNT_H *(unsigned short*)0x4000106
#define REG_TM2CNT_L *(volatile unsigned short*)0x4000108
#define REG_TM2CNT_H *(unsigned short*)0x400010A
#define REG_TM3CNT_L *(volatile unsigned short*)0x400010C
#define REG_TM3CNT_H *(unsigned short*)0x400010E
Anyone got an idea?
It's not going well... I get the feeling I can't zero these timers, or something. Here's what I'm doing:
Code: |
REG_TM1CNT_H = 0x80 | 0x4; // Set timer 1 to 'start' and 'countup' REG_TM0CNT_H = 0x2 | 0x80; // Set timer 0 to prescale val. F/256 and 'start'. REG_TM0CNT_L = REG_TM1CNT_L = 0; // Zero both timers to be sure.. while (true) // Start the main loop... { if (REG_TM1CNT_L) // If a second has passed, this timer non-zero { REG_TM1CNT_H = 0; // Stop the countup-timer... curPos = MoveBG(curPos + REG_TM1CNT_L); // move the background by the amount of seconds passed (usually 1) REG_TM1CNT_L = 0; // Set the timer back to zero REG_TM1CNT_H = TMR_START | TMR_COUNTUP; // Start the timer again. } } |
This should be working, for all I can figure out. However, the background immediately starts scrolling at tremendous speed. I guess REG_TM1CNT_L, for some reason, is never 0, so that it scrolls -every- iteration. But why? It should work like a charm, according to all the docs... What am I missing?
Here's my #defines for the timer registers, just to be sure:
#define REG_TM0CNT_L *(volatile unsigned short*)0x4000100
#define REG_TM0CNT_H *(unsigned short*)0x4000102
#define REG_TM1CNT_L *(volatile unsigned short*)0x4000104
#define REG_TM1CNT_H *(unsigned short*)0x4000106
#define REG_TM2CNT_L *(volatile unsigned short*)0x4000108
#define REG_TM2CNT_H *(unsigned short*)0x400010A
#define REG_TM3CNT_L *(volatile unsigned short*)0x400010C
#define REG_TM3CNT_H *(unsigned short*)0x400010E
Anyone got an idea?