|
Revision 122, 2.5 KB
(checked in by icarus75, 2 years ago)
|
|
uc: add support for US split-phase supplies
|
-
Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | # define PULSE 0 |
|---|
| 24 | # define POWER 1 |
|---|
| 25 | |
|---|
| 26 | # define WATT 1000000000 |
|---|
| 27 | # define SECOND 624 // 625Hz - 1 |
|---|
| 28 | |
|---|
| 29 | #ifndef SENSOR0 |
|---|
| 30 | #error "SENSOR0 not defined" |
|---|
| 31 | #endif |
|---|
| 32 | |
|---|
| 33 | #ifndef SENSOR1 |
|---|
| 34 | #error "SENSOR1 not defined" |
|---|
| 35 | #endif |
|---|
| 36 | |
|---|
| 37 | #ifndef SENSOR2 |
|---|
| 38 | #error "SENSOR2 not defined" |
|---|
| 39 | #endif |
|---|
| 40 | |
|---|
| 41 | #ifndef SENSOR3 |
|---|
| 42 | #error "SENSOR3 not defined" |
|---|
| 43 | #endif |
|---|
| 44 | |
|---|
| 45 | #ifndef PHASE |
|---|
| 46 | #error "PHASE not defined" |
|---|
| 47 | #endif |
|---|
| 48 | |
|---|
| 49 | #ifndef METERCONST |
|---|
| 50 | #error "METERCONST not defined" |
|---|
| 51 | #endif |
|---|
| 52 | |
|---|
| 53 | #define START 0 |
|---|
| 54 | #define END3 0xffffffff |
|---|
| 55 | #define END2 0xeeeeeeee |
|---|
| 56 | #define END1 0xdddddddd |
|---|
| 57 | #define END0 0xcccccccc |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | #define MacU16X16to32(uint_32Acc, uint_16In1, uint_16In2) \ |
|---|
| 63 | asm volatile ( \ |
|---|
| 64 | "clr r2 \n\t" \ |
|---|
| 65 | "mul %B2, %B1 \n\t" \ |
|---|
| 66 | "movw r4, r0 \n\t" \ |
|---|
| 67 | "mul %A2, %A1 \n\t" \ |
|---|
| 68 | "add %A0, r0 \n\t" \ |
|---|
| 69 | "adc %B0, r1 \n\t" \ |
|---|
| 70 | "adc %C0, r4 \n\t" \ |
|---|
| 71 | "adc %D0, r5 \n\t" \ |
|---|
| 72 | "mul %B2, %A1 \n\t" \ |
|---|
| 73 | "add %B0, r0 \n\t" \ |
|---|
| 74 | "adc %C0, r1 \n\t" \ |
|---|
| 75 | "adc %D0, r2 \n\t" \ |
|---|
| 76 | "mul %A2, %B1 \n\t" \ |
|---|
| 77 | "add %B0, r0 \n\t" \ |
|---|
| 78 | "adc %C0, r1 \n\t" \ |
|---|
| 79 | "adc %D0, r2 \n\t" \ |
|---|
| 80 | "clr r1 \n\t" \ |
|---|
| 81 | : \ |
|---|
| 82 | "+r" (uint_32Acc) \ |
|---|
| 83 | : \ |
|---|
| 84 | "a" (uint_16In1), \ |
|---|
| 85 | "a" (uint_16In2) \ |
|---|
| 86 | : \ |
|---|
| 87 | "r2", "r4", "r5" \ |
|---|
| 88 | ) |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | struct state { |
|---|
| 92 | boolean pulse; |
|---|
| 93 | boolean toggle; |
|---|
| 94 | uint32_t nano; |
|---|
| 95 | uint16_t adc; |
|---|
| 96 | |
|---|
| 97 | boolean power; |
|---|
| 98 | uint32_t nano_start; |
|---|
| 99 | uint32_t nano_end; |
|---|
| 100 | uint8_t pulse_count; |
|---|
| 101 | uint8_t pulse_count_final; |
|---|
| 102 | }; |
|---|
| 103 | |
|---|
| 104 | struct sensor { |
|---|
| 105 | char id[33]; |
|---|
| 106 | uint32_t value; |
|---|
| 107 | }; |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | void WDT_off(void); |
|---|
| 111 | void WDT_on(void); |
|---|
| 112 | void send(uint8_t msg_type, const struct sensor *measurement, const struct state *aux); |
|---|