We present an example of a construction of an embedded software system-a controller-from the formal specification to executable code. The CO-OPN (Concurrent Object Oriented Petri Net) formal specification language is used for modelling the controller and the associated hardware system with the inherent limitation of its physical components. CO-OPN formal language is based on coordinated algebraic Petri nets. The CO-OPN model can be used to verify some properties of the controller in the concrete physical environment. This is achieved by constrained animation of the valid prototype produced by automatic code generation. The possibility to incrementally refine the generated code can be used to obtain a more efficient implementation.