Statistics
| Revision:

root / trunk / tp_info6 / Emb_App / radiocommande.c @ 1

History | View | Annotate | Download (2 KB)

1
/***********************************************************************/
2
/*                                                                     */
3
/*  FILE        :radiocommande.c                                       */
4
/*  DATE        :Mon, Feb 13, 2006                                     */
5
/*  DESCRIPTION : measure 6 channels on the receiver                   */
6
/*  CPU GROUP   :62P                                                   */
7
/*                                                                     */
8
/*  This file is generated by Renesas Project Generator (Ver.4.5).     */
9
/*                                                                     */
10
/***********************************************************************/
11
#ifdef M32C87
12
        #include "sfr32c87.h"
13
#endif
14

    
15
#ifdef M32C83
16
        #include "sfr32c83.h"
17
#endif
18

    
19
#include <itron.h> 
20
#include <kernel.h> 
21
#include "kernel_id.h" 
22

    
23

    
24
//function's prototypes declaration
25

    
26

    
27

    
28
int canal[7];
29
int canal_ok;
30

    
31

    
32
void capture_init(void)
33
{
34
     prc2 = 1;                //unprotect writing in pd9 register
35
     pd9_0 = 0;
36
         prc2=0;
37
         ps3_3=0;
38
         psl3_3=0;
39
     tb0mr = 0x4A;            //timer B0 in duration measurement mode with f8
40
     tb0ic = 0x07;            //enable timer B0 interrupt at level x
41
     tb0s = 1;                //start timer B0
42
         
43
         canal_ok=0;
44
}
45

    
46
void mesure(void)
47
{
48
     static char k=-1;
49
         static int flag=0;
50
         unsigned int tpulse;
51
         int val; 
52
        
53
        tpulse=tb0>>1; // Pulse time 
54

    
55
        if (tpulse<400) { // Too short pulse
56
                k=-1;
57
                canal_ok=0;
58
                return;
59
        }        
60
        
61
        if (tpulse>10000) // Synchro pulse
62
        {
63
                k=0; // Return to canal 0
64
                return;
65
        }
66
        
67
        if (k==(char) -1) // Not synchronised
68
                return; // Nothing to do
69

    
70
        if (!(k & 0x01))  // 500us High pulse
71
                if (tpulse>600) {
72
                        k=-1; // Invalidate mesure and wait a new synchro
73
                        canal_ok=0;
74
                        return;
75
                }
76

    
77
        if (k & 0x01) // Pulse timing
78
                canal[k>>1]=tpulse-1360; // 1360 neutral zone
79

    
80
        k++;
81
        if (k>11) {// Last canal
82
                k=-1;
83
                canal_ok=1;
84
        }
85
}