TINY20 pin pullup

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

HI,

 

I am having trouble with a tiny20 implementation. A stock piece of code I've used before is failing on the 20.  It is a button debounce/handler. It reads a pin with a button attached and processes it.  My code sees the first button hit but then ignores more hits.  I am wondering if I have the pin input thing set up right, seeing as how it changed and the datasheet does not fill me with confidence. Here is the init code:

	// set up pins
	/* enable the pull-up function */
	PUEA = 0x30;
	PORTA = 0x30;	// PA 4-5 pullups
	DDRA = 0xCF;	// PA 0-3,6-7 outputs, 4-5 inputs
	DDRB  = 0x07; 	// PB 0-1-2 outs

I cannot debug as they changed it again and one wire debug is not available on the tiny20.

 

Thanks!

Tim Ressel
Portland, OR
timr@earthling.net

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

The first test is a sanity check -- what voltage is right at the AVR pin(s) when running the tests?

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

madhun wrote:
...they changed it again...

???

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Why did you choose the T20 if you need in circuit debug i.e. debug-wire?  Would a T24 be a better match?

 

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

The input pins .. PA4 and PA5 .. are connected to pushbuttons that go to ground. The Tiny20 provides the pullup. The levels on these pins are fine. The issue is inside the proc. I was wondering if I had set up the input pins correctly.

Tim Ressel
Portland, OR
timr@earthling.net

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

The input pins .. PA4 and PA5 .. are connected to pushbuttons that go to ground. The Tiny20 provides the pullup. The levels on these pins are fine.

When you say 'fine'?  What does that mean?  And how did you determine it is so?

 

For me, 'fine' would only be if my multimeter measures VCC (or nearly) with the button released, and 0V (or nearly) with the button pressed.  I'd expect the DMM to return to VCC when the button was again released.  Is this what you're seeing? 

 

If 'yes', then obviously you:

had set up the input pins correctly.

 

If your code is 'not working', I'd look elsewhere.

 

 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

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

I scoped the pins and pushed the buttons. The levels are as expected.

Tim Ressel
Portland, OR
timr@earthling.net

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

There are two kinds of push-switch debouncers.  One causes an interrupt when the first active edge of the push action happens.  It then (sometimes) waits about 15 milliseconds and checks the input line again.   Then it sets a volatile boolean flag for the main code that indicates that an active-push down event happened. Then it exits the interrupt.

 

The other switch routine samples the switch about 15 times a second.  The new sample is compared to the previous one.  If it is different, then it sets that old volatile boolean flag for the main code that indicates that an active-push down event happened.

 

Which type are you using?

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

Um, neither. I use a 6mS interrupt to sample the input pin and stuff the value into an 8-bit shift register: low means button pushed, high means not. Then the shift register has all zeros then a valid button press is detected and processed. My library issues button up, down, and hold events for multiple buttons.

 

--tr

Tim Ressel
Portland, OR
timr@earthling.net

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

It turns out the pins are fine. The problem lies elsewhere. Namely, when I enable SPI everything stops.

Tim Ressel
Portland, OR
timr@earthling.net