K22 processor

Committer:
bosko001
Date:
Sun Mar 21 18:20:15 2021 +0100
Revision:
7:4aa3dac73b66
novi pocetak

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bosko001 7:4aa3dac73b66 1 #ifndef ZEROCROSSING_H
bosko001 7:4aa3dac73b66 2 #define ZEROCROSSING_H
bosko001 7:4aa3dac73b66 3
bosko001 7:4aa3dac73b66 4 #include "mbed.h"
bosko001 7:4aa3dac73b66 5
bosko001 7:4aa3dac73b66 6 #include "IOdata.h"
bosko001 7:4aa3dac73b66 7
bosko001 7:4aa3dac73b66 8 /************************ port clase ***************************/
bosko001 7:4aa3dac73b66 9 struct S_bitPortIn
bosko001 7:4aa3dac73b66 10 {
bosko001 7:4aa3dac73b66 11 union
bosko001 7:4aa3dac73b66 12 {
bosko001 7:4aa3dac73b66 13 struct
bosko001 7:4aa3dac73b66 14 {
bosko001 7:4aa3dac73b66 15 char d0: 1; char d1: 1; char d2: 1; char d3: 1; char d4: 1; char d5: 1; char d6: 1; char d7: 1;
bosko001 7:4aa3dac73b66 16 };
bosko001 7:4aa3dac73b66 17 char port;
bosko001 7:4aa3dac73b66 18 };
bosko001 7:4aa3dac73b66 19 public:
bosko001 7:4aa3dac73b66 20 void portIn_refresh( void );
bosko001 7:4aa3dac73b66 21 char get_port( void ) { portIn_refresh( ); return port;}
bosko001 7:4aa3dac73b66 22 };
bosko001 7:4aa3dac73b66 23 struct S_bitPortOut
bosko001 7:4aa3dac73b66 24 {
bosko001 7:4aa3dac73b66 25 union
bosko001 7:4aa3dac73b66 26 {
bosko001 7:4aa3dac73b66 27 struct
bosko001 7:4aa3dac73b66 28 {
bosko001 7:4aa3dac73b66 29 char d0: 1; char d1: 1; char d2: 1; char d3: 1; char d4: 1; char d5: 1; char d6: 1; char d7: 1;
bosko001 7:4aa3dac73b66 30 };
bosko001 7:4aa3dac73b66 31 char port;
bosko001 7:4aa3dac73b66 32 };
bosko001 7:4aa3dac73b66 33 public:
bosko001 7:4aa3dac73b66 34 void set_port( char port ) { this->port = port; portOut_refresh(); }
bosko001 7:4aa3dac73b66 35 void portOut_refresh( );
bosko001 7:4aa3dac73b66 36 };
bosko001 7:4aa3dac73b66 37
bosko001 7:4aa3dac73b66 38 class C_zeroCrossing
bosko001 7:4aa3dac73b66 39 {
bosko001 7:4aa3dac73b66 40 Timer t; // timer meri vreme trajanja zero crossing impulsa
bosko001 7:4aa3dac73b66 41
bosko001 7:4aa3dac73b66 42 int zcCounter = 0; // brojac zero crossing impulsa
bosko001 7:4aa3dac73b66 43 void inc_zcCounter( void ) { zcCounter ++; }
bosko001 7:4aa3dac73b66 44
bosko001 7:4aa3dac73b66 45
bosko001 7:4aa3dac73b66 46 unsigned int frc; // free running counter za merenje vremena trajanja impulsazero crossinga
bosko001 7:4aa3dac73b66 47 unsigned int timeON, timeOFF; // vreme trajanja nivoa ON i OFF zero crossinga u mikrosekundama
bosko001 7:4aa3dac73b66 48 Timeout toutON, toutOFF;
bosko001 7:4aa3dac73b66 49 void toutONfun( void); // obavezna funkcija uzlazne ivice, meri trajanje 0 zero crossinga
bosko001 7:4aa3dac73b66 50 void toutOFFfun(void); // obavezna funkcija silazne ivice, meri trajanje 1 zero crossinga
bosko001 7:4aa3dac73b66 51
bosko001 7:4aa3dac73b66 52 void (*p_ontime_toutONfun)(void) = nullptr ; // pointer na korisnicku funkciju uzlazne ivice
bosko001 7:4aa3dac73b66 53 void ontime_toutONfun(void); // korisnicka funkcija uzlazne ivice
bosko001 7:4aa3dac73b66 54 void (*p_ontime_toutOFFfun)(void) = nullptr ; // pointer na korisnicku funkciju silazne ivice
bosko001 7:4aa3dac73b66 55 void ontime_toutOFFfun(void) ; // korisnicka funkcija silazne ivice
bosko001 7:4aa3dac73b66 56
bosko001 7:4aa3dac73b66 57
bosko001 7:4aa3dac73b66 58 void (*p_postpone_toutONfun)(void); // odlozena korisnicka funkcija od uzlazne ivice
bosko001 7:4aa3dac73b66 59 void postpone_toutONfun(void); // odlozena korisnicka funkcija od uzlazne ivice
bosko001 7:4aa3dac73b66 60 int postpone_toutONtime = 0; // odlaganje u mikrosekundama
bosko001 7:4aa3dac73b66 61 void postpone_toutON( unsigned int tim );// { toutON.attach_us( [this](){postpone_toutONfun();}, postpone_toutONtime ); }
bosko001 7:4aa3dac73b66 62
bosko001 7:4aa3dac73b66 63 void postpone_toutOFFfun(void); // odlozena korisnicka funkcija silazne ivice
bosko001 7:4aa3dac73b66 64 void (*p_postpone_toutOFFfun)(void); // odlozena korisnicka funkcija silazne ivice
bosko001 7:4aa3dac73b66 65 int postpone_toutOFFtime = 0; // vreme odlaganja u mikrosekundama
bosko001 7:4aa3dac73b66 66 void postpone_toutOFF( unsigned int tim );// { toutOFF.attach_us( [this](){postpone_toutOFFfun();}, postpone_toutOFFtime );}
bosko001 7:4aa3dac73b66 67
bosko001 7:4aa3dac73b66 68 S_bitPortOut s_portout;
bosko001 7:4aa3dac73b66 69 S_bitPortIn s_portinMin, s_portinMax;
bosko001 7:4aa3dac73b66 70
bosko001 7:4aa3dac73b66 71 public:
bosko001 7:4aa3dac73b66 72
bosko001 7:4aa3dac73b66 73
bosko001 7:4aa3dac73b66 74 C_data *pc_data;
bosko001 7:4aa3dac73b66 75
bosko001 7:4aa3dac73b66 76
bosko001 7:4aa3dac73b66 77 C_zeroCrossing( C_data *);
bosko001 7:4aa3dac73b66 78
bosko001 7:4aa3dac73b66 79 int get_zcCounter( void ) { int temp = zcCounter; zcCounter = 0; return temp;}
bosko001 7:4aa3dac73b66 80
bosko001 7:4aa3dac73b66 81 int get_zcTimeON( void ) {return timeON;}
bosko001 7:4aa3dac73b66 82 int get_zcTimeOFF( void ) {return timeOFF;}
bosko001 7:4aa3dac73b66 83
bosko001 7:4aa3dac73b66 84 void set_ontimeONfun( void (*pf)(void)) {p_ontime_toutONfun = pf;}
bosko001 7:4aa3dac73b66 85 void set_ontimeOFFfun( void (*pf)(void)) {p_ontime_toutOFFfun = pf;}
bosko001 7:4aa3dac73b66 86
bosko001 7:4aa3dac73b66 87 void set_postponeONfun( void (*pf)(void)) {p_postpone_toutONfun = pf;}
bosko001 7:4aa3dac73b66 88 void set_postponeOFFfun( void (*pf)(void)) {p_postpone_toutOFFfun = pf;}
bosko001 7:4aa3dac73b66 89
bosko001 7:4aa3dac73b66 90 void set_portOut( char data ) { s_portout.set_port(data);}
bosko001 7:4aa3dac73b66 91 char get_portInMin( void ) { return s_portinMin.get_port();}
bosko001 7:4aa3dac73b66 92 char get_portInMax( void ) { return s_portinMax.get_port();}
bosko001 7:4aa3dac73b66 93 };
bosko001 7:4aa3dac73b66 94
bosko001 7:4aa3dac73b66 95
bosko001 7:4aa3dac73b66 96
bosko001 7:4aa3dac73b66 97 #endif