ATTint2313 PWM output pins give different Voltages under same command

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

I am using 3 of the 4 pwm outputs of the 2313 uC on a project.

I am analogWriting a random output to them so that they imitate fire lighting with leds.

 

Code:

#define F_CPU 1000000UL
#include <avr/io.h
#include <util/delay.h

int i = 0;

void setup() {
DDRB |= B00011100;
  DDRD |= B00000000;
  
  MCUCR  |= B00000011;   //watch for rising edge
  GIMSK  |= B01000000;   //enable external interrupt
  SREG   |= B10000000;   //global interrupt enable
  TCCR0A |= B10100011;   //PWM mode select
  TCCR0B |= B00000001;   //clock source = CLK, start PWM
  TCCR1A |= B10100011;   //PWM mode select
  TCCR1B |= B00000001;   //clock source = CLK, start PWM
}

void loop() {
 i=random(155)+100;
      analogWrite(12,i);
      delay(5);
      analogWrite(11,i);
      delay(5);
      analogWrite(13,i);
      delay(5);}
}

 

I am using outputs  OC1B, OC1A and OC0A and it seems as though OC0A is always brighter than the other two.

Indeed after measuring the pin with a multimeter it outputs more voltage than the OC1B, OC1A pins for the same analogWrite command. What gives AVRfreaks? :/

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

Since the T2313 is not supported by Arduino IDE, what "core" are you using to support it, please provide a link.

 

Jim

 

 

 

 

 

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

tellSlater wrote:
I am using outputs OC1B, OC1A and OC0A and it seems as though OC0A is always brighter than the other two. Indeed after measuring the pin with a multimeter ...

Interesting in itself.  PWM doesn't "output a voltage".  It is dong logical 1/0 at a certain rate and duty.  Your meter is doing an average.

 

Get rid of all your |=.  Reseach how Arduino sets up the timers by default.  Then add all your |= and you end up with fruit salad.

 

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

Brian Fairchild wrote:
Where does the horrible practice of using "|=" to set initial values come from?

 

https://www.avrfreaks.net/commen...

https://www.avrfreaks.net/commen...

https://www.avrfreaks.net/commen...

https://www.avrfreaks.net/commen...

https://www.avrfreaks.net/commen... *** may well be your situation...

...

 

 

 

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.

Last Edited: Mon. Dec 3, 2018 - 05:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since the T2313 is not supported by Arduino IDE, what "core" are you using to support it, please provide a link.

 

https://github.com/SpenceKonde/A... ??

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

Correct!

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

Thank you, I can see why this could be a problem. Also, I know how a PWM works, no worries there.

I don't see how this could be affected by a timer.

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

tellSlater wrote:
I don't see how this could be affected by a timer.

???  Tell much more about that.  AVR8 PWM is carried out by a timer...  (some of the links go into that in detail...have you bothered to read the linked threads?)

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.

Last Edited: Mon. Dec 3, 2018 - 09:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

Then add all your |= and you end up with fruit salad.

 

I like that analogy!  :-)

 

The |= is definitely one of the problems.  Timers 0 and 1

are different and have different modes.  Setting the two

low bits of TCCR1A puts the timer into 10-bit PWM mode

so the brightness will be much less than expected.

 

Also, as noted, Arduino (or in this case the tiny core) sets

up the timers so you should not touch TCCRnX at all!

 

I suggest removing everything from setup() and see if

your sketch works as expected.

 

--Mike

 

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

I know that much but aren't they all linked to the same timer with this setup?

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

Thanks for the ideas! I will try this tomorrow.

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

tellSlater wrote:
I know that much but aren't they all linked to the same timer with this setup?

With all of you |=, they may have a different setup from what you think.  You are adding "mode select" bits from what is already there.

 

There is no sense arguing about it; gather the evidence:

 

-- When Arduino gives you control at startup, gather, log, and examine the state of the TCC registers.  What do you find?

-- Repeat after all of your |= setup.  What do you find?

-- Repeat getting rid of the |=.  What do you find?

 

When reporting the above, include a complete schematic, and preferably a 'scope trace of the suspect pins.

 

theusch wrote:
some of the links go into that in detail...have you bothered to read the linked threads?

As mentioend, some of the links go into exactly what Arduino sets timers to by default.  Now, it might be a bitdifferent for your core.  Find out what that is!  Determine what the core uses the timers fo!  You then have to decide whether to give that up (e.g. millis() ) or live with it.

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 are right again.. I am going to do my best to switch from Arduino IDE to Atmel Studio. Then I will use a TTL to Serial to read my registers and debug. Does that sound like a good plan? Should I go with some other IDE?

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

tellSlater wrote:
I am going to do my best to switch from Arduino IDE to Atmel Studio.

Why do you need to do that to do what I said?!?

tellSlater wrote:
Then I will use a TTL to Serial to read my registers and debug.

While an ICE is a good thing, there are other ways.  I might log to EEPROM and then use my ISP to read back, and then a hex editor and the map file to interpret.

 

But use your main tool -- your head.  Surely your Arduino implementation will have the source available somwhere.  And/or documentation.  How are the timers set up?

But no matter--just set up your timers fresh; abandon the Arduino's default use.  Then go from there.

 

The above is a 5-minute job.  Your proposal is much more effort.  The elapsed time will be much longer, and introduce yet more variables.

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.

Last Edited: Tue. Dec 4, 2018 - 07:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seriously just delete everything in setup().  I read the source

for the core and it sets up the timers correctly.  Messing with

the registers afterward, as you did, put timer 1 into 10-bit PWM

mode instead of 8-bit PWM mode.  Even with a maximum value

of 255, the output will only be ON for 1/4 of the time.  Try it!

 

--Mike

 

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

avr-mike wrote:
I read the source for the core and it sets up the timers correctly.

It might fall on deaf ears. but perhaps give a link for the OP?

 

Seriously, get rid of the |= unless you really mean it.

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

OP has the source which js posted a link to in #4.

 

--Mike

 

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

avr-mike wrote:
OP has the source which js posted a link to in #4.

Yet it seems that OP doesn't want to follow up on hints.  I'm out.

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 am obviously new to this.. I am trying my best to follow what you say. I wouldn't be here asking for help if I understood what "log to EEPROM" or "hex editor and the map file" meant.

And even then, after each reply I am trying my best to figure out what half your text means and learn.

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!

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

Up to now:

tried replacing the |= with = , it did not work

tried deleting setup commands entirely and selectively, did not work

Thank you everyone for helping!

 

theusch wrote:

I might log to EEPROM and then use my ISP to read back, and then a hex editor and the map file to interpret.


I might be trying this next.

 

theusch wrote:

Surely your Arduino implementation will have the source available somwhere.  And/or documentation.  How are the timers set up?

I really don't have the skill to understand how the timers are set in the core's source code for now but since  avr-mike did that, I will leave it for now. Thanks mike;)

 

theusch wrote:

just set up your timers fresh; abandon the Arduino's default use.

I am new to this and using literary terms like "fresh" doesn't help me understand. No idea how to take above sentences.

TO THE FINDER... THE ISLE OF KOHOLINT, IS BUT AN ILLUSION... HUMAN, MONSTER, SEA, SKY... A SCENE ON THE LID OF A SLEEPER'S EYE... AWAKE THE DREAMER, AND KOHOLINT WILL VANISH MUCH LIKE A BUBBLE ON A NEEDLE... CAST-AWAY, YOU SHOULD KNOW THE TRUTH!