strange problem with tiny2313

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have made an usb key board with a ft232RL and a tiny2313. the keyboard works well after programming. but when I cycle power at the keyboard it will not work any more.
I have done some testing to find the problem and it looks like that the software is running in the tiny. I see it scanning the keyboard(portb) but there changes nothing at portd when I press a key. I have also tested the principle without the tiny. It then works but then I can only use four keys. The tiny does some multiplexing for the keyboard. I am also not using the usart on both of the chips. all goes by bitlogic.

I do want to program the chip everytime I want to work with the keyboard

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My bet is on a timing issue at power-up. What happends if you power up and then cycle the reset on the AVR?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i have tried that and it will still not work.

here is the code i use.

.org 0x0000
	rjmp init
.org 0x000d
	rjmp scankb
.org 0x0020
lookuptable1:
.db 0b00110100, 0b00101100	//1toets1,2toets2	bitcode
.db 0b00000000, 0b00100100	//3niks,4toets3		00082140
.db 0b00000000, 0b00000000 	//5niks,6niks
.db 0b00000000, 0b00111000	//7niks,8toets4
lookuptable2:
.db 0b00110000, 0b00101000	//1toets5,2toets6	bitcode
.db 0b00000000, 0b00100000	//3niks,4toets7		00082140
.db 0b00000000, 0b00000000 	//5niks,6niks
.db 0b00000000, 0b00011100	//7niks,8toets8
lookuptable3:
.db 0b00010100, 0b00001100	//1toets9,2toets10	bitcode
.db 0b00000000, 0b00000100	//3niks,4toets11	00082140
.db 0b00000000, 0b00000000 	//5niks,6niks
.db 0b00000000, 0b00011000	//7niks,8toets12
lookuptable4:
.db 0b00010000, 0b00001000	//1toets13,2toets14	bitcode
.db 0b00000000, 0b00000000	//3niks,4toets15		00082140
.db 0b00000000, 0b00000000 	//5niks,6niks
.db 0b00000000, 0b00000000	//7niks,niks
init:
ldi r16, low(RAMEND); Main program start
out SPL,r16; Set Stack Pointer to top of ram
ldi temp, 0b11110000 // toetsenbord poort instellen. spi pinnen worden output om 
out ddrb,temp //storing te verminderen
ldi temp, 0b00111100 // define output to pc
out portd,temp
out ddrd, temp
ldi temp, 0b00000010 // timer instellen
out tccr0a,temp
ldi temp, 0b00000100 // prescaler op 256
out tccr0b, temp
ldi temp, 254
out ocr0a, temp
ldi temp, 0b00000001
out timsk, temp		// timer interupt mask instellen op oc 0 a
sei					// vanaf nu reageren op interupts
doeniks:
nop
rjmp doeniks
scankb:
//rij1
ldi zl, lookuptable1*2-1
ldi scanpatroon , 0b11101111	//scan patroon for row 1, pullups aan
rijen:

out portb, scanpatroon
nop
in temp, pinb
cp temp, scanpatroon	// vergelijken met gestuurd patroon
brne toetsingedrukt
subi zl,-8
sec
rol scanpatroon			// patroon vershuiven
brcs rijen
ldi uitgang, 0b00111100
out portd, uitgang
reti
toetsingedrukt:
com temp				//invert because of pullups
andi temp, 0b00001111	// only last nibble is important for 
add zl, temp			// lookup table
lpm uitgang,z
out portd, uitgang
reti

I have one led conected to the rts pin at the ft232rl and i noticed that it blinks several times at startup. i could make same sort of time out at the beginning of the program

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe the watch dog timer is inadvertently becoming enabled?

The data sheet states:

Quote:
If the Watchdog is accidentally enabled, for example by a runaway pointer or brown-out condition, the device will be reset and the Watchdog Timer will stay enabled. If the code is not set up to handle the Watchdog, this might lead to an eternal loop of time-out resets. To avoid this situation, the application software should always clear the Watchdog System Reset Flag (WDRF) and the WDE control bit in the initialisation routine, even if the Watchdog is not in use.
When you power cycle your board, it is possible that VCC to the AVR does not go low enough to do a full power on reset and the watchdog timer may not be disabled. For example, there may be current from the USB 5V supply that makes it to the AVR supply.

Although, if it is the watchdog causing the problem, I would expect it to at least work sometimes. It's still worth a check and regardless, you should always ensure the watchdog gets disabled on power up (or actually use it in your program). I learned this one the hard way myself.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have disabled the brownout (was enabled) and made sure that the watchdog is not running. but it still has the same problem.

i have changed the code a bit so that i can see when it resets. as far as i can tell it does not reset in normal operation, but it will not work either

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
lpm uitgang,z

this may be unrelated, but what is in ZH when you do this? Unless I'm overlooking something, I don't see ZH cleared anywhere, so ZH could be anything. Clear ZH so you don't end up reading some unwanted flash address (most likely erased flash in this case- 0xFF's).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

curtvm wrote:

lpm uitgang,z

this may be unrelated, but what is in ZH when you do this? Unless I'm overlooking something, I don't see ZH cleared anywhere, so ZH could be anything. Clear ZH so you don't end up reading some unwanted flash address (most likely erased flash in this case- 0xFF's).


looks that this was the trick. Zh is now cleared every time I scan the keyboard and its works perfectly.

I assumed that all registers where reset every time at start up. For some reason this not happens at normal powerup. Next time I make sure that every register I use has a defined value and not the reset value.

thanks for the help