help with pin-change int

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

I'm setting my pin-change int like so, then I wait.

PCICR = (1<<PCIE1);// watch PORTC.5 
PCMSK1 = (1<<PCINT12);
_delay_us(60);

The trouble I'm having is that it fires once right off the bat. The pin its watching is set high a ways before hand. It fires thinking its change? then does not fire again until it does change. Is there a way to init the vale of 1 so it does not think it changed?

Visual aid.

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

As with many of the "trigger" bits, they can be set based on the event, and not when you are watching them. ;)

So the bit might have been set earlier. typically, you manually clear the bit before enabling the interrupt. Or, if you need to prevent a race then have global interrupts turned off during the set of the __IE bit and the write (usually 1) to the corresponding __IF. Others will need to post the bulletproof sequence as I have never cared about the race.

Lee

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

You only want the IRQ on the -ve transition. So the ISR() returns immediately on a +ve transition pin-change.

You have to identify a pin-change in the first place. You also have to do something with the intervening +ve transitions. (most of which take place while the ISR() is processing)

David.

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

theusch, right I was not thinking that through.. Should have known that..

Hi, David. Yes your right just need some adjustments for debugging and understanding. The controllers vary in production and that lead-in is not always the same. The Code worked perfect but I need to simplify a few things to see what cause some of the undesired very seldom results.

BTW, the lengths varies on controller to controller but not by much, only a few nanosecond. But in time some controllers drift past my reads so I did this.

	//adjuster
	sbic	PINx,SCKB;
	rjmp	adjust1;//take a bit of extra time.
	adjust1:
	sbic	PINx,SCKA		;D6
	sec
	rol		r18
...

If it does not see the drop it guesses its not in the right place and adjust, works like a charm..