organize things as follows. The first weighing would represent the nines place, the second weighing the threes place, and the final weighing the units place. I chose "the left pan goes down" to represent the digit 1 and "the right pan goes down" represents the digit -1. The digit 0 represents the pans balancing. Then I placed the 12 coins on the pans in such a way that, if any one of them turned out to be counterfeit and heavy, the outcome of the weighing would be a positive number in balanced ternary notation. Here is how the numbers are placed on the pans according to these rules.
left pan right pan
(9) first weighing 5,6,7,8,9,10,11,12
(3) second weighing 2,3,4,11,12 5,6,7
(1) third weighing 1,4,7,10 2,5,8,11
Obviously this assignment of coins to pans cannot work because the number of coins per pan in the first two weighings are not equal. However, if we interpret the sign of the outcome for certain coins oppositely, we can insure that the coin assignment to the pans is four coins per pan. Accordingly, I chose to place the coins 7, 9, 11, and 12 to be placed so that the outcome weighing would have a sign opposite to the correct sign. This produced the assignment
left pan right pan
(9) first weighing 5,6,8,10 7,9,11,12
(3) second weighing 2,3,4,7 5,6,11,12
(1) third weighing 1,4,10,11 2,5,7,8
For example, if the counterfeit coin is 6 and heavier than the other coins, then, in the first weighing, the left pan goes down, in the second weighing the right pan goes down, and in the last weighing the pans balance. This produces the base three number (1,-1,0)=9-3+0=6, indicating that the counterfeit coin is the sixth coin and it is heavier than the other coins because 6 is positive. If the counterfeit coin is 5 and lighter than the other coins, then, in the first weighing, the right pan goes down, in the second weighing the left pan goes down, and in the last weighing the left side goes down. This produces the base three number (-1,1,1)=-9+3+1=-5, indicating that the counterfeit coin is the fifth coin and it is lighter than the other coins. The coins 7, 9, 11, and 12 are treated oppositely. If the counterfeit coin is 7 and is heavier than the other coins, then, in the first weighing, the right pan goes down, in the second weighing the left pan goes down, and in the last weighing the right pan goes down. This produces the base three number (-1,1,-1)=-9+3-1=-7, indicating, for this special case, that the counterfeit coin is the seventh coin and it is heavy because we reverse the sign for the specially treated coins.
You cannot fail to notice that this method should be able to handle thirteen coins. However, to maintain the same number of coins per pan, we need a coin guaranteed to be good. The table below takes care of this situation with G representing the known good coin.
left pan right pan
(9) first weighing 5,6,8,10,13 7,9,11,12,G
(3) second weighing 2,3,4,7,13 5,6,11,12,G
(1) third weighing 1,4,10,11,13 2,5,7,8,G