View previous topic :: View next topic |
Author |
Message |
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
switch VS array which one is more efficient?[SOLVED] |
Posted: Thu Apr 09, 2015 6:00 pm |
|
|
Greeting my friends,
I am working on a 7 segments driver. The segments part, I got it working good with both switch case statement 0-9 and with int array[10]. which one is more efficient for this purpose? Why?
Thanks,
Last edited by Sam_40 on Tue Apr 14, 2015 2:48 pm; edited 2 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
|
Posted: Thu Apr 09, 2015 6:24 pm |
|
|
PCM programmer,
What is your choice for similar task?
Which one is more efficient for my purpose and why?
They both worked and I did not notice the different. |
|
|
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
|
Posted: Thu Apr 09, 2015 6:29 pm |
|
|
I forgot to mention I did not use the default in the switch statement!
Thanks, |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Apr 09, 2015 6:55 pm |
|
|
You should take the time and effort to dump the listings of your two test programs. Within the lines of assembler, you'll soon see which is 'better'.
A program can be 'better' because it is faster or since it takes up less memory or other resources. To some speed is the main criteria, as more things' can be accomplished within a certain time frame. Others favour more compact code, when space is a cost factor.
These days it's almost a 'Ford vs. Chev' comparison.
Jay |
|
|
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
|
Posted: Thu Apr 09, 2015 7:12 pm |
|
|
Jay,
I am 100% chevy guy. the reason is Chevrolet clutches offer better quality at lower prices lol
I just thought there is a quick and sweet answer
assembler are way over my head at the moment :(
Regards, |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 10, 2015 3:18 pm |
|
|
Quote: | PCM programmer,
What is your choice for similar task?
Which one is more efficient for my purpose and why?
They both worked and I did not notice the different. |
Are you talking about the segments used for each digit ?
I use an array for that data:
Code: | // The following array tells the CCS lcd_symbol() function which
// segments to turn on, to display the numbers from 0 to 9.
// 0 1 2 3 4 5 6 7 8 9
byte const Digit_Map[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xE6}; |
Then I use the CCS function, lcd_symbol() to turn on the segments.
This is for use with an LCD 7-segment display, with a PIC that has
an lcd segment controller built-in. |
|
|
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
|
Posted: Fri Apr 10, 2015 4:58 pm |
|
|
No, I am using just a simple 7 segment LED with no built in controller! The one I am using is common cathode.
The way I am controlling the 7 segments is:
1- All the segments (A, B, C, D, E, F, G) are connected to the port B pin (0-6 via 330ohm resisters).
2- All the common connected to port C (D1, D2, G3, D4) are connected to pin (2-5) via 4k7 resisters and BC547 transistors.
3- I got it working good with both switch case statement 0-9 and with int array[10].
4- This is how I done it. In the main() and using while(true) loop. and in this order:
output_b(the number I want to display on the first digit)
output_c(the first digit to turn high for example C2 as byte)
delay_ms(1)
output_b(all output low)
output_c(one digit to turn low for example C2 as byte)
delay_ms(1)
and so on for the rest of the digit.
I did this part for each digit because I had ghosting problem and that how I fixed it:
output_b(all output low)
output_c(one digit to turn low for example C2 as byte)
delay_ms(1)
Thanks, |
|
|
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
|
Posted: Tue Apr 14, 2015 12:38 pm |
|
|
Guys,
I will go with the array it look nicer as far as code!
One more question. When first worked on this, I decided to use 2N3904 transistors for the commons. I am very sorry it is OT, But I am sure one of you know the answer and it may help others. Using the same setup. From the PIC output to 4K7 or 4K2 even tried it down to 2K2 then to B on NPN trans. it works great with BC547 and it does NOT work with 2N3904? Both made by Fairchild and have identical parameters that effect my project?
It will work with the 2N3904 if I turn it ON all the Time (the seven segments) but not in multiplexing?
I did the math for the base current and I came up with 4K2. I did try that and I got the same results. it works with BC547 and it does NOT work with 2N3904?
Any idea?
Thanks,
Last edited by Sam_40 on Tue Apr 14, 2015 12:50 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Tue Apr 14, 2015 12:50 pm |
|
|
You did twig that the pinout is TO92R, not TO92....
e, b, c across the flat, not c, b, e
I ran into this when I had to do a substitute for the BC, because it is getting hard to get now. |
|
|
Sam_40
Joined: 07 Jan 2015 Posts: 127
|
|
Posted: Tue Apr 14, 2015 2:42 pm |
|
|
Ttelmah,
You are 100% right. Thank you very much. Reading so many datasheet and I made this mistake that me troubleshot it for a while. On my final PCB I want to use the MMBT3904 which is SOT-23. Since I like to try my project physically, I built it first on predrill PCB and using through hole parts, Just in case something need to be change.
This kind problem pay off as a learning curve and save from ordering 30+ PCB that have a defective silk screen, holes, ...etc.
Thanks again for your help,
Sam |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Wed Apr 15, 2015 12:34 am |
|
|
Glad it was as simple as that. It's the classic 'non obvious' error that stares you in the face. |
|
|
|