Frédéric Fort
email: frederic.fort@univ-lille.fr

Julien Forget
email: julien.forget@univ-lille.fr

Code generation for multi-phase tasks on a multi-core distributed memory platform

Keywords: generation, PREM, distributed memory

Ensuring temporal predictability of real-time systems on a multi-core platform is difficult, mainly due to hard to predict delays related to shared access to the main memory. Task models where computation phases and communication phases are separated (such as the PRedictable Execution Model [23]), have been proposed to both mitigate these delays and make them easier to analyze.

, that automatically translates a high-level synchronous dataflow system specification into a PREM-compliant C program. By automating the production of the PREM-compliant C code, low-level implementation concerns related to task communications become the responsibility of the compiler, which saves tedious and error-prone development efforts.

Introduction

Multi-core hardware platforms are increasingly being used for the implementation of embedded systems, due to their potential for increasing system performances. However, implementing real-time systems on such platforms remains complex, mainly because cores share access to a central memory. This leads to contentions, which cause significant execution delays that are hard to predict, because they require to finely analyse task codes, task interferences and the contention resolution mechanisms [START_REF] Pellizzoni | Impact of peripheral-processor interference on wcet analysis of real-time embedded systems[END_REF].

To simplify the analysis of task interferences, the PRedictable Execution Model (PREM) [START_REF] Pellizzoni | A predictable execution model for cots-based embedded systems[END_REF] advocates to decouple communication phases from computation phases. For instance, the AER task model [START_REF] Durrieu | Predictable flight management system implementation on a multicore processor[END_REF], a declination of the Partially funded by the French National Research Agency, Corteva project (ANR-17-CE25-0003) 1 PREM model, splits each task of the system into three phases. The Acquisition phase loads task data and instructions from the main memory into the core's local memory. Then, the Execution phase performs the task computations using only local memory. Finally, the Restitution phase copies the results of the E-phase back into the main memory, for use by other tasks. This simplifies timing analysis because: 1) communication phases are clearly identified, so the system scheduler can schedule communications [START_REF] Alhammad | Schedulability analysis of global memorypredictable scheduling[END_REF][START_REF] Maia | Schedulability analysis for global fixed-priority scheduling of the 3-phase task model[END_REF] and avoid contentions; 2) worst-case execution time analysis (WCET) of computation phases does not need to take bus contentions into account [START_REF] Pellizzoni | A predictable execution model for cots-based embedded systems[END_REF].

Manually implementing a PREM-compliant program is tedious, unintuitive and error-prone. Another solution is to rely on a compiler that automates phases separation. For instance, PREM-compliant compilation for the LLVM framework has been proposed in [START_REF] Forsberg | Heprem: Enabling predictable gpu execution on heterogeneous soc[END_REF][START_REF] Matějka | Combining prem compilation and ilp scheduling for highperformance and predictable mpsoc execution[END_REF]. Our approach also tackles PREMcompliant C code generation but starts from a higher level of abstraction than previous approaches.

Contribution

We present an extension to an existing compiler, which produces PREM-compliant code. The input of the compiler is a Prelude synchronous data-flow program [START_REF] Pagetti | Multi-task implementation of multi-periodic synchronous programs[END_REF]. The output of the compiler is concurrent multi-task PREM-compliant C code. The synchronous semantics is close to the PREM model, making the translation into PREM natural. We target a multi-core platform with distributed memory: one shared main memory plus one private scratchpad memory (SPM) for each core. According to a predefined distribution of tasks onto cores, the compiler generates a separate C code for each core. The code includes mechanisms to execute tasks periodically, synchronise task communications across cores and perform data transfers between local memories and the main memory. The main advantage of our approach is to simplify the development process, by automating the translation from the high-level specification in Prelude to the low-level implementation in C. In particular, concerns related to task communications become the responsibility of the compiler.

Validation We experiment with the Rosace case study [START_REF] Pagetti | The rosace case study: From simulink specification to multi/many-core execution[END_REF], running on an FPGA platform with two NIOS-II Altera processors, using the Erika Real-Time Operating System by Evidence [START_REF]Erika enterprise[END_REF]. Because we rely on a compiler to produce the C code, we can easily compare PREM and non-PREM implementations (we simply need to recompile the Prelude program with different options). Because we rely on reconfigurable hardware (the FPGA), we can easily compare architectures with scratchpad memory or with cache memory.

Related works

Decoupling communications from computations, so as to improve timing predictability, was first proposed in the PRedictable Execution Model (PREM) approach [START_REF] Pellizzoni | A predictable execution model for cots-based embedded systems[END_REF]. PREM was first designed for improving timing predictability of I/O peripheral accesses for a single core hardware, but was then extensively studied in the context of multi-core hardware where cores contend for shared resources.

The majority of works on PREM task models concerns timing analysis. In [START_REF] Burgio | A memory-centric approach to enable timing-predictability within embedded many-core accelerators[END_REF], authors have demonstrated the benefit of using PREM to reduce the pessimism of WCET analysis. The problem of designing scheduling algorithms and schedulability analysis for PREM tasks has drawn a lot of attention [1-3, 5, 14, 15, 18, 25, 30-32]. Schedulability analysis is out of the scope of the present paper. Our work relies on classic partitioned Deadline-Monotonic scheduling, using semaphores to implement inter-task synchronisations related to datacommunications.

Other works have focused on the implementation of PREM-compliant applications. OS-level support or hardware drivers for the execution of PREM tasks have been proposed in [START_REF] Capodieci | Sigamma: Server based integrated gpu arbitration mechanism for memory accesses[END_REF][START_REF] Tabish | A real-time scratchpad-centric os for multi-core embedded systems[END_REF][START_REF] Tabish | A reliable and predictable scratchpad-centric OS for multi-core embedded systems[END_REF][START_REF] Wasly | A dynamic scratchpad memory unit for predictable real-time embedded systems[END_REF]. Converting legacy code into PREMcompliant code is a non-trivial task, which requires a very good understanding of the code to convert. Therefore, solutions have been proposed to automate this conversion. Light-PREM [START_REF] Mancuso | Light-prem: Automated software refactoring for predictable execution on COTS embedded systems[END_REF] is a software refactoring approach to produce PREM-compliant code from legacy code, based on memory profiling tools. In [START_REF] Soliman | WCET-Driven Dynamic Data Scratchpad Management With Compiler-Directed Prefetching[END_REF], authors proposed a compilation technique that produces code that executes memory access phases in parallel with computation phases. The authors of [START_REF] Forsberg | Heprem: Enabling predictable gpu execution on heterogeneous soc[END_REF] proposed a technique for compiling a GPU kernel into PREM-compliant code. In [START_REF] Matějka | Combining prem compilation and ilp scheduling for highperformance and predictable mpsoc execution[END_REF], authors present a compiler based on the LLVM infrastructure that refactors legacy code into PREM code.

Our work is orthogonal to these approaches, in that we start from a highabstraction language that naturally fits with the hypotheses of the PREM model. The Prelude language [START_REF] Pagetti | Multi-task implementation of multi-periodic synchronous programs[END_REF], belongs to the Synchronous Languages family. Compilation of synchronous languages for distributed hardware platforms was studied in [START_REF] Aubry | Synchronous distribution of signal programs[END_REF][START_REF] Girault | Automatic rate desynchronization of embedded reactive programs[END_REF][START_REF] Grandpierre | Optimized rapid prototyping for real-time embedded heterogeneous multiprocessors[END_REF], but with a single execution thread per CPU. Compilation into multi-thread/multi-task code was proposed for Prelude in [START_REF] Pagetti | Multi-task implementation of multi-periodic synchronous programs[END_REF], then for control-flow synchronous languages in [START_REF] Yip | The forec synchronous deterministic parallel programming language for multicores[END_REF][START_REF] Yuan | Compiling esterel for multi-core execution[END_REF] and for Scade in [START_REF] Pagano | A model based safety critical flow for the aurix multi-core platform[END_REF]. Unlike Prelude, [START_REF] Pagano | A model based safety critical flow for the aurix multi-core platform[END_REF][START_REF] Yip | The forec synchronous deterministic parallel programming language for multicores[END_REF][START_REF] Yuan | Compiling esterel for multi-core execution[END_REF] do not target systems with multiple periodicity constraints. In [START_REF] Pagetti | Automated generation of time-predictable executables on multicore[END_REF], a first version of PREM-compliant code generation for Prelude was proposed. However, it relies on a non-preemptive schedule computed off-line, and executed in bare metal. In comparison, the present work relies on preemptive on-line scheduling using the Erika OS.

Model

Hardware model

We consider a multi-core architecture with distributed memory. Each processor ρ i ∈ Π has access to a global shared memory M G and to a private memory M i . We assume a static allocation of code and data to SPMs. Dynamic SPM allocation, where SPM address ranges can be shared between elements with non-overlapping lifespans is not considered here (unlike e.g. [START_REF] Soliman | WCET-Driven Dynamic Data Scratchpad Management With Compiler-Directed Prefetching[END_REF]). Compared to a cache-based architecture, in our case distributed memory is apparent in the program code (local memory is explicitly addressable). Thus, memory transfers between private and global memories are handled by the Prelude compiler. This implies more predictable memory accesses without overburdening the programmer.

Scheduling

We assume a fixed-priority partitioned scheduler (Deadline-Monotonic in our Erika implementation). Task partitioning and schedulability analysis are out of the scope of this paper, so priority assignments and allocation of tasks to processors are considered to be inputs of our model. We use semaphores to implement task synchronisations required for data-communications purposes. We do not allow simultaneous execution of communication and computation phases on the same processor (unlike e.g. [START_REF] Soliman | WCET-Driven Dynamic Data Scratchpad Management With Compiler-Directed Prefetching[END_REF]).

Prelude

Prelude is a synchronous data-flow programming language. In comparison to more traditional synchronous languages, it adds primitives dedicated to the specification of real-time constraints and targets compilation into multi-task code. A simple Prelude program, which we will use as a running example for the rest of the paper, is provided in Figure 1. The program first declares imported nodes, sensors and actuators, whose behaviour is programmed outside Prelude as C functions. The main node M details the data-flows between the previous nodes. For instance, C produces value tmp, which is used by actuator D. Periods are specified on the inputs of the main node, (e.g. A has period 5 and offset 0). The Prelude compiler deduces the periods of node calls from the period of their inputs (hence, the data-flow nature of the language). In addition, it requires the inputs and outputs of an imported node call to be synchronous, i.e. to have the same rate. Since the inputs/outputs of node C initially have different rates, we use rate transition operators to make them synchronous: A/^2 produces a flow twice slower than A. Similarly tmp*^2 produces a flow twice faster than tmp, so the compiler infers that D has rate (5, 0).

The synchronous semantics is a natural match with the PREM model, because it assumes that programs and functions repeatedly execute the following sequence: 1) acquire all their inputs simultaneously; 2) perform computations with no side-effect on variables other than their outputs; 3) produce all their outputs simultaneously.

Task graph

The translation of a Prelude program into C code consists of two main steps. First, the Prelude program is translated into a task graph. Then, the task graph is translated into C code. The present work did not require any modification on the first step, the reader is referred to [START_REF] Forget | Scheduling Dependent Periodic Tasks Without Synchronization Mechanisms[END_REF] for details. The task graph is a directed acyclic graph (T , D). Each task τ i ∈ T releases a sequence of non-overlapping periodic jobs with a period T i , where τ n i denotes the n-th job of τ i . Since we assume partitioned scheduling, each task τ i ∈ T is assigned to a processor ρ i ∈ Π and may only execute on that processor. We denote π i for that processor.

The set D defines the data-dependencies between jobs, using a model derived from [START_REF] Forget | Scheduling Dependent Periodic Tasks Without Synchronization Mechanisms[END_REF], which allows for data-dependencies between tasks of different periods. We denote τ n i → τ m j when (τ n i , τ m j ) ∈ D, which means that τ n i produces data that is used by τ m j . Let H i,j = lcm(T i , T j ) be the hyperperiod of τ i and τ j . We impose that communications follow a pattern that repeats each H i,j , which is commonly the case in real-time applications [START_REF] Forget | Scheduling Dependent Periodic Tasks Without Synchronization Mechanisms[END_REF]. A dependency between two tasks τ i and τ j is defined by a set of job pairs denoted D i,j , where by definition:

∀(τ n i , τ m j ) ∈ D i,j : n < Hi,j Ti ∧ m < Hi,j
Tj . Then, we obtain D by unrolling all D i,j across multiple hyperperiods:

D = {(τ p i , τ q j ) |∃k ∈ N, τi, τj ∈ T , (τ n i , τ m j ) ∈ Di,j, (p, q) = (n, m) + (k Hi,j Ti , k Hi,j Tj )}
The task graph for our running example is depicted Figure 2. Each two successive jobs of τ D depend on the same job of τ C . One out of two successive values produced by task τ A is used by task τ C . τ B and τ C have non-harmonic periods:

τ 0 C , τ 1 C , τ 2
C depend on data produced by respectively τ 0 B , τ 1 B and τ 3 B ; this pattern repeats every H B,C .

Multi-phase communications

In this section, we focus on task data-dependencies, detail their semantics, and how they translate into the PREM model. In this paper, we use the conventions of the AER task model [START_REF] Durrieu | Predictable flight management system implementation on a multicore processor[END_REF], a declination of the PREM model.

We assume that task communications follow a causal semantics. For a given execution schedule, let begin(τ n i ) denote the date τ n i starts executing and end(τ n i ) denote the date at which it completes in this schedule. Causal communication semantics impose that:

5 A B C D ρ1, T=5 ρ1, T=6 ρ0, T=10 ρ0, T=5 D A,C = {(τ 0 A , τ 0 C )} D B,C = {(τ 0 B , τ 0 C ), (τ 1 B , τ 1 C ), (τ 3 B , τ 2 C )} D C,D = {(τ 0 C , τ 0 D ), (τ 0 C , τ 1 D )} Figure 2: Running example Phase Dependency Phase Dependency E A R A D A,C E B R B D B,C A C D B,C , D A,C E C D C,D E D D C,D
Table 1: Phases and related data-dependencies

• Any job τ n i produces all its output data at end(τ n i ); • Any job τ n i acquires all its input data at begin(τ n i ); • For all τ n i → τ m j , we must have: end(τ n i ) < begin(τ m j )

AER phases

Let us now detail how causal communications translate into the AER model of [START_REF] Durrieu | Predictable flight management system implementation on a multicore processor[END_REF]. Each task τ i is divided into three phases. During the Acquisition phase (A i ), data is copied from M G into M i . The Execution phase (E i ) then executes using only M i . Finally, in the Restitution phase (R i ), the results of the Execution phase are copied back from M i into M G . In our implementation, not all tasks have A-and E-and R-phases. First, tasks without any incoming data-dependencies, have no A-phase. Tasks without outgoing data-dependencies, have no R-phase. Second, we say that a datadependency τ n i → τ m j is local iff π i = π j , else it is distant. We also say that a task τ j is colocated with τ i , iff π i = π j . If a task has only local incoming data-dependencies, it has no A-phase (no need to use M G ). The same applies for outgoing data-dependencies and R-phases. Phases for our running example are detailed in Table 1. For instance, τ C copies both its inputs during A C . Since τ C and τ D are colocated, their datadependencies are directly handled by E C and E D .

Precedence constraints

To respect the causal semantics of data-dependencies, we impose precedence constraints between phases. Some data-dependencies impose redundant precedence constraints that can safely be removed (e.g.

τ 0 C → τ 1 D because τ C is twice slower than τ D ): relevant(τ n i → τ m j ) ⇔ τ n i → τ m j , m < m∧ τ n i → τ m j , n < n Let X n i → Y m j
denote a phase precedence constraint (which imposes that end(X n i ) < begin(Y m j )). By definition, we have:

∀A n i , E n i , R n i : A n i → E n i → R n i ( 1
)
∀τ n i , τ m j , relevant(τ n i → τ m j ), π i = π j : R n i → A m j ( 2
)
∀τ n i , τ m j , relevant(τ n i → τ m j ), π i = π j : E n i → E m j (3)
In our running example, precedence constraints between τ C and τ D stem from Equation 3, and others from Equation 2.

AER code generation

An overview of the compilation of a Prelude program is provided in Figure 3. The Prelude program is compiled into one C file per CPU and one C file for the global memory M G . Each CPU code contains one function per phase allocated to that partition, and related communication and synchronisation code (see Figure 4 for instance). The M G code contains data shared for inter-processor communication purposes. In addition the C application contains code not generated by Prelude: 1) for each task, a user-provided imported function, to be executed by jobs of the corresponding E-phase; 2) the OS specific code that integrates the generated files into the final application.

In Erika one processor assumes the master role, which is in charge of declaring and initialising shared data (in our case, of handling the M G data). The compilation of the C code produces one binary per processor ρ i , to be stored in M i , which contains the instructions and local data of ρ i . The binary of the master processor also contains shared communication data, which the master processor copies at boot-time into M G .

In our running example, processor ρ 0 is the master processor. As an example, the code generated for tasks τ A , τ C is provided in Figure 4. It is detailed in the next sections.

Communication buffers

For each input or output of each task, the compiler allocates a working variable in M i that is only accessed by the phases of that task (variables suffixed by _loc

Multi-rate communications

The Prelude compiler determines for each D i,j (see [START_REF] Pagetti | Multi-task implementation of multi-periodic synchronous programs[END_REF] for more details):

• The size of the communication buffer i_j_buff (e.g. C_D_buff is of size 2);

• A function must_change_i_j, which tells when to change the cell of i_j_buff each τ m j reads from (e.g. must_change_C_D always returns true);

• A function must_write_i_j, which tells for each τ n i if it must write in i_j_buff (e.g. must_write_A_C tells that only one out of two successive jobs of τ A writes in the buffer);

• A function must_wait_i_j, which tells if τ m j must wait on the communication semaphore;

• A function must_post_i_j, which tells if τ n i must post on the communication semaphore.

In the Erika implementation, each data-dependency D i,j is associated with a semaphore. Before copying the input for τ j , if must_wait_i_j returns true we wait on the associated semaphore (Figure 4 Line 4). After copying the output for τ i , if must_post_i_j returns true we post on the associated semaphore (Line 11). This ensures that phases execution respect the precedence constraints defined in Section 4.2.

Validation

We validate our work by implementing the Rosace [START_REF] Pagetti | The rosace case study: From simulink specification to multi/many-core execution[END_REF] case study on an FPGA board with two softcores, using the Erika OSEK-compliant RTOS.

Hardware platform

In order to allow the comparison between different hardware architectures, we rely on an FPGA development board, a Cyclone III by Altera with two NIOS-II softcores, depicted in Figure 5. The data and instruction master ports connect the processor to the Avalon Interconnect Fabric, a partial crossbar with a master/slave behaviour, which serves as a hub to access shared resources of the board. In our case, only NIOS-II processors are masters. Each master is only connected to a subset of slaves. Accesses from two masters to two different slaves can execute simultaneously. Simultaneous accesses to the same slave are arbitrated with a round-robin policy. Tightly-coupled data and instruction ports offer private contention-free access to processor-dedicated on-chip memories. Each processor has access to a tightly-coupled memory for data and to another for instructions. These memories serve as scratchpad memory (M i ). Processors share access to an on-chip shared RAM (M G ). On a real embedded board, the shared memory would be an external component (e.g. SDRAM, SRAM), with typically longer access time. Therefore, our shared RAM is controlled by an artificially slower clock which mimics these slower accesses. Finally, processors are also connected to an on-chip mutex, on-board IOs and timers, through the master ports. We use the mutex to implement synchronisations, because the processors do not have dedicated built-in primitives.

In addition to the scratchpad architecture we just detailed, we implement a cache-based architecture. It features a cache on each master port, with access performances similar to the scratchpads. The FPGA has tight space limitations (Erika is not available on more recent FPGA boards), memory sizes are reported in Table 2. Space reserved for SPM in the scratchpad-based architecture is instead reserved for the main memory in the cache-based architecture.

OSEK-compliant code

Erika is an OSEK-compliant RTOS, so tasks must all be declared statically in an OIL configuration file, which is generated by the Prelude compiler in our case. The OIL file is divided into several sections, in particular:

• CPU_DATA sections, which describe the hardware processors (identifier, source files, Hardware Abstraction Layer, stack address space, ...);

• TASK sections define the task set (CPU allocation, events to handle synchronisations, stack size, ...). In our case, each phase is declared as a separate TASK;

• EVENT sections which enable us to implement binary semaphores.

Rosace case study

We use the Rosace [START_REF] Pagetti | The rosace case study: From simulink specification to multi/many-core execution[END_REF] case study, a longitudinal flight controller, to validate our work. It measures the airspeed, vertical speed and altitude of the aircraft, and controls the aircraft accordingly. We simplified parts dedicated to environment simulation (which are not meant to be embedded), so that corresponding tasks return dummy values.

The main benefit of the case study is to demonstrate that the Prelude compiler can automatically generate the Rosace PREM-compliant C code for our distributed memory platform. This also enables us to compare different hardware architectures as shown in Figure 6. We use the response time of each task for the comparison. The figure shows the speedup of PREM code on the SPMbased architecture with respect to non-PREM on the cache-based architecture (e.g. speedup of 2 means that SPM+PREM is twice as fast as cache+non-PREM). We provide results for different RAM clock speeds: either the same as the global clock (red), 4 times slower (green) or 8 times slower (blue, which corresponds to observed latencies on an external SRAM on similar boards). We provide mean results for 20 executions for each configuration (variance is very low).

The observed speedup is proportional to the RAM clock. When the shared RAM is the slowest, the average speedup is 6.29 with a standard deviation of 2.19. When the shared RAM has the same clock as the global clock, the SPM implementation barely outperforms the cache one. The average speedup is 1.09 with a standard deviation of 0.31. This is likely due to the OS overheads of the PREM-compliant implementation, since each phase is implemented as a separate task.

Conclusion

We presented a method to translate synchronous data-flow programs into multitask PREM-compliant C code, targeted for execution on a multi-core platform with distributed memory using an industrial RTOS. We validated our approach by implementing the Rosace case study on an FPGA platform. We compared the performance of a scratchpad-based architecture with PREM-compliant code, with a cache-based architecture with non-PREM code. Switching between both versions, only requires to change the compilation options. Schedulability anal- ysis, which requires to consider multi-rate precedence constraints in multi-core, is left for future works.

  imported node C(i,j: int) returns (o:int) wcet 2; sensor A wcet 1; sensor B wcet 1; actuator D wcet 1; node M(A: int rate (5,0); B: rate (6,0)) returns (D: int) var tmp; let tmp=C(A/^2, B*^3/^5); D=tmp*^2; tel

Figure 1 :

 1 Figure 1: Prelude running example.

Figure 5 :

 5 Figure 5: The hardware design.

Figure 6 :

 6 Figure 6: Observed speedup (higher is better)

Table 2 :

 2 Size of memories for the experiments

	Memory (SPM architecture)	Size
	Data SPM	ρ 0 : 5kB, ρ 1 : 4kB
	Instruction SPM	ρ 0 : 12kB, ρ 1 : 8kB
		Main	2kB
	Memory (cache architecture)	Size
	Data cache	2kB
	Instruction cache	4kB
		Main	29kB
	Instr.
	scratchpad 0	NIOS	NIOS
	Data	CPU 0	CPU 1
	scratchpad 0

or _out in Figure 4). It allocates a communication buffer for each D i,j (variables suffixed by _buff in Figure 4). If τ i and τ j are colocated, the buffer resides in M i (e.g. C_D_buff in M 0 ), otherwise it resides in M G (e.g. A_B_buff).

In the E-phase code, the call to the imported function only operates on working variables (e.g. Figure 4 Line 17). Before this call, we must copy input data from communication buffers into working variables. After this call we must copy output data from working variables into communication buffers. For colocated communications, the copies are directly performed by the E-phase (Line 18). For distant communication, they are performed by the A/R-phases (Lines 7 Column 1, and 8 Column 2). We use the OS-specific functions read val and wrive val to perform copies between M i and M G .


Amélie Wannebroucq

Seydou Ouédraogo

Rita Meunier-Prest

Jean-Moïse Suisse

Mabinty Bayo

Marcel Bouvet
email: marcel.bouvet@u-bourgogne.fr

Seydou Ouedraogo

On the interest of ambipolar materials for gas sensing

Based on the electrochemical properties of a series of metallophthalocyanines this article shows that the phthalocyanine bearing four alkoxy groups and twelve fluorine atoms behaves approximately as those with eight fluorine atoms. This indicates that the electrondonating effect of one alkoxy group balances the electro-withdrawing effect of one fluorine atom. We engaged three metallophthalocyanines, namely the octafluoro copper phthalocyanine, Cu(F 8 Pc), an octaester metallophthalocyanine and a phthalocyanine bearing four alkoxy groups and twelve fluorine atoms, Zn(T 4 F 12 Pc), in building original conductometric transducers that are Molecular Semiconductor -Doped Insulator heterojunctions (MSDIs) in association with the highly conductive lutetium bisphthalocyanine, LuPc 2 . Whereas the octaester derivative and Zn(T 4 F 12 Pc) exhibited a negative response to ammonia, as expected for p-type materials, Cu(F 8 Pc) exhibited a particular behavior. At low humidity levels, 30 and 10 % rh, the current of the Cu(F 8 Pc)/LuPc 2 MSDI decreases, similarly to p-type devices, but at higher relative humidity values, 70 % rh, the current increases under ammonia, which is the signature of a n-type behavior. This ambipolar behavior is unique amongst semiconducting sensing materials. This work opens the way to the study of ambipolar materials as sensing materials for the development of a new type of conductometric gas sensors.

Graphical abstract

Highlights

 Ambipolar materials exhibit a unique feature in chemosensing.  Humidity can act as a trigger between p and n-type behaviors.  The tuning of the electronic properties of sensing materials is of importance.

Introduction

Most molecular materials used in organic electronics only exhibit an unipolar behavior, with either electrons or holes as majority charge carriers [START_REF] Zhao | 25th Anniversary article: Recent advances in n-type and ambipolar organic field-effect transistors[END_REF][START_REF] Zaumseil | Electron and ambipolar transport in organic field-effect transistors[END_REF]. However, devices that can transport both electrons and holes are very important to design complementary integrated circuits without requiring the implementation of two types of field-effect transistors with por n-type channels. The first ambipolar behavior ever observed in an OFET was with the lutetium bisphthalocyanine, LuPc 2 , as molecular semiconductor [START_REF] Guillaud | Field-effect transistors based on intrinsic molecular semiconductors[END_REF]. Although the term ambipolar was not used in the published paper, the authors did observe both n and p channels, under vacuum and in air, respectively. This clearly indicates that the density of charge carriers of both p-and n-type can be high in LuPc 2 , depending on the experimental conditions. This is a consequence of its particularly low energy gap, ca. 0.5 eV [START_REF] André | Electrical and magnetic properties of thin films and single crystals of bis(phthalocyaninato)lutetium[END_REF][START_REF] Bouvet | Electrical properties of rare earth bisphthalocyanine and bisnaphthalocyanine complexes[END_REF], resulting from its radical nature.Moreover, in this case, the SiO 2 dielectric material was modified by long alkyl chains, known for avoiding charge trapping at the semiconductor -dielectric material interface [START_REF] Bouvet | Electrical properties of rare earth bisphthalocyanine and bisnaphthalocyanine complexes[END_REF].

Generally, ambipolar devices result from the combination of two materials, including blends of polymers. There are several examples in the literature, including poly-phenylene vinylene or polyhexylthiophene as hole-transporting material with a fullerene derivative (PCBM) as electron-transporting semiconductor [START_REF] Meijer | Solution-processed ambipolar organic field-effect transistors and inverters[END_REF], a pentacene derivative associated with a perylenediimide [START_REF] Shim | Laterally-stacked, solutionprocessed organic microcrystal with ambipolar charge transport behavior[END_REF] or a perfluorophthalocyanine [START_REF] Jea | An organic microcrystal array-embedded layer: highly directional alternating p-and n-channels for ambipolar transistors and inverters[END_REF] as n-type materials, blends of benzimidazolebenzophenanthroline ladder polymer (BBL) and copper phthalocyanine [START_REF] Babel | Ambipolar charge transport in air-stable polymer blend thin-film[END_REF],

and blends of two phthalocyanines, one bearing octyloxycarbonyl substituents, Cu((COOC 8 H 17 ) 8 Pc) , and the other one alkoxy chains, Cu((OC 8 H 17 ) 8 Pc) [START_REF] Wu | Two-step solution-processed twocomponent bilayer phthalocyaninato copper-based heterojunctions with interesting ambipolar organic transiting and ethanol-sensing properties[END_REF]. Organic heterostructures, including p-n heterojunctions and ambipolar transistors, have been described in detail by by H. Wang and D. Yan [START_REF] Wang | Organic heterostructures in organic field-effect transistors[END_REF]. We can also cite interesting reviews on ambipolar OFETs, by H. Sirringhaus [START_REF] Zhao | 25th Anniversary article: Recent advances in n-type and ambipolar organic field-effect transistors[END_REF][START_REF] Zaumseil | Electron and ambipolar transport in organic field-effect transistors[END_REF][START_REF] Sirringhaus | Device physics of solution-processed organic field-effect transistors[END_REF][START_REF] Cornil | Ambipolar transport in organic conjugated materials[END_REF]. The historical LuPc 2 example aside, several families of molecules were reported that exhibit an ambipolar behavior with a single semiconductor layer capable of conducting both electrons and holes. For instance, the [START_REF] Meijer | Solution-processed ambipolar organic field-effect transistors and inverters[END_REF][START_REF] Meijer | Solution-processed ambipolar organic field-effect transistors and inverters[END_REF]-phenyl-C61-butyric acid methyl ester (PCBM) -a C60 derivative that is known as a n-type material can exhibit a p-type channel with gold electrodes on SiO 2 treated with hexamethyldisilazane as the dielectric material [START_REF] Anthopoulos | Ambipolar organic field-effect transistors based on a solution-processed methanofullerene[END_REF]. In the same way, a donor-acceptor conjugated polymer derived from BDOPV (benzodifurandione-based oligo p-phenylene vinylene) exhibited a n-type behavior under vacuum and an ambipolar behavior when doped by oxygen [START_REF] Lei | A BDOPV-based donor-acceptor polymer for high-performance n-type and oxygen-doped ambipolar field-effect transistors[END_REF].

From these examples, it is clear that particular operating conditions of the devices and specific atmospheres are required to observe an ambipolar charge transport.

Donor-acceptor copolymers based on naphthalenediimide acceptor and (E)-2-(2-(thiophen-2-yl)vinyl)thiophene donor [START_REF] Chen | Naphthalenediimide-based copolymers incorporating vinyl-linkages for high-performance ambipolar field-effect transistors and complementary-like inverters under air[END_REF], or on polyfluorene derivatives [START_REF] Meijer | Solution-processed ambipolar organic field-effect transistors and inverters[END_REF], which have a band gap energy of 1.55 eV, are also nice examples of single component ambipolar materials.There is also the work of Y. Chen on lanthanide double decker [START_REF] Kong | Flexible, ambipolar organic field-effect transistors based on the solution-processed films of octanaphthoxy-substituted bis(phthalocyaninato) europium[END_REF] and triple decker complexes [START_REF] Kan | High-performance air-stable ambipolar organic field-effect transistor based on tris(phthalocyaninato) europium(III)[END_REF][START_REF] Kong | Air-stable ambipolar field-effect transistor based on a solution-processed octanaphthoxy-substituted tris(phthalocyaninato) europium semiconductor with high and balanced carrier mobilities[END_REF]. These cases are similar to the abovementioned LuPc 2 complex, since the ambipolarity results from the low energy gap, ca. 0.5 and 1.0 eV for lanthanide double and triple decker complexes, respectively. In addition, halogenated tetracene and pentacene and heteroatoms containing acenes [START_REF] Tang | Ambipolar, high performance, acene-based organic thin film transistors[END_REF][START_REF] Liang | The position of nitrogen in Nheteropentacenes matters[END_REF][START_REF] Zeng | High performance CMOS-like inverter based on an ambipolar organic semiconductor and low cost metals[END_REF], quinoidal quaterthiophen derivatives and tetracyanothienoquinoids [START_REF] Watanabe | Microcrystallization of a solution-processable organic semiconductor in capillaries for high-performance ambipolar field-effect transistors[END_REF][START_REF] Li | Five-ring fused tetracyanothienoquinoids as highperformance and solution-processable n-channel organic semiconductors: effect of the branching position of alkyl chains[END_REF] can also lead to an ambipolar behavior.

The ambipolar character of a material can be anticipated from the knowledge of the energy of its frontier orbitals, HOMOs and LUMOs [START_REF] Usta | Design, synthesis, and characterization of ladder-type molecules and polymers. Airstable, solution-processable n-channel and ambipolar semiconductors for thin-film transistors via experiment and theory[END_REF], but relatively to the work function of the electrodes, since it determines whether charge injection is likely [START_REF] Zaumseil | Electron and ambipolar transport in organic field-effect transistors[END_REF]. However, the emergence of such a behavior and its observation is highly dependent on the morphology of materials [START_REF] Babel | Ambipolar charge transport in air-stable polymer blend thin-film[END_REF]. Tuning of electronic properties of materials can be achieved by the introduction of electron-donating or electron-withdrawing substituents on macrocyclic molecules [START_REF] Usta | n-Channel semiconductor materials design for organic complementary circuits[END_REF][START_REF] Chen | Tuning the semiconducting nature of bis(phthalocyaninato) holmium complexes via peripheral substituents[END_REF][START_REF] Mei | Side chain engineering in solution-processable conjugated polymers[END_REF]. It is well-known that fluorine substituted macrocycles exhibit stabilized frontiers orbitals compared to non substituted counterparts, e.g. by 1.2 eV for hexadecafluoro-metallophthalocyanines, M(F 16 Pc), relatively to the non fluorinated phthalocyanines, MPc [START_REF] Murdey | Frontier electronic structures in fluorinated copper phthalocyanine thin films studied using ultraviolet and inverse photoemission spectroscopies[END_REF]. Thus, perfluorinated phthalocyanines are n-type materials whereas non substituted phthalocyanines are p-type materials. The introduction of fluorine atoms on the phthalocyanine ring leads to n-type semiconductors useful to get n-type OFETs [START_REF] Yang | Analyte chemisorption and sensing on n-and p-channel copper phthalocyanine thin-film transistors[END_REF] and p-n heterojunctions [START_REF] Wang | Organic heterojunction with reverse rectifying characteristics and its application in field-effect transistors[END_REF], which can be used as gas sensors [START_REF] Muzikante | A novel gas sensor transducer based on phthalocyanine heterojunction devices[END_REF]. It is worth mentioning that the effect of the central metal of metallophthalocyanines on their chemosensing properties is rather weak compared to the electronic effect of substituents on the macrocycle. However, A. C. Kummel and W. C. Trogler reported the effect of the coordination strength of analytes on the central metal for five metallophthalocyanine resistors studied towards a series of VOCs [START_REF] Bohrer | Comparative gas sensing in cobalt, nickel, copper, zinc, and metal-free phthalocyanine chemiresistors[END_REF].

Reported examples of ambipolar devices used for chemosensing are very rare. Thus, an ambipolar hybrid organic-inorganic thin film transistor, containing pentacene and zinc oxide as semiconductors, was employed as an ethanol vapor sensor [START_REF] Dutta | Hybrid organic/inorganic ambipolar thin film transistor chemical sensor[END_REF]. In p-channel accumulation mode, a decrease of current with the introduction of analyte was observed, while in the n-channel triode mode, an increase in current with analyte delivery was observed. In this case, the ambipolarity allowed for carrying out chemosensing experiments in two different operation modes. Another example is the one combining n and p phthalocyanines. The p/n bilayers were much more sensitive to ethanol than the corresponding n/p bilayer, even though in both cases the current increases under ethanol [START_REF] Wu | Two-step solution-processed twocomponent bilayer phthalocyaninato copper-based heterojunctions with interesting ambipolar organic transiting and ethanol-sensing properties[END_REF]. The same devices exhibit a current decrease under ammonia, but both with a very low sensitivity. However, the response observed is not clearly related to the ambipolar character of the devices, since the morphology of sensing material can be different in both structures.

In the case of diketopyrrolopyrrole-based ambipolar transistors, the interest of ambipolar character comes from the number of physical parameters to measure, like both electron and hole mobilities, additionally to conductivity [START_REF] Wang | A highly sensitive diketopyrrolopyrrole-based ambipolar transistor for selective detection and discrimination of xylene isomers[END_REF]. Thus, using a combined pattern-recognition method along with these multiple sensing parameters, a detection down to 40 ppm of xylene and a discrimination between xylene isomers were achieved. These few examples stress the need for studying the interest of ambipolar materials for chemosensing.

While the interest in ambipolar materials is obvious in organic electronics, it is completely looked over in conductometric sensors. Generally, in sensors, the increase or decrease of the measured electrical current gives a first indication on the nature of chemical species in the atmosphere in contact with the device. This is the reason why we want to discuss the interest of ambipolar materials for gas sensing.

In the present paper, we report on the electrochemical and chemosensing properties of three differently substituted phthalocyanines, the octafluorophthalocyanine Cu(

Characterizations

The UV-visible spectra were registered using a Shimadzu UV-2600 Spectrometer between 350 nm and 800 nm. A bare floated glass substrate was used as a reference for the thin films. The infrared spectra were recorded on a Bruker Vector 22 using KBr pellets, in transmission mode. Mass spectroscopy analysis was performed on an electrospray mass spectrometer amaZon SL (Bruker) coupled with a HPLC Ultimate The solutions were deoxygenated for 10 min with argon, and a positive overpressure of argon was maintained above the electrolyte during the entire measurement performed at room temperature.

Electrical and chemosensing measurements

Electrical measurements were carried out with Indium Tin Oxide (ITO) interdigitated electrodes (IDE) deposited onto a 1 x 1 cm² glass substrate and separated by 75 m.

Their total length was 15 mm. Thin films of phthalocyanines were prepared either by sublimation under secondary vacuum (ca. 10 -6 mbar) in a UNIVEX 250 thermal evaporator (Oerlikon, Germany), at a rate of 1 Å.s -1 , by heating in a temperature range of 400-450 °C for 1 and 450-500 °C for LuPc 2 , or by the solvent cast technique, from DMF solutions. The workbench used for NH 3 exposure, at different relative humidity (rh) values, was described previously [START_REF] Gaudillat | Bias and humidity effects on the ammonia sensing of perylene derivative/lutetium bisphthalocyanine MSDI heterojunctions[END_REF]. Ammonia gas, 1000 ppm in synthetic air and synthetic air were used from standard cylinders, purchased from Air Liquide, France. The total flow was in the range 0.5-0.55 NL.min -1 depending on ammonia concentration and the volume of the test chamber was 8 cm 3 . Gas sensing experiments were carried out in a dynamic fashion, with 4 min-long rest periods alternating with 1 min-long exposure periods. In the present study, all the electrical measurements were carried out at the lab temperature (18-22 °C) unless otherwise specified.

Results and Discussion

Electrochemical studies

From the electrochemical data reported for the zinc tetra-2-(2-thienyl)ethoxy}phthalocyanine [START_REF] Obirai | Synthesis, electrochemical and electrocatalytic behaviour of thiophene-appended cobalt, manganese and zinc phthalocyanine complexes[END_REF], the zinc hexadecafluorophthalocyanine and the non substituted zinc phthalocyanine [START_REF] Schöllhorn | Influence of peripheral electron-withdrawing substituents on the conductivity of zinc phthalocyanine in the presence of gases. Part 1: reducing gases[END_REF], we estimated the values of redox potentials of The electrochemical behavior of phthalocyanines 2 and 3 was investigated using cyclic voltammetry (CV) in DMF, at a concentration of 10 -3 mol.L -1 (Figs S4 and S5). Experimentally, 3 exhibits two reduction steps, at -0.78 V (E pcred1 , irreversible system) and -1.05 V (reversible system, E 1/2red2 = (E pcred2 +E pared2 )/2) vs SCE, which can be attributed to the successive reductions of the phthalocyanine ring, corresponding to the redox couples Pc 2-/Pc 3- and Pc 3-/Pc 4-, respectively. Taking into account the irreversibility of the first reduction peak, the E pcred1 value at -0.78 V turns out to be compatible with the value above estimated for the first reduction potential (-0.65 V). One oxidation peak attributed to the first oxidation of the phthalocyanine ring appears at +0.97 V (E pox1 ). Due to the lack of reversibility, it is not possible to define a redox potential difference, E redox , between the first oxidation and reduction potentials. Despite being determined on molecules in electrolytic solutions, electrochemical potentials can be used to evaluate the energy values of the frontier orbitals, HOMOs and LUMOs, known to be responsible for the electronic properties of the corresponding materials, in the solid state. Indeed, it was shown that, in the case of large aromatic molecules, as phthalocyanines, the redox potential difference E redox = E°o x1 -E°r ed1 does not depend on the polarity and the dielectric constant of the medium in which they are determined, and that there is a good agreement between E redox (in V) and the energy gap (in eV) determined in the solid state [START_REF] Bouvet | Determination of energy gap values in molecular crystals II. Intrinsic dark conductivity and electrochemical methods[END_REF]. However, determining an absolute energy level in the solid state raises the question of the reference. There is a consensus on calculating the HOMO and LUMO energy values from the onset potential defined as the potential at which the initial electron transfer from the HOMO, or to the LUMO, becomes visible on the cyclic voltammogram as a rise in anodic or cathodic current, respectively [START_REF] Ahmida | Measurements and prediction of electronic properties of discotic liquid crystalline triphenylenes and phthalocyanines[END_REF][START_REF] Cardona | Electrochemical considerations for determining absolute frontier orbital energy levels of conjugated polymers for solar cell applications[END_REF][START_REF] Brédas | Chain-length dependence of electronic and electrochemical properties of conjugated systems: polyacetylene, polyphenylene, polythiophene, and polypyrrole[END_REF][START_REF] Leonat | Cyclic voltammetry for energy levels estimation of organic materials[END_REF]. So, we calculated the energy of HOMOs and LUMOs of all the above mentioned phthalocyanines from the onset of their redox potentials determined in solution versus SCE or versus ferricinium/ferrocene (Fc + /Fc), as reference electrodes, depending on the reference actually used to determine the redox potentials:

(1a) or (1b) (2a) or (2b)

In the present work, the standard redox potential of Fc + /Fc was determined at +0.44 V vs SCE. All the data are compiled in Table 1 and reported in Fig. 1. The energy levels of a series of copper phthalocyanines determined directly versus the vacuum level, by Ultra-Violet Photoelectron Spectroscopy (UPS) and Inverse PhotoEmission Spectroscopy (IEPS), have been added [START_REF] Murdey | Frontier electronic structures in fluorinated copper phthalocyanine thin films studied using ultraviolet and inverse photoemission spectroscopies[END_REF]. For all the data reported in literature without showing voltammograms, the E 1/2 was used instead of the onset values.

Electrical and sensing properties

Films of 2 and 3 were obtained by solvent cast, from 85 µL of DMF solutions, at concentrations of 2x10 -3 and 3.3x10 -3 mol L -1 , respectively, deposited dropwise on interdigitated electrodes (IDE). The substrate was heated at 60 °C in a closed desiccator in order to fully evaporate the solvent and increase the homogeneity of the films. Electrical measurement in ambient atmosphere showed that these films were too resistive for suitable chemosensing studies, at least up to +10 V, with these IDEs. However, it was possible to build MSDI heterojunctions, by vacuum evaporation of lutetium bisphthalocyanine, LuPc 2 , 50 nm in thickness, on the previous films. For 1, the sublayer (50 nm in thickness) was also deposited by vacuum evaporation. The MSDI heterojunctions are called hereafter MSDI 1, MSDI 2 and MSDI 3, in reference to the nature of their sublayer. Their electronic absorption spectra in UV-visible are given in supplementary materials (Figs S1, S2 and S3).

For pure n-type sublayers, such as metalloperfluorophthalocyanines M(F 16 Pc), the response to ammonia is positive whereas it decreases for a LuPc 2 resistor. On the contrary, with pure p-type sublayers, e.g. pentacene, oligothiophene or a non substituted phthalocyanine [START_REF] Parra | Molecular semiconductor-doped insulator (MSDI) heterojunctions: an alternative transducer for gas chemosensing[END_REF][START_REF] Bouvet | Molecular semiconductor-doped insulator (MSDI) heterojunctions: Oligothiophene/bisphtalocyanine (LuPc 2 ) and perylene/bisphthalocyanine as new structures for gas sensing[END_REF], ammonia induces a decrease in current through the MSDI. An important point about MSDIs is that the only material available to interact with the outer atmosphere is the top layer. We demonstrated that the transport properties are dominated not only by the energy barrier at the interface between the sublayer and the LuPc 2 top layer, but also by the Schottky contact between the sublayer and the electrodes [START_REF] Bouvet | Revisiting the electronic properties of Molecular Semiconductor -Doped Insulator (MSDI) heterojunctions through impedance and chemosensing studies[END_REF]. These energy barriers are higher with M(F 16 Pc) than with p-type sublayers.

The I-V characteristics measured on all three MSDIs are symmetrical but not linear (Fig. 2), contrarily to those observed with a LuPc 2 resistor in the same potential range [START_REF] Parra | Molecular semiconductor-doped insulator (MSDI) heterojunctions: an alternative transducer for gas chemosensing[END_REF]. The deviation from the linearity is weak for MSDI 2, but greater for MSDIs 1 and 3. The current measured at 10 V under dry synthetic air varies by less than a factor of ten for all three devices, from 6.6 A for MSDI 3, to 16.3 A for MSDI 1 and to 53 A for the MSDI 2. Under NH 3 , the MSDI 3 showed a current decrease (Fig. 3), as expected for a p-type MSDI heterojunction prepared from a p-type sublayer. This reveals that compound 3 is capable of transporting positive majority charge carriers, even though their density remains very low. This was not obvious a priori due to the presence of twelve fluorine atoms on the phthalocyanine ring. This confirms that the four electron-donating alkoxy groups compensate, at least partially, the withdrawing effect of fluorine atoms, as mentioned in the electrochemistry section above. Quantitatively, the relative response, defined as (I-I 0 )/I 0 is of -1.6 % at 30 ppm NH 3 , under dry atmosphere.

The MSDI 2 exhibits also a negative response to NH 3 (-0.7 % at 30 ppm) under dry atmosphere, i.e. less than half that of the MSDI 3. 4). During the first exposure to 70% rh, the current of the MSDI 3 decreases by 6% in 10 min, whereas it diminishes by only 0.9% for the MSDI 2. More interestingly, for the MSDI 2, no matter the history of the sample, such as several exposition periods to humidity and ammonia, the increase of rh from 0 to 70 % induces a current decrease of ca. 2%. In the case of the MSDI 3, the relative response to humidity variations is highly dependent on the history of the device, and lies in the range -5% to -10%, for the same experiment in the range 10-70% of rh. We also studied the sensitivity of all the devices to NH 3 , at 90, 60 and 30 ppm, and under a variable relative humidity level, in the range 10-70 % rh. For the MSDI 2, the response to NH 3 is highly reversible in all the rh range, even though a drift of the response occurs at 70 % (Fig. 5). Despite the clearly visible response to NH 3 , the overall current variation caused by the rh variations, which is of -3 % between 10 % rh and 70 % rh, remains higher than the response to NH 3 . It is precisely the double of the response to 90 ppm NH 3 (-1.5 %). However, we have to keep in mind that ammonia sensors that are not affected by humidity variations in such a broad range are very rare [START_REF] Sizun | Microstructured electrodeposited polypyrrole-phthalocyanine hybrid material, from morphology to ammonia sensing[END_REF][START_REF] Gaudillat | Humidity insensitive conductometric sensors for ammonia sensing[END_REF]. As such, MSDI 2 exhibits an interesting response to NH 3 for all application in which the rh remains in the range 30-50 %. Despite a higher response to NH 3 , the behavior of MSDI 3 is worse in such a competitive experiment. Thus, the response to 90 ppm NH 3 is ca. 3%, whereas the current decreases by 20% from 10 % rh to 70 % rh.

As a result, the MSDI 2 reveals to be a better NH 3 sensor than the MSDI 3 when targeting real-world conditions, and can be used when the relative humidity is known or when it varies in a small range (typically in the range 30-50 % rh). The chemosensing properties of MSDIs 1 are different from those of MSDIs 2 and 3. In dry air, the current decreases under NH 3 , just as it does for the two other devices built with a p-type sublayer. But, during the first exposure to 70 % of rh, the current sharply decreases by 5% at first, down to a minimum value, then sharply increases to revert back to its original value (Fig. 6). Such transient behavior was observed at every new exposure to humidity that followed a long period in dry air. This means that the humidity is not only trapping or neutralizing majority charge carriers as expected for a p-type transducer, but we believe that this MSDI turns from p-type to n-type majority charge carriers. This is due to the very peculiar behavior of the LuPc 2 top layer, which is a p-type material in air but is also capable of transporting negative charge carriers [START_REF] Guillaud | Field-effect transistors based on intrinsic molecular semiconductors[END_REF]. As a result, when a LuPc 2 top layer is associated with 1 as a sublayer, the majority charge carriers responsible for the current turn from positive to negative. This is allowed by the value of the energy levels of 1. So, a small difference in the frontier orbitals energy between 1, 2 and 3 is responsible for strong effects in chemosensing. This fact is confirmed by exposure to NH 3 at different relative humidity values. During exposition, the measured current through MSDI 1, at 70 % and 50 % rh, increases under NH 3 whereas it decreases at 30 % and 10 % rh (Fig. 7). Quantitatively, the relative response to 30 ppm NH 3 is +3.7 % at 70 % rh and +1.5 % at 50 % rh, but turns to negative values at 30 % rh (-1.4%) and at 10 % rh (-1.6%). In air the MSDI 1 exhibits a p-type behavior, but water molecules trap majority (positive) charge carriers in the top layer when the humidity increases: the current is governed by minority (negative) mobile charges and the device behaves as a typical n-type MSDI, with an increase of the current under NH 3 . These results confirm the ambipolar behavior of the MSDI 1. Such a transient behavior had been already mentioned for MSDI 1, when exposed to 90 ppb of ozone, a strong oxidizing species, but without any reference to a possible ambipolar behavior [START_REF] Parra | Molecular semiconductor-doped insulator (MSDI) heterojunctions: an alternative transducer for gas chemosensing[END_REF]. In the very beginning of the exposure, the sensor displays an increase of current due to the doping of LuPc 2 , as any p-type conductometric device. However, the conductivity profile reaches a maximum in the subsequent seconds, then the current drops (Suppl. Info. of [START_REF] Parra | Molecular semiconductor-doped insulator (MSDI) heterojunctions: an alternative transducer for gas chemosensing[END_REF]).

In addition, we repeated the exposure to a given NH 3 concentration and a given rh value for twenty exposure/recovery cycles. The current variation at rh values of 70 % and 30 %, both at 30 ppm NH 3 are shown on Fig. 8 left. At 70 % rh, the sensor remains of n-type, even though the relative response decreases from -7.3 % to -4.9 % along the experiment. At 30 % rh, the relative response is more stable, at 1.62 ±0.05 %.

In another experiment, following a 15 min long exposition, the sensor recovers its baseline current after about 1 h, as demonstrated by exposing MSDI 1 to 30 ppm NH 3 at 30 % rh (Fig. 8 right). This experiment shows that the response after 15 min is about 7 times higher than the one observed after the 1 min long exposures. At a first glance, the response of MSDI 1 to NH 3 seems quite bad, since it is positive or negative depending on the relative humidity value. However, if the rh is stable, or known, e.g. by combining the MSDI device with a humidity sensor, it can be used as a NH 3 sensor. The association of two of the sensors studied here is even more interesting: for instance, if MSDIs 1 and 3 (or 1 and 2) were to be combined into one sensing system, a principal component analysis of the data would take advantage of the differences in their responses to give access to both the concentration of NH 3 and the rh value. So, the ambipolar behavior of the conductometric sensor enables a multimodal detection, as above mentioned in the introduction with polymer-based ambipolar transistors [START_REF] Wang | A highly sensitive diketopyrrolopyrrole-based ambipolar transistor for selective detection and discrimination of xylene isomers[END_REF].

Conclusion

The electrical properties of three substituted phthalocyanines bearing electron withdrawing substituents have been studied. The octafluorophthalocyanine 1, the octaester phthalocyanine 2 and the phthalocyanine bearing four alkoxy groups and twelve fluorine atoms 3 exhibit almost similar electrochemical properties. Used as sublayers in MSDI heterojunctions with LuPc 2 as a top layer, they show quite different chemosensing features.

MSDIs 2 and 3 exhibit a negative response to ammonia, whereas the response of the MSDI 1 depends on the relative humidity. We showed that this particular behavior results from the ambipolar character of 1.

Since the response of the device exposed to one gas can be positive or negative depending on the environmental conditions, such as a humidity variation in the present study, the ambipolar behavior of a conductometric chemical sensor can be considered as an unacceptable parameter to get a working and efficient sensor. However, it can be also considered as a feature that makes these ambipolar devices stand out from all other conductometric devices. This makes them promising elements for the design of new sensor arrays. Since the ambipolar behavior of a semiconductor material depends on the operating conditions, ambipolar materials, i.e. materials capable of exhibiting both p-type and n-type conductivities, are a priori good candidates to building in such sensing systems. PARI SMT 08 and CDEA programs is gratefully acknowledged. We would like to thank the European Union for fundings (FEDER and short term missions) through the COST action TD1105 EuNetAir. The research Ministry in Burkina Faso is thanked for supporting a mission in France (S. 0.).

F 8 3 ,Scheme 1

 831 Scheme 1 List of the phthalocyanine complexes studied in this work

2. 3 .

 3 Electrochemical measurements All electrochemical experiments were performed in DMF (dried by percolation on activated alumina) + Bu 4 NPF 6 0.1 M, with a PGSTAT302 N (Metrohm) potentiostat connected to a PC and the data collected were analyzed using the Nova® 1.11 Software. Cyclic voltammetry (CV) was carried out by means of a three-electrode configuration consisting of the Pt disk (1.6 mm in diameter, Bioanalytical Systems) as working electrode, a platinum wire as counter-electrode and an SCE electrode as reference separated from the solution by a glass chamber with a porous vycor tip filled up with a saturated solution of Bu 4 NPF 6 in DMF. Potentials were reported versus the saturated calomel electrode, SCE. The working Pt electrode was soaked for 10 min in KOH (2 M), polished with 0.1 µm alumina, etched for 10 min in concentrated sulfuric acid (2 M) and sonicated 10 min in water, and then in absolute ethyl alcohol.

The cyclic voltammogram of 2 (

 2 photoelectron spectroscopy (UPS) and inverse emission photoelectron spectroscopy(IEPS) showed that the energy levels of 1 are in between these of CuPc and Cu(F 16 Pc)[START_REF] Murdey | Frontier electronic structures in fluorinated copper phthalocyanine thin films studied using ultraviolet and inverse photoemission spectroscopies[END_REF]. So, the three studied phthalocyanines 1-3 have electrochemical properties close to each other. The three corresponding materials may exhibit an ambipolar behavior under the right conditions.

Figure 1 :

 1 Figure 1: Energy values of HOMO and LUMO calculated from redox potentials determined by cyclic voltammetry versus SCE (triangle), using equations 1 and 2, or directly determined by photoelectron spectroscopies UPS and IEPS, on the copper complexes (star).

Figure 2 .

 2 Figure 2. Typical I-V characteristics for the MSDIs 1 (solid line), 2 (dashed line), and 3 (dotted line) prepared with compounds 1, 2 and 3 as sublayer, respectively, and with LuPc 2 as a top layer. Inset: Scheme of a MSDI heterojunction; the arrows indicate the pathway of charges across the device.

Figure 3 :

 3 Figure 3: Response of a MSDI 3 to NH 3 (90, 60 and 30 ppm), in dry atmosphere, during exposure/recovery cycles (1 min/4 min); T = 21 °C.

Figure 4 :

 4 Figure 4: Response I/I 0 of MSDIs 1 (solid line), 2 (dashed line) and 3 (dotted line) to relative humidity in the range 10-70 % (bottom curve), during exposure periods of 10 min. I 0 is the current value of each device at the beginning of the experiment.

Figure 5 :

 5 Figure 5: Response of a MSDI 2 (solid line) to NH 3 (90, 60 and 30 ppm, dotted line), with relative humidity in the range 10-70 % (dashed line), during exposure/recovery cycles (1 min/4 min); T = 20 °C.

Figure 6 :

 6 Figure 6: Variation of the current (solid line) as a function of time for MSDI 1 during exposure to relative humidity (dotted line).

Figure 7 :

 7 Figure 7: Response of MSDI 1 (solid line) to NH 3 (90, 60 and 30 ppm, dotted line), with rh values of 50 % and 30 % (dashed line), during exposure/recovery cycles (1 min/4 min); T = 19 °C.

Figure 8 :

 8 Figure 8: (left) Response of a MSDI 1 (solid line) to 30 ppm NH 3 (dotted line) at a relative humidity value of 30 % (upper curve) and 70 % (lower curve), during twenty exposure/recovery cycles (1 min/4 min); (right) response to 30 ppm of NH 3 (exposure duration: 15 min) at 50 % rh; T = 20 °C.

  3.Since from ZnPc (-0.95) to Zn(F 16 Pc) (-0.43 V), E 1/2red is shifted by +0.52 V, due to the presence of 16 fluorine atoms, we can evaluate the effect of twelve F atoms at +0.39 V. In the same way, based on the reduction potential of ZnT

[START_REF] André | Electrical and magnetic properties of thin films and single crystals of bis(phthalocyaninato)lutetium[END_REF]

Pc (-0.99 V vs AgCl/Ag, i.e. ca. -1.03 V vs SCE) and the effect of twelve fluorine atoms, the reduction potential of 3 is expected to lie at ca. -0.65 V (-1.03 +0.38).

Table 1 :

 1 Redox potentials of a series of phthalocyanines determined by cyclic voltammetry versus SCE (peak potentials or E 1/2 if indicated), and energy values of HOMOs and LUMOs calculated from the onset of these potentials (or from peak potentials or E 1/2 if indicated), using equations 1 and 2, or directly determined by photoelectron spectroscopies, UPS and IEPS. Values given in ref.[START_REF] Ma | The first solution-processable ntype phthalocyaninato copper semiconductor: tuning the semiconducting nature via peripheral electron-withdrawing octyloxycarbonyl substituents[END_REF] using a slightly different formula.Determined from equations 1 or 2 in which E 1/2 or E peak were used instead of E onset .

	Compound [ref.]	Solvent Ered2 (V)	ERed1 (V)	EOx1 (V)	LUMO (eV) HOMO (eV)
	Zn(T4Pc) [40]	DMF		-1.03 a	0.43 a E1/2 -3.37 f	-4.83 f
	ZnPc [41]	DMF	-1.35 E1/2 -0.95 E1/2 0.59 E1/2 -3.45 f	-4.99 f
	[49]	DMF	-1.42 E1/2 -0.93 E1/2 0.64 E1/2
	Zn(T4F12Pc), 3 [36]	DMF	-1.05 E1/2 -0.78	0.97	-3.62 f	-5.37 f
	This work					-4.14	-5.19
	Co((COOC6H13)8Pc), 2	DMF	-1.18	-0.50	0.62 E1/2 b -3.90 f
	This work					-4,24
	Cu((COOC8H17) 8Pc) [43]	CH2Cl2	-0.81	-0.49	1.14	-3.95 c	-5.58 c
	15C5 d [43]	CH2Cl2	-0.85	-0.59	1.05	-3.85 c	-5.49 c
	Zn(F16Pc) [41]	DMF	-0.64 E1/2 -0.43 E1/2 1.04 e	-3.97 f	-5.44 f
	[49]		-0.9 E1/2	-0.6 E1/2		-3.47
	CuPc [29]					-3.16 g	-5.20 g
	Cu(F8Pc), 1 [29]					-3.91 g	-6.06 g
	Cu(F16Pc) [29]					-4.46 g	-6.39 g
	d Acronym used for Cu((COOR) 6 (15C5)Pc). e Estimated in ref. [41] from an irreversible peak.

a Recalculated from data determined vs AgCl/Ag, using (E 0 AgCl/Ag ) = -0.04V vs SCE. b This oxidation corresponds to the redox couple Co 3+ /Co 2+ . c f g Measured experimentally by photoelectron spectroscopy (UPS and IEPS) [29].

Acknowledgements

The authors acknowledge the Agence Nationale de la Recherche for funding through the ANR projects CAP-BTX ANR-BLAN-2010-917-02 and OUTSMART ANR-2015-CE39-0004-03 and the MENESR for a PhD grant (A. W.). Financial support from the European Union and the Conseil Régional de Bourgogne through the FABER and the