need help on Program counter

Discussion in 'General Electronics Chat' started by abhimanyu143, Dec 30, 2014.

  1. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    hello,
    A program counter is a register that contains the address of the instruction being executed at the current time. Data ,instruction and address are stored in Rom memory
    different instruction cycle
    MOV A, Rn 1 byte instruction take one cycle
    MOV Rn,A 1 byte instruction take one cycle
    Mov A#immediate 2 byte instruction take two cycle
    MOV A#immediate 2 byte instruction take two cycle
    how does program counter make for 8051

    I need basic idea how does program counter make ?
     
    Last edited: Dec 30, 2014
  2. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    I have spent many hours to search about program counter. But I did not find useful link that will explain how does PC make
    I want to make very small Program counter
    what should I know ? I don't understand where to start ? because I cant use up or down counter. I have no Idea ?
     
  3. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,572
    2,536
    The program counter is an internal register that works through of logic gates, that points to the next next instruction in whatever program is stored in the 8051 (be it flash, eeprom, etc) executable memory. This program can be linear or conditional, and logically single ended or being eternally executed in a closed loop...
    The way I understand your question is this: 'I want to know how an actual MCU "thinks" or processes all of the instructions that I programmed in it.' ... is that right?

    Are you familiar with any kind of digital logic simulator?
     
  4. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    I have downloaded 8051 Ide . I now how does up/ down counter make but Program counter is different. I don't understand how does PC make for processor
     
  5. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    The program counter is just a simple register that is made up of binary counters with 'preset' and 'clear' function. We dont use up/down counters, I guess, is because we dont need to decrement by one addresses in a program. Stepping the program counters can be done by simply controlling the clock of the binary counters. But we do have instructions like "INC R1" or "INC A" which are for registers and also direct memories like "INC 0xAABB'.

    To modify an address, we can control the clock of the binary counter together with the presets as in JMP or branch instructions. One more thing about the 8051 is that it runs on 12MHz (typical) and each instruction needs roughly 12 clock pulses to execute (single byte instructions). This is about 1 to 3us/instruction on a 12 MHz xtal. Where as a PIC needs 4 clock pulses to achieve 1uS/instruction on a 4 MHz xtal.

    Allen
     
    Last edited: Jan 2, 2015
    abhimanyu143 likes this.
  6. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,572
    2,536
    Download Digital Works, and check the examples. The basic, elementary way in which the PC works is through logic gates that later store information in registers... this might take you a while to understand, but it's worth the time you will spend studying it...
     
  7. WBahn

    Moderator

    Mar 31, 2012
    17,743
    4,789
    Ask yourself what things a program counter has to do along with the execution of each instruction. It must do one of two things -- increment to the next instruction or change to a different instruction as a result of a branch/jump. Doesn't that sounds an awful lot like a normal counter than either increments or gets loaded with a new value? There's a reason that it is called a program 'counter'.
     
  8. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    A program counter is a register that contains the address of the instruction being executed at the current time.program counter incremented just after the instruction has been executed. each byte has its own address,In these situations, the PC incremented by the number of bytes. for Branch or jump instruction. program counter counter move at different address

    I need ,preset function so that signal can jump on that address
    preset Function ?
     
  9. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,804
    832
    A preset function loads a preset value into the counter. Similar to how we used "load" to transfer register contents (in your other thread). You would present your jump address to the inputs (preset) and load them into the counter, errrr, program counter.
     
  10. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    there are two part of circuit
    1 output of program memory connected with accumulator , register and immediate data
    note (there is mistake in program memory I used 8 bit but I can use 4 bit. just ignore )
    2. output of program counter connected with Program memory
    I want to assemble both circuit. I tried. look this image
    upload_2015-1-3_7-22-36.png
    I don't understand where to connect input of program counter ? how PC will operate ?
     
  11. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Did you check post #14 on your thread "ROM Memory"?

    Allen
     
  12. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    Hi Allen,
    I looked that design
    upload_2015-1-3_8-56-11.png
    we have circuit that execute three instruction and program counter that hold current instruction address
    MOV A#5
    mov R1,A
    Mov A,R1

    actually I don't understand how that program counter will work ?
     
  13. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Imagine about executing the instruction "LJMP 1234H".

    In the 27256 eprom, let's assume the instruction is stored at address 0100H-0102H like this
    Code (Text):
    1.  
    2. Address (Hex)      data (Hex)      instruction      remarks
    3. ----------------------------------------------------------------------
    4. 0100               02              LJMP 1234H
    5. 0101               34                               lower 8 bit of address
    6. 0102               12                               upper 8 bit of address
    From the above, can you guess how are the inputs of the P.C. are connected to? Also look at the data sheet of 8051 and see the block diagram of the core architecture and see how the P.C. is connected.

    Allen
     
    Last edited: Jan 9, 2015
  14. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    what are the low address mux and high address mux. why we use multiplexer with program counter
     
  15. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Simply because your address is 16-bit and your data is 8-bit. So you need to load a 16 bit address from 8 bit data bus in 2 clock cycles.

    Allen
     
  16. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    I know address is 16-bit and data is 8-bit. I now what is multiplexer and its truth table. I don't understand why we use multiplexer with program counter ?
     
  17. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    It is just terminology.
    If you want to call it selector or tri-state buffers or anything you want, it's fine.

    In my work, it is normally called a data selector and the symbol looks like this -

    data selector.PNG
    Allen
     
    Last edited: Jan 3, 2015
  18. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    I am not sure if I understand your question correctly. Are you saying that a mux is not needed in the program counter design?

    Allen
     
    Last edited: Jan 3, 2015
  19. abhimanyu143

    Thread Starter Member

    Aug 25, 2014
    211
    1
    data bus is 8 bit and address bus is 16 bit. you have divided address bus into two part low address bus and high address bus
    I think it will easy to understand me if I connect program counter with my circuit.
    assume we have circuit that can be load or store data ,

    I made circuit in my other thread Rom memory that can execute some load and store instruction
    actually I want to add program counter with that circuit
    I want to see that how does program counter deal with following code
    Code (Text):
    1. MOV A,#2H
    2. MOV A,#4H
    3. Acall delay :
    4. MOV A,#5H
    5. Acall delay
    6. MOv R1#4
    7. MOV R1,A
     
  20. absf

    Senior Member

    Dec 29, 2010
    1,492
    372
    Even "ACALL" instruction has an address of 11 bits. You still need to break the address down to 3 + 8 bits and load them in 2 steps. Besides, ACALL involve stack pointer register and return address when returning from the called subroutine, which I think would be tough for you to implement. Why not wait till you have a full understanding on how its mechanism works?

    There is the SJMP instruction but it uses offset to calculate the jump address and I have no idea how to implement it. May be the ALU is needed there.

    Can you say this in simpler English? I dont understand what you mean...

    Allen
     
    Last edited: Jan 4, 2015
Loading...