ATtiny45 alternate port function pin question

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

I think the ATtiny45 might work in an application, but I have not obtained one to try out yet. I did not see anything in the data sheet that answers this question. It would save me some design time if I could get an answer.

When Timer1 GTCCR register bits COM1B1=0 and COM1B0=1 (toggle OC1B), it activates two compare pin alternate functions for OC1B (PB4 pin 3) and inverted OC1B (PB3 pin 2). Pin 3 PB4 will be enabled as an output to use OC1B. Does pin 2 PB3 still function correctly as an input PB3 port or does the alternate pin function prevent this?

I need to use the Timer1 OC1B output, but there are so few pins on this device I cannot afford to loose the use of another pin just because COM1B1:0 activated the alternate pin function. If I cannot use pin 2 PB3 as in input then I cannot use the Attiny45 for this application. Thanks in advance.

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

I believe that if you set the PB3 to be an input [Data Direction Register bit 3 at logic 0], then the pin can be used as an input by reading the PINB register. Check the data sheet in the timer section for OC1B. If it says that the data direction register must be set to output for the toggle function to work, then I would assume that you could one of the pins as an input. If you know electronic symbols, then check the diagram in the section for the in/out ports. On the AVR, the output section can be switched off and the electrical level on the pin can be read directly. In that case the timer can be sending signals to the port but they won't reach the actual pin.
So I'm 95% sure that you can use this pin as an input while the other pin is toggling under the control of the timer.

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

That is a non-PWM, or "normal" mode, right? From the datasheet:

Quote:
The inverted PWM outputs OC1A and OC1B are not connected in normal mode.

and
Quote:
• Bits 5,4 - COM1B1, COM1B0: Comparator B Output Mode, Bits 1 and 0

The COM1B1 and COM1B0 control bits determine any output pin action following a compare match with compare register B in Timer/Counter1. Output pin actions affect pin PB4 (OC1B). Since this is an alternative function to an I/O port, the corresponding direction control bit must be set (one) in order to control an output pin. Note that [bar] OC1B is not connected in normal mode.

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

Duh :oops: I missed it. Yes I can use normal mode, which means I certainly can use this part. Thank you both very much for the help.

Mike

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

There sure are a lot of subsystems and alternate functions packed into that line of chips. It makes the functional layout quie interesting.

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

I've never had the opportunity to use the exact type of timer as the ATtiny45V Timer1 before (so far I've only used the standard ATmega timers). The more in depth I read about it, the more I respect its capabilities.

I agree. It is a bit of a tangled web to sort out which of the many possible combinations of functions can coexist on only 6 pins.

Its a good thing this chip will work for me since I really want the sleeping BOD.

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

I've used the tiny45 for a few projects. One of the most important things I've found is to make sure that none of the alternate functions are enabled by default. I found this on a couple of them and it caused a few problems

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

Quote:

One of the most important things I've found is to make sure that none of the alternate functions are enabled by default. I found this on a couple of them and it caused a few problems

??? Example please?

Quote:
Table 12-3. Port B Pins Alternate Functions
Port Pin Alternate Function
PB5 RESET / dW / ADC0 / PCINT5(1)
PB4 XTAL2 / CLKO / ADC2 / OC1B / PCINT4(2)
PB3 XTAL1 / CLKI / ADC3 / OC1B / PCINT3(3)
PB2 SCK / ADC1 / T0 / USCK / SCL / INT0 / PCINT2(4)
PB1 MISO / AIN1 / OC0B / OC1A / DO / PCINT1(5)
PB0 MOSI / AIN0 / OC0A / OC1A / DI / SDA / AREF / PCINT0(6)

I can't think of how any of these could be "enabled by default", except Analog Comparator ACD and this shouldn't interfere unless you are searching for uA.

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.