How can I controll a 7 segments 4 digits display?

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

Hello! I hope you are fine

 

I'm beginner in AVR and I have a problem, I don't know how can I controll a 7 segments 4 digits display. I find documentation but I don't understand all. 

I want to do a program to increment a counter when I push a button,so that number max is 9999. 

 

Do you have documentation or a code reference to edit it and make my function?

 

Thanks!!

Last Edited: Tue. May 11, 2021 - 05:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Better idea,

Show us the documentation you have been reading and do not understand?

 

What AVR are you using?

What LED display?

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

I'm using a ATmega328P, and I'm using this display: https://www.instructables.com/Us...

My display is common cathode.

 

 

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

Fixed link: https://www.instructables.com/Using-a-4-digit-7-segment-display-with-arduino/

 

So which part(s) of that don't you understand?

 

There are plenty of others available - have you also tried some others?

 

I'm beginner in AVR

Before moving on to multi-digit 7-segment displays, have you covered the basics; eg, blinking a single LED ?

 

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

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

MarioFuentes08 wrote:
I want to do a program to increment a counter when I push a button

Quite a common question lately: https://www.avrfreaks.net/search...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Avoid that "Instructable".    It is not good.

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

Hello, 

The fastest and easiest way to interface four 7-segment displays to an AVR is to order a MAX7219 module board from eBay that does exactly that. Like this for @$3:https://www.ebay.com/itm/1431647...

 

Connect it to an Arduino Nano, like this:https://www.ebay.com/itm/1431647... The Nano board has all CPU and support circuitry to connect with and receive programs from your PC.

 

Google, download, and load the Arduino IDE and the primary MAX7219 library.  Spend a few hours reading the data sheet and "playing with" the example programs.

 

Adapt your application code to the 7-seg module and the Arduino.   Load into a case and package it for shipping.   You've spent @$10 and six hours.  If you follow everyone else's advice here, you end up with a $30 development board and spending 50 hours learning how to make MicroChip Studio work, pouring over data sheets to learn what "magic numbers" to load into CPU registers, and debugging your custom PCB.

 

Life is too short not to use Arduino. Whatever form of ATmega328 and 7-seg display that you have, put them away in a drawer for some other time.  Use the cheap module boards found on eBay instead. 

 

Unless, and I assume that this is the case, you are a student and this is an assignment and you HAVE to use the parts that your teacher has given you to use and those are a DIP ATmega328 and a generic 4x7-seg display with all...those...pins....  In that case, Google search for "AVR 7-seg homework solutions" and just submit to your teacher the first thing that pops up and actually works.

Last Edited: Thu. May 6, 2021 - 01:59 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:
The fastest and easiest way to interface four 7-segment displays to an AVR is ...

But is the goal simply to get a 4-digit display quickly - or to understand how it works ... ?

 

(or to get the homework done?)

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MarioFuentes08 wrote:
I'm using a ATmega328P

Is it in the form of an Arduino - eg, a Uno ?

 

Or some other standard board?

 

Or a bare chip on a breadboard?

 

If you're not using Arduino, an ATmega328P Xplained Mini would be an ideal choice: https://www.avrfreaks.net/forum/...

 

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

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If I simply google "arduino four 7-seg led" I find lots of "projects" like:

 

https://create.arduino.cc/projec...

https://osoyoo.com/2017/08/08/ar...

https://www.circuitbasics.com/ar...

https://www.hobbytronics.co.uk/a...

etc. etc. 

 

But the problem these days is that anyone can post something on the internet and you have no immediate way of knowing if it's an utter wok of genius or  a festering pile of dung.

 

Many of those do explain the basic theory but there's lots of repeated code (rather than modular functions and data arrays) that may suggest it was simply a "beginner project". However if you read a few - perhaps try a few (the joy of Arduino is that everyone probably has very similar hardware!) then you should get the general idea.

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

Thanks but I'm programming in assembler, not in C

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

The LEDs neither know nor care what language you use - the way the hardware works doesn't change.

 

So do you understand how this works at the hardware level?

 

You need to start there before you can move on to coding it in any language.

 

Again, do you understand the basics of how to turn a single LED on and off? Can you code  that in assembler?

 

Once you can control one LED, you can move on to controlling the 7 LEDs for one digit;

 

When you can control 1 digit, you can move on to controlling multiple digits.

 

As always, you need to start with basics and build up step-by-step

https://www.avrfreaks.net/forum/not-really-topic-all-solving-big-andor-complicated-problems

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. May 6, 2021 - 03:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MarioFuentes08 wrote:
Thanks but I'm programming in assembler, not in C
Same meat, different gravy.

 

The actual sequence of events remains the same so it should be possible to look at either C or even Arduino (potted C++) and see what it is doing then translate that to what you would need to do in Asm to achieve the same. In fact most C compilers can be persuaded to show you the intermediate Asm they generate for a given operation.

 

Whether it is Asm, C or C++ what you probably don't want is stuff like:

  //3
  digitalWrite(pinA, LOW);   
  digitalWrite(pinB, HIGH);   
  digitalWrite(pinC, LOW);   
  digitalWrite(pinD, HIGH);   
  digitalWrite(pinE, LOW);   
  digitalWrite(pinF, LOW);   
  digitalWrite(pinG, HIGH);

which in raw C might be something more like:

// 3
PORTB &= ~(1 << 7);
PORTB |= (1 << 6);
PORTB &= ~(1 << 5);
PORTB |= (1 << 4);
PORTB &= ~(1 << 3);
PORTB &= ~(1 << 2);
PORTB |= (1 << 1);

and in Asm something like:

CBI PORTB, 7
SBI PORTb, 6
CBI PORTB, 5
SBI PORTB, 4
CBI PORTB, 3
CBI PORTB, 2
SBI PORTB, 1

If you really want to write 0B01010010 (0x52) to the segments to light up '3' then just do:

PORTB = 0x52;

or

LDI R16, 0x52
OUT PORTB, R16

and in fact what you probably really want is something more like:

.cseg
digits:
    .db 0x42 ; '0'
    .db 0x03 ; '1'
    .db 0x51 ; '2'
    .db 0x52 ; '3'
    .db 0x6B ; '4'
    .db 0x2C ; '5'
    .db 0x91 ; '6'
    .db 0x5A ; '7'
    .db 0x7E ; '8'
    .db 0x73 ; '9'
    
    LDI R16, 3
    RCALL print_dig
    
print_dig:
    LDI R27, low(digits >> 1)
    LDI R28, high(digits >> 1)
    CLR R17
    ADD R27, R16
    ADC R28, R17
    LD R16, X
    OUT PORTB, R16
    RET

(or something vaguely similar to that anyway) so you don't have different code sequences for each of '0', '1' ... '8', '9' but you have one array of values for the segments and you index into that array (I used 'X' which is R28:R27) to pick up the right pattern then output it to the PORT.

 

This kind of thing is the same algoriithm whether you actually code it in Asm, C, C++ or whatever. It's techniques like this that you could pull from good C / C++ code and recode in Asm.

 

(and no my bit patterns for the segments are completely made up and bear no resemblance to actual values - which in part will depend on how the 'a'..'g' segments are connected to the pins anyway)

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

clawson wrote:
one array of values for the segments and you index into that array ... to pick up the right pattern then output it to the PORT.

@ MarioFuentes08  - this is often known as a "lookup table"

 

A couple of examples from a recent thread:

 

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

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

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Take a look here

 

Today we will be showing how to control both a 7-segment display and a 4-digit display using our ATmega328P and AVR assembly language code. In the course of doing this we will have to take diversions in to how to use the stack to reduce the number of registers that we need to tie up. 

 

https://www.instructables.com/Co...

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

Not a great idea to have just one series resistor in the common anode line

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not a great idea to have just one series resistor in the common anode line

I'd agree if they are turning on more than one seg at a time  (could mux seg-by-seg, digit by digit...nice and dim!)...suppose need to look at the code  

use 7 resistors onm the segmants

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

Thanks but I'm programming in assembler, not in C

If you have a fair amount of experience in Asm, and understand the hardware, then it is very reasonable to undertake this project in Asm.

 

If any of that is not the case, then if you know C I'd actually suggest that you first do this project in C.

That will let you figure out how to drive a multiplexed, multi-digit display, and how to use a lookup table to output the desired value, and how to set up a Timer/Counter for generating your scan ISR, etc.

 

I think it is much easier to learn the HW, write the code, and debug the overall process, in a high level language, than in Asm.

 

When the project works in C, then (re) write it in Asm, following your working code as the starting point.

 

As many compilers allow one to insert in-line ASM into their C, you could even replace some functions / subroutines one-by-one, and continue to verify that the project is running as expected.

 

Writing / developing the project "twice" might at first seem like "extra" work.

In actual fact it might well not be.

 

JC

 

 

 

 

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

Any help?

Attachment(s): 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Yup the keyword here is multiplexing. I did a quick search:  https://www.google.com/search?q=7+segment+digit+multiplexing&source=lnms&tbm=isch

 

Look at the schematics. Anyone not using one resistor per segment has no clue. This is the case of the tutorial you posted on  #3, and apparently of most people. The amount of crap on today's internet is appalling.

 

You need to already know what you are trying to learn to recognize a good tutorial. In other words, it won't happen. So you did well to ask us for help. Here you go, a couple of people who actually know what they are doing:

https://www.programming-electronics-diy.xyz/2021/01/7-segment-display-library-for-avr.html

https://www.onetransistor.eu/2018/12/wiring-of-4digit-7segment-display.html

 

Last Edited: Sat. May 8, 2021 - 11:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MarioFuentes08 wrote:
I'm using a ATmega328P,

El Tangas wrote:
Yup the keyword here is multiplexing.

The ATmega328P doesn't have enough port pins to directly drive four 7-segment displays - so, if the processor choice is fixed, there are 2 options:

  1. Multiplexing
  2. some sort of external driver

 

Anyone not using one resistor per segment has no clue

Not necessarily:  as  avrcandies said, you might multiplex one segment at a time - ISTR there was a post a while back by someone doing just that?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Not necessarily:  as  avrcandies said, you might multiplex one segment at a time - ISTR there was a post a while back by someone doing just that?

Well that's true but certainly not the simplest thing to do when you are just starting. The display code would need a segment loop inside the digit loop or something like that.

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

El Tangas wrote:
not the simplest thing to do

TBH, I didn't really see the benefit - just for the sake of saving a couple of transistors for the digit drives.

 

Have tried a bit of searching, but not found it yet.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No,  you would have a 7-division multiplex lighting 4 digits instead of the conventional 4-division multiplex lighting 7 segments.

 

You still have a large peak current.  e.g. for a segment requiring an average 5mA.   The 7-division means 35mA for 1/7 duty on the segment pin.  4-division means 20mA for 1/4 duty.

 

However the common-pin (digit) has to sink 35x4 mA for 1/7.  But has to sink 20x7 mA for an '8'.

 

Which is why you can drive segments with an AVR but need a transistor for the common pin.

You trade 7 segment resistors for 7 external transistors.   Or accept a much smaller average current.

 

Conventional displays seldom show '8888' in real life but it is a worst case.

It is very common to have segment b lit on all 4 digits

 

David.

Last Edited: Sat. May 8, 2021 - 01:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
You trade 7 segment resistors for 7 external transistors.   Or accept a much smaller average current.

 

I see. So for a common cathode display like the one used by the OP you would need 7 high side transistors, probably PNP.

 

Well to use that scheme I would then use a common anode display instead, so that everything would be reversed and a ULN280x could replace the discrete transistors. It would be a nice setup, actually.

 

But still 4 extra transistors might be needed to drive the "common" display pins (I mean labeled common, not really common in this scheme) since the MCU pins would be hard pressed to supply 35 mA directly.

Last Edited: Sat. May 8, 2021 - 02:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas wrote:
 for a common cathode display like the one used by the OP you would need 7 high side transistors

IIRC, that's not what was happening in the thread I'm thinking of.

 

The segments were each connected to a port pin, and each common pin to a port pin.

 

So only at most 1 segment of 1 display was ever active at any 1 time.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok,  you can do a 28-division multiplex if that is what floats your boat.

 

That just means 28x5 mA peak current to achieve 5mA average.

 

If you have ever multiplexed 7-segments you would know that 8-division is about the practical limit.

 

Note that I just invented 5mA as a typical average segment current.   If you have small bright devices,  you can probably get away with 1mA average segment current.

 

Note that LEDs accept low duty cycles and high peak current.   The multiplex frequency goes up.   But the efficiency goes down.    The human eye notices any flicker.

 

I have driven 4-digit multiplex from AVR port pins.   Don't expect to read it in sunlight.

 

No,  I did not study the Instructable.   My first thought was "wrong" resistors in the schematic.    I glanced at some of the comments which made the same point.   The author really did not seem to understand the electronics.

Seriously.    I am horrified by some of the cr*p on the Internet.  A beginner should start with a respected Tutorial.    The subject is not difficult.

 

Incidentally,   one of the features of the traditional 8051 is that the ports can sink but not source current.    Which means that 8051 tutorials are always going to get the electronics correct.

 

David.

Last Edited: Sat. May 8, 2021 - 02:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
you can do a 28-division multiplex if that is what floats your boat.

Not my boat - the guy who made that post. (I still haven't found it)

 

That just means 28x5 mA peak current to achieve 5mA average.

Indeed - that was my point to him.

 

A beginner should start with a respected Tutorial.

I guess the trouble with for a beginner is how to know what to trust.

 

frown

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is my cookbok for 7S display:
Use 4xPNP (or MOSFET) + CA display, or, use 4xNPN + CC display, and 8 curent-reducing 100-220 ohm resistors
Total of 12 pins is required, or use HC595 to save 5 pins
Refresh rate of 60Hz is the optimum

WDT 16ms timer may be used
Do not do it that simple, (EBAY is full of disgusting modules with 7S visible from 90m distance,) do provide
levels of light 1/4/16 or so
Up to 8 keys may be added

 

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

grohote wrote:
Refresh rate of 60Hz is the optimum (sic?)

Do you mean minimum ?

 

Some people will still see flicker at 60 Hz

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No,  grohote  means exactly what he said.

 

The human brain accepts moving pictures at 30 FPS but really does not like multiplex at less than 50Hz.

There is little point in going faster than you need.  i.e. cycles wasted in the ISR() and risk of shadow.

 

For example.   a conventional 4-digit multiplex with 5ms ISR() means a Frame takes 20ms.   or 50 FPS.

An 8-digit multiplex with 2ms ISR() means 16ms or 62 FPS.

 

Of course many embedded systems will have a 1ms "system tick" anyway.   You just multiplex on 5th tick   (or 2nd tick)

 

David.

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

No need for 5ms, 2ms or 1ms, yet, the light creation does require separate Timer for that. For example, if the table of light levels is 1, 4, 12, 30, 89, 220 and the prescaller is 32 on 8M clock, then the longest light will be 220*32/8=880us and the shortest 4us (plus interrupt overhead). On 16ms refresh, do set light, 'com' one of this figures and fill TCNT, initiate TCCR, exit and expect OVF int, remove light and proceed with the next digit. After 4ms max, all digits are served.

Milan

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

So no takers for the Atmel diagram and assembler code in #19? surprise

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sun. May 9, 2021 - 11:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:
#12

did you mean #19 ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes #19....blush

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

david.prentice wrote:
The human brain accepts moving pictures at 30 FPS but really does not like multiplex at less than 50Hz.

There is little point in going faster than you need.  i.e. cycles wasted in the ISR() and risk of shadow.

Old movies, e.g. of the 35mm film variety were displayed at 24 FPS,

but the shutter was clicked at twice that rate.

NTSC televisions of the analog era, displayed at roughly 60 half-frames per second,

each half containing only odd or even lines.

 

IIRC roughly 60 = 60,000/1001.

Moderation in all things. -- ancient proverb

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

Hi JS, the code for keys there is very poor.
The solid code should be state-based, having Idle-Detect-Busy-BusyRel /-Long-LongRel/
for security and all possible functions, and the key should be detected on key release only. Scanning can be each 16 to 50ms which is fast enough for a couple of keys per second.

 

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

Hi JS, the code for keys there is very poor.

surprise Huh are you saying that Atmel application notes are rubbish? surprise cheeky

 

I'm sure that that application note has 95% of what the OP wanted including code and as only one switch is required a simple change including hardware debounce could be accommodated.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I will lock this thread as the OP has stared another one https://www.avrfreaks.net/forum/...

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Topic locked