issues on creating my own PID from scratch

I want to write my own PID controller code for controlling a DC motor speed.The PID output is fed to a PWM unit to vary the input of DC motor to set speed at certain rpm.The DC motor already as a tachometer which gives the absolute speed in voltage(0-10volts).I studied some articles and read the forum on PID controllers. 1>My basic question is at what intervals do i need to take samples for PID? 2>And since intergral control is sum of errors.Do I start summing since the code starts and sum to infinite or do i need to reset this sum when i take another sample? 3>Do i really need a interrupt function or can i simply create a function and call it I would be grateful on any input towards this. thanks

Is there some reason to write your own? There is a PID control library already available.

thankyou for your reply.I want to learn and understand it.Using just the library wont help me to grasp the concept very well.

There is a link on that page to You'll learn more than enough studying Brett's material.