Enabling OC1B output on a Tiny85.

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

With regular Mega or Tinys,   you just make DDRx.y an output for an OCnx pin,   and set the COMnxy bits for your specific output mode.

 

OC1A and OC0A seem to work like this on a Tiny85.    But although I can see bits changing in the debug IO view,   there is no output on OC1B.

 

The TIMER1_COMPB interrupt is generated and serviced normally.

The COM bits are normal.

The Fuses are set for "Internal 8MHz RC" so both PB3 and PB4(OC1B) pins are available to the outside world.

 

Help.    I must have missed something in the "Alternate Function for PB4",    but I can't see what.

 

David.

Last Edited: Fri. Sep 19, 2014 - 03:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm sure you've never posted this before:  "Show a complete test program that demonstrates the symptoms."  ;)  wink

 

"...I/O view..." -- simulator or debugWire?

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
/*
 * OC1B_t85.c
 *
 * Created: 19/09/2014 18:43:48
 * Author: David Prentice
 */

#include <io.h>
#define F_CPU _MCU_CLOCK_FREQUENCY_

void main(void)
{
/*
    // this flashes nOC1B @ 1.0Hz.   OC1B is 0V output.
    DDRB |= (1<<DDB4);               // make OC1B pin output
    DDRB |= (1<<DDB3);               // make nOC1B pin output
    GTCCR = (1<<COM1B0);             // toggle in CTC mode
    TCCR1 = (1<<CTC1)|(15 << CS10);  // CTC, div16384
    OCR1C = F_CPU/16384/2/1 - 1;     // togge 1Hz. OCR1C = 243 @ F_CPU=8MHz
*/
/*
    // this flashes OC1A @ 1.0Hz.   nOC1A is 0V output.
    DDRB |= (1<<DDB1);               // make OC1A pin output
    DDRB |= (1<<DDB0);               // make nOC1A pin output
    TCCR1 = (1<<COM1A0);             // toggle in CTC mode
    TCCR1 |= (1<<CTC1)|(15 << CS10); // CTC, div16384
    OCR1C = F_CPU/16384/2/1 - 1;     // togge 1Hz. OCR1C = 243 @ F_CPU=8MHz
*/

    // this flashes nOC1B @ 0.95Hz.   OC1B is 0V output.
    DDRB |= (1<<DDB4);        // make OC1B pin output
    DDRB |= (1<<DDB3);        // make nOC1B pin output
    GTCCR = (1<<COM1B0);      // toggle in CTC mode
    TCCR1 = (15 << CS10);     // div16384.  just overflow @ 0.953Hz

    while (1) {
        // Please write your application code here
    }
}

I can't make anything simpler than this.    The actual place where I noticed the problem was a Soft UART with TX on PB4.

Other implementations with TX on OC1A or OC0A worked as expected.   I was using regular non-CTC mode with COMPB (and COMPA)

matches.

 

I am sure that this is something to do with setting the correct "Alternate Function".    But I have not understood how.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
GTCCR = (1<<COM1B0);      // toggle in CTC mode

But you haven't set CTC mode, you are in Normal mode, right?  (with the posted uncommented-out code)

 

Let's see what CodeVision Wizard makes of this...

 

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 1.953 kHz
// Mode: Normal top=0xFF
// OC1A output: Disconnected
// OC1B output: Toggle on compare match
// Timer Period: 0.13107 s
// Output Pulse(s):
// OC1B Period: 0.26214 s Width: 0.13107 s
// Timer1 Overflow Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
PLLCSR=(0<<PCKE) | (0<<PLLE) | (0<<PLOCK);

TCCR1=(0<<CTC1) | (0<<PWM1A) | (0<<COM1A1) | (0<<COM1A0) | (1<<CS13) | (1<<CS12) | (0<<CS11) | (1<<CS10);
GTCCR=(0<<TSM) | (0<<PWM1B) | (0<<COM1B1) | (1<<COM1B0) | (0<<PSR1) | (0<<PSR0);
TCNT1=0x00;
OCR1A=0x00;
OCR1B=0x00;
OCR1C=0x00;

Looks like your code.  (after making PB4 an output)  :(

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

27.2 Errata ATtiny45

...

27.2.3 Rev B and C
• PLL not locking
• EEPROM read from application code does not workin Lock Bit Mode 3
• EEPROM read may fail at low supplyvoltage / low clock frequency
Timer Counter 1 PWM output generation on OC1B- XOC1B does not work correctly

...

4. Timer Counter 1 PWM output generation on OC1B – XOC1B does not work correctly
Timer Counter1 PWM output OC1B-XOC1B does not work correctly. Only in the case when
the control bits, COM1B1 and COM1B0 are in the same mode as COM1A1 and COM1A0,
respectively, the OC1B-XOC1B output works correctly.
Problem Fix/Work around
The only workaround is to use same control setting on COM1A[1:0] and COM1B[1:0] control
bits, see table 14-4 in the data sheet. The problem has been fixed for Tiny45 rev D.

 

27.3 Errata ATtiny85

...

 [does NOT have the same paragraph]

Sure sounds like your symptoms.

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

It's a know erratum.

https://www.avrfreaks.net/forum/a...

 

EDIT: walked away to get a coffee and Lee had already answered ;)

"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]

 

Last Edited: Fri. Sep 19, 2014 - 06:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

EDIT: walked away to get a coffee and Lee had already answered ;)

I seemed to remember that discussion, but was unable to search it out on the new site.  I was just going to go to "legacy" when you posted.

 

 

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 just put attiny85 errata the new site's search bar.  I'm impressed that it turned up.  Every other search I've tried has been pointless.

 

"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
void main(void)
{
/*
    // this flashes nOC1B @ 1.0Hz.   OC1B is 0V output.  no difference
    DDRB |= (1<<DDB4);               // make OC1B pin output
    DDRB |= (1<<DDB3);               // make nOC1B pin output
    GTCCR = (1<<COM1B0);             // toggle in CTC mode
    TCCR1 = (1<<COM1A0);             // copy the COM settings
    TCCR1 |= (1<<CTC1)|(15 << CS10);  // CTC, div16384
    OCR1C = F_CPU/16384/2/1 - 1;     // togge 1Hz. OCR1C = 243 @ F_CPU=8MHz
*/

    // this flashes OC1A @ 1.0Hz.   nOC1A is 0V output.  no difference
    DDRB |= (1<<DDB1);               // make OC1A pin output
    DDRB |= (1<<DDB0);               // make nOC1A pin output
    TCCR1 = (1<<COM1A0);             // toggle in CTC mode
    GTCCR = (1<<COM1B0);             // copy the COM settings
    TCCR1 |= (1<<CTC1)|(15 << CS10); // CTC, div16384
    OCR1C = F_CPU/16384/2/1 - 1;     // togge 1Hz. OCR1C = 243 @ F_CPU=8MHz

/*
    // this flashes nOC1B @ 0.95Hz.   OC1B is 0V output. no difference
    DDRB |= (1<<DDB4);        // make OC1B pin output
    DDRB |= (1<<DDB3);        // make nOC1B pin output
    GTCCR = (1<<COM1B0);      // toggle in non-CTC mode
    TCCR1 = (1<<COM1A0);      // copy the COM settings
    TCCR1 |= (15 << CS10);    // div16384.  just overflow @ 0.953Hz
*/
    while (1) {
        // Please write your application code here
    }
}

I tried the "fix".   It made no difference to any of the 3 cases.     Then I swapped the Tiny85 in the STK500 with a Tiny45.    The Tiny85 was"0709" and the Tiny45 was "0850".

 

So both were fairly old !

 

Anyway,  thanks for finding the Errata.    I find it odd that it is OC1B that is wrong.    Somehow,    I would have thought it would be nOC1B.    After all,   not everyone uses the complementary outputs.

 

David.