IO plocana FRDM K64

Committer:
bosko001
Date:
Fri Apr 30 00:06:39 2021 +0200
Revision:
15:3429cdc6e5f4
Parent:
7:4aa3dac73b66
ugradjen privremeni timeout 4s i telegram reseta ploce

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bosko001 7:4aa3dac73b66 1 #ifndef IOZCCONTROL_H
bosko001 7:4aa3dac73b66 2 #define IOZCCONTROL_H
bosko001 7:4aa3dac73b66 3
bosko001 7:4aa3dac73b66 4 #include "ZeroCrossing.h"
bosko001 7:4aa3dac73b66 5 #include "IOspiprotokol.h"
bosko001 7:4aa3dac73b66 6
bosko001 7:4aa3dac73b66 7
bosko001 7:4aa3dac73b66 8 #define LOWER_THEN( val, max) (val < max ? true : false)
bosko001 7:4aa3dac73b66 9 #define HIGHER_THEN( val, min) (val > min ? true : false)
bosko001 7:4aa3dac73b66 10 #define IN_RANGE( val, min, max) (LOWER_THEN( val, max ) && HIGHER_THEN(val, min)) ? true : false
bosko001 7:4aa3dac73b66 11
bosko001 15:3429cdc6e5f4 12 #define CHECK_PERIOD 1000000 // 1S = 1.000.000 uS
bosko001 7:4aa3dac73b66 13 #define LOW_FREQ 40 // Hz
bosko001 7:4aa3dac73b66 14 #define HIGH_FREQ 70
bosko001 7:4aa3dac73b66 15
bosko001 7:4aa3dac73b66 16
bosko001 7:4aa3dac73b66 17 #define NO_IMP_MAX (HIGH_FREQ * 2 * CHECK_PERIOD / 1000000)
bosko001 7:4aa3dac73b66 18 #define NO_IMP_MIN ( LOW_FREQ * 2 * CHECK_PERIOD / 1000000)
bosko001 7:4aa3dac73b66 19
bosko001 7:4aa3dac73b66 20
bosko001 7:4aa3dac73b66 21 // extern void ledON(void);
bosko001 7:4aa3dac73b66 22 // extern void ledOFF(void);
bosko001 7:4aa3dac73b66 23
bosko001 7:4aa3dac73b66 24 /** Class C_zcControl kontrolise zero crossing sinhronizaciju
bosko001 7:4aa3dac73b66 25 * komande i citanja indikacija.
bosko001 7:4aa3dac73b66 26 */
bosko001 7:4aa3dac73b66 27
bosko001 7:4aa3dac73b66 28 class C_zcControl
bosko001 7:4aa3dac73b66 29 {
bosko001 7:4aa3dac73b66 30
bosko001 7:4aa3dac73b66 31 /**Ticker t je tajmer periode 1 sec koji prebojava
bosko001 7:4aa3dac73b66 32 * broj impulsa zero crossinga u periodi
bosko001 7:4aa3dac73b66 33 */
bosko001 7:4aa3dac73b66 34 Ticker t;
bosko001 7:4aa3dac73b66 35 C_zeroCrossing *p_zeroCrossing;
bosko001 7:4aa3dac73b66 36 C_spiProtokol *p_spiProtokol;
bosko001 7:4aa3dac73b66 37 bool zc;
bosko001 7:4aa3dac73b66 38 public:
bosko001 7:4aa3dac73b66 39
bosko001 7:4aa3dac73b66 40 C_zcControl( C_zeroCrossing *p_zc, C_spiProtokol *p_sp)
bosko001 7:4aa3dac73b66 41 {
bosko001 7:4aa3dac73b66 42 p_zeroCrossing = p_zc;
bosko001 7:4aa3dac73b66 43 p_spiProtokol = p_sp;
bosko001 7:4aa3dac73b66 44 t.attach_us([this](){check_zc();}, CHECK_PERIOD);
bosko001 7:4aa3dac73b66 45 }
bosko001 7:4aa3dac73b66 46
bosko001 7:4aa3dac73b66 47 void check_zc( void )
bosko001 7:4aa3dac73b66 48 {
bosko001 7:4aa3dac73b66 49 int zcCount = p_zeroCrossing->get_zcCounter();
bosko001 7:4aa3dac73b66 50 zc = IN_RANGE(zcCount, NO_IMP_MIN, NO_IMP_MAX);
bosko001 7:4aa3dac73b66 51 p_spiProtokol->set_zeroCrossing( zc); // zc == true => zero crrossing je dobar!
bosko001 7:4aa3dac73b66 52
bosko001 7:4aa3dac73b66 53 // if( zc == true ) ledON();
bosko001 7:4aa3dac73b66 54 // else ledOFF();
bosko001 7:4aa3dac73b66 55 }
bosko001 7:4aa3dac73b66 56 bool get_zerocrossing( void ) { return zc; }
bosko001 7:4aa3dac73b66 57
bosko001 7:4aa3dac73b66 58 };
bosko001 7:4aa3dac73b66 59
bosko001 7:4aa3dac73b66 60
bosko001 7:4aa3dac73b66 61 #endif