You might have a faulty speed sensor. I don't where it is on Mazda but on our CR-V 98, it is attached to the transmission. It is a spur gear and each revolution has an equivalent speed.Ive got this problem with my mazda 6 2004, my speedometer not working. But there were time that it works when tcs light is on. What could be the cause of this?