first working version with frequency = 250