Drive a BLDC motor with Mega 2560

Hi everyone,
I've just got an assignment to build a controller together with Arduino mega 2560 (The only piece we have in lab) and drive a BLDC motor for a small car. The motor is estimated between 200W to 600w. And the basic function includes controlling the motor to run at it's most efficiency speed/output. (although this is a later part of the story.)

I need to build up a PWM controller which adjust the motor speed to the speed reference signal input to the controller. And the first step is to get a code which runs inside the Arduino for such application.
Understand that there are huge amount of information about Arduino controller and I'm really lost in those thousands of search result.
Can someone help me with a PWM code that is already workable inside the mega 2560 so that I can test it and learn from there?

  1. What BLDC motor is that (with built-in Hall sensors) or not)?
  2. Do you already have the commutator for driving the motor or will that also be part of your To Do?

I don't have personal experience with BLDC and arduinos as their controllers, but I am just studying this stuff aside of my current project, so I can share some links which could help you getting a step further:

Don't forget to use the forum's search; there is a great potential that this topic already was discussed here before, e.g.:
https://forum.arduino.cc/index.php?topic=276741.0