Go Down

Topic: Self-test on Simple Programming of ATmega328 using Arduino UNO Platform (Read 5427 times) previous topic - next topic

GolamMostafa

Learners like me and others may down load the attached quiz-question and try to answer.

GolamMostafa



Let us try to develop some Arduino IDE Codes to show 00, 01, 02, 03, ..., 98, 99, 00, 01 (cyclically) on DP0-DP1 positions of the above schematic.

I would like to begin with the following Pseudo Codes:
Code: [Select]

void setup()
{
   Set directions of IO lines as needed                                 // L11:
   Initialize other variables and data structures as needed   // L12:
 }

void loop()
{
    byte x = 0x00;   //                                                L21:
    //-----------------------------------------------        L22:
    byte x1 = 8-bit cc-code for the left digit of x
    byte x2 = 8-bit cc-code for the right digit of x
    //-----------------------------------------------        L23:
    Send x1 onto DP0 via PORTD, PORTB
    Assert LL at cc0-pin of DPO
    Assert LH at cc1-pin of DP1
   //------------------------------------------------         L24:
    Send x2 onto DP1 via PORTD, PORTB
    Assert LH at cc0-pin of DPO
    Assert LL at cc1-pin of DP1
    //------------------------------------------------        L25:
    delay(5);
   //-------------------------------------------------       L26:
   Executes codes similar to above in a linear way (inductive reasoning) or using [i]for()[/i]
   structure (deductive reasoning) to show 01, 02, ..., 09. 
   //-- now facing problem: how to show the next number - 10?   
}


Learners may repack the bare Arduino UNO Kit as per following figure to accommodate the hardware resources of the above figure. And then the given Pseudo Codes could be coded and tested on 'SSS (Small Start Strategy)' methodology. This method has been tested in the class room; the participants showed satisfactory outcomes!

 

CrossRoads

1.   Which port line is being referred by DPin-1?
[Unclear. PINDx and PORTDx are the uC nomenclature, DPin-x is not. One might assume PD1, the TXD line, is being referred to.]

2.   Which two instructions of the following will ignite L?
   (a)   digitalWrite(8, HIGH);
   (b)   bitClear(PORTB, 5);
   (c)   boolean n= HIGH;
      bitWrite(PORTB, 5, n);
[c, assuming the pin had been set to output mode]

3.   Write assignment instruction for the function
pinMode(0, HIGH) to set the direction of PD0-line.
[incorrect syntax. pinMode (0, INPUT); or (0, INPUT_PULLUP) or (O, OUTPUT) are correct.

4.   Write instruction to read the value of Pin-4 of ATmega328 and write it into PD1-line. Assume that the directions of the port lines are already as needed.
[digitalWrite (1, (digitalRead(2) );  assuming Pin-4 refers to the physical pin]

5.   Write instruction (s) to show 3 at DP2 position of the 7-segment display unit. Assume that the directions of the lines are already set as required.
[digitalWrite (8,  HIGH); // a
digitalWrite (9, HIGH); //b
digitalWrite (10, HIGH); // c
digitalWrite (11, HIGH); // d
digitalWrite (12, LOW); // e
digitalWrite (13, LOW); // f
digitalWrite (6, HIGH); // g
digitalWrite (7, LOW); // p
digitalWrite (1 HIGH); // mux 1
digitalWrite (0, LOW); // mux 0

Note the drawing is missing any current limiting resistors for the LEDs, and 74LS138 is only recommended for 8mA sink current max.

6.   Write down the symbolic names of the Data Direction Register that are present in the system.
[DDRB, DDRC, DDRD]

7.   After the inclusion of the 74LS138 decoder, how many port lines are now available in the system?
[1, pin 3]
8.   Which segment (a or b or ……, p) of which display (DP0 or DP1, …DP3) will appear as ON after the execution of the following instruction?
   byte x = 0x87;
   boolean n = bitRead(x, 7);
   bitWrite(PORTD, 7, n);
   digitalWrite(1, HIGH);
   bitSet(PORTD, 0);
[first 3 lines put HIGH on pin13, so p is driven.
PORTD bits 1,0 = 1,0 -> DP2 enabled]

9.   Assume that the wiper of R2 is exactly at the 1/3rd position from 0V-point. What will be the value of x (in hex format) after the execution of the following instruction?
      int  x = analogRead(A5); (You can use Calculator.)
[assuming Aref is set to External, it has only a 0.1uF cap to Gnd connected, and assuming a linear pot, then the voltage at A5 = 5V/3 = 1.67V, and x ~= 1.67*1024/5V = 342decimal = 0x155]

10.   What output values (0 or 1) would be produced by the following two instructions after pressing K1?
   (a)   digiatlRead(2);
   (b)   bitRead(PIND, 2);
   (c)   bitRead(PORTD, 2);
[which 2 of the 3 instructions?]
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

GolamMostafa

@CrossRoads

It's my great pleasure to see your interaction and involvement for better education of the learners in the way of reinforcing constructive criticisms.

In fact, the quiz-question has been set for testing the progress of my (about 135) undergraduate students.

Therefore, please wait until next Saturday to see what the answers are given by the students. I have also solution sheets/answer sheet for these questions. In the meantime, I would like to state that there could be mistakes in the composition of my questions either conceptually, syntactically, semantically or all. I will remain open with the readers to make necessary amendments in the present quiz-question in order to make a better quiz-question next time.

Few clarifications in response to your queries (I will not comment now on your answer):
1. DPin is our local symbolic name. It stands for Digital Pin Connector. It refers to the Arduino UNO's
  sockets (holes) with PCB designations 0, 1, .., 12, 13 into which we plug pins of the jumper wires.

   APin stands for analog pin connector (A0 to A5). PPin stands for power pin connector (5V, GND
   3.3V, ..).

  PINDx (x = 0 to 7) : PIND2 refers to Bit-2 of PIND Register.
  PORTDx (x = 0 to 7): PORTD3 refers to Bit-3 of PORTD Regiter. (In AVR Studio it is called PD3.)

2. No comment, now.

3. You are right (I frequently make this mistake).

4. No comment, now.

5. We have avoided CLR to save space in the breadboard. Hopefully, segments will not destroy MCU's
    port lines.

    Practically, 74LS138 is driving well the cc-pins of the display devices resulting well visibility of the
    segments.

6 - 8.  No comment, now.

9. The students will solve it assuming Vref as DEFAULT (5V). Probably they will use 1023 instead
    of 1024 (Input = 5V, Vref = 5V; Output = 000000 11 1111 1111 = 03FF = 1023). There are
    many references in the net/forum of using both 1023 and 1024! Which one is the
    preferred one and why?

10. Typographic mistake (the word two is to be deleted).





CrossRoads

#9, no doubt 1023 will be used, but 1024 is correct per the datasheet.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

larryd

If you try harder, the schematic could be made a bit more unreadable, if that's what your intention was.




.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

GolamMostafa

Soon, I will come up with a revised Schematic where the segment pins of the 7-segment devices will be driven by an 8-bit 'Bit Addressable Latch (74LS259)'. I along with my co-learners will test the functionality of the circuit, and then we will clarify the rationality for putting so many extra things with the basic Arduino. In the mean time, let the readers be pondering about our intentions.

Thanks for the comment which I had been expecting since the posting of the schematic.

 

larryd

Quote
we will clarify the rationality for putting so many extra things with the basic Arduino.
That's a good thing ;)

.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

larryd

Maybe some version like this for the Arduino:




Or for the 328:




Then, revisit the other items in the schematic.



Please confirm the blocks for accuracy.

.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

GolamMostafa

1. I am not familiar with the top diagram.

2. The Bottom diagram agrees with the board layout signals of Arduino UNO R3.


GolamMostafa

A: Revised Schematic, which has no more chance to undergo further revision.


B: The repackaged Arduino UNO that conforms with the above Schematic.


C: Why have we added the 74LS138 decoder and 74LS259 addressable latch?
(1) We have aded these two chips for expanding the IO lines of the ATmega328 from 20 to 25.
(2) Now, we can carry out the following experiments without taking out any jumper wiring that
    we have done for the previous experiment.

    * 4-digit 7-segment display unit
    * LCD
    * Connecting input device (K1)
    * External hardware interrupt
    * Analog-to-Digital Conversion
    * Counting of external events
    * PWM
    * SPI Bus operation/ISP Interface
    * TWI Bus Operation
    * UART
    * Serial Monitor
    * Interprocessor Communication (Arduino UNO and Arduino NANO)
    * System Design (Temperature Measurement).
   
D: Let us remember that we started Lab Works in the following sequence (Lab Sheets are
     available for uploading).
(1) Keep blinking L.
(2) Blink L for 5 times using goto statement.
(3) Blink L using for() structure
(4) 7-segment display device (single) being driven by PORTD for the segments and PORTB for the
     cc-pins.
(5) Building 2-digit multiplexed display,

........................
.........................

(n) we have arrived at the present state of expanding IO lines. Every student has his own
     Learning Kit which he will keep with him and practice MCU programming at the most
     convenient time.

** Things might appear clumsy; however, it gives pleasure when observing the scenario of how the parallel bits passing through the addressable latch and getting their places at the right positions of the 4-digit multiplexed display**

**One might suggest for Arduino MEGA. The MEGA is very costly (900); Arduino UNO (450); 74LS138 (20), and 74LS259 (25).**

Thanks for hearing. 



Robin2

Two or three hours spent thinking and reading documentation solves most programming problems.

GolamMostafa


CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

GolamMostafa

Let me tell you the story/history! It's not always dry!! There is always someone around to hear the tale!





Please find the attached file for the detailed schematics of an unpublished works!MTK8038Schematics

Go Up