Read the specifications and just do it. You're just making things happen at a regular interval (approximately 7458 CPU cycles).
http://wiki.nesdev.com/w/index.php/APU_Frame_CounterNote that you need to multiply by 2 to turn APU cycles listed on that page into CPU cycles.
this info might be wrong, will edit soon.
Mode 0:
7457 cpu cycles, clock envelopes and linear counter
7456 cpu cycles since the last one, clock envelopes, linear counter, sweep and length counters
7458 cpu cycles since the last one, clock envelopes and linear counter
7458 cpu cycles since the last one, clock envelopes, linear counter, sweep and length counters, make an IRQ happen if enabled
Mode 1:
7457 cpu cycles, clock envelopes and linear counter
7456 cpu cycles since the last one, clock envelopes, linear counter, sweep and length counters
7458 cpu cycles since the last one, clock envelopes and linear counter
7458 cpu cycles since the last one, clock nothing
7452 cpu cycles since the last one, clock envelopes, linear counter, sweep and length counters