That's a good question. If you have a simple sequence of past events, then each event is expressed in the simple past.
"I did my homework. Then I ate my dinner. Then I went to see my friend"
This is an example of the use of the past perfect.
"By the time I was ready to eat my dinner, I had already done my homework."
In this second case, we are learning more about a specific time in the past - the time when you were ready for dinner. The past perfect is used toi tells us what happened before this specific time - you had done your homework.
I recommend you do a few grammar exercises on the past perfect to consolidate your knowledge, for example, from www.englishpage.com