Reading the program counter value

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
himc_284346
Level 3
Level 3
Welcome! 10 replies posted 5 replies posted

 Is there any way to read the Program Counter value of a particular point in my code? I want to store this value in a varaiable and process it. (specifically for PSoC3).

0 Likes
1 Solution
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

 Program Counter register addresses can be found from PSoC3 Registers TRM.(Link:http://www.cypress.com/?rID=37833). But this register cannot be accessed using CY_GET_REG API's. It can be accessed only when CPU is in halt state.

View solution in original post

0 Likes
6 Replies
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

 Program Counter register addresses can be found from PSoC3 Registers TRM.(Link:http://www.cypress.com/?rID=37833). But this register cannot be accessed using CY_GET_REG API's. It can be accessed only when CPU is in halt state.

0 Likes
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

 Another method for reading the value will be using assembly instructions. These steps can be used to read the Program Coounter Value.

   

1)Use LCALL. When LCALL is used the Program counter value will be pushed on to stack.
2)Use POP instruction to read 
stack register value to DPL and DPH register.
3)Store the DPH DPL values to 
the variable.

himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

While adding assebly instructions,please refer the knowledge base article available in the link : http://www.cypress.com/?rID=43621 

himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

 Please check the code snippet given below. Please add the same in your project. The Program Counter Value corresponding to the label here: will be stored in the variable ProgramCounterValue.

   

 

   

uint16 ProgramCounterValue;

   

/*---- This assembly code will store the Program Counter value to the variable ProgramCounter----- */

   

   

#pragma asm   

   

LCALL here

   

    here:

   

       POP DPH1

   

       POP DPL1

   

  

   

MOV DPTR, #ProgramCounterValue?040

   

MOV A, DPH1

   

MOVX @DPTR, A

   

INC DPTR

   

MOV A, DPL1

   

MOVX @DPTR, A

   

#pragma endasm 

   

   

/*----End of the assembly block ------ */

lock attach
Attachments are accessible only for community members.
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

The above attached project will print the Program Counter value on the LCD Screen.

0 Likes