Rev 1044 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1044 | Rev 1045 | ||
|---|---|---|---|
| Line 2... | Line 2... | ||
| 2 | #include <avr/interrupt.h> |
2 | #include <avr/interrupt.h> |
| 3 | #include <stdio.h> |
3 | #include <stdio.h> |
| 4 | #include <string.h> |
4 | #include <string.h> |
| 5 | #include <config.h> // All configuration parameters |
5 | #include <config.h> // All configuration parameters |
| 6 | #include <bios.h> // BIOS interface declarations, including CAN structure and ID defines. |
6 | #include <bios.h> // BIOS interface declarations, including CAN structure and ID defines. |
| 7 | #include <drivers/uart/serial.h> |
- | |
| 8 | #include <drivers/timer/timer.h> |
7 | #include <drivers/timer/timer.h> |
| 9 | #include <drivers/adc/adc.h> |
8 | #include <drivers/adc/adc.h> |
| 10 | 9 | ||
| 11 | #define APP_TYPE 0xf001 |
10 | #define APP_TYPE 0xf001 |
| 12 | #define APP_VERSION 0x0002 |
11 | #define APP_VERSION 0x0002 |
| Line 44... | Line 43... | ||
| 44 | { |
43 | { |
| 45 | // Enable interrupts as early as possible |
44 | // Enable interrupts as early as possible |
| 46 | sei(); |
45 | sei(); |
| 47 | 46 | ||
| 48 | Timer_Init(); |
47 | Timer_Init(); |
| 49 | Serial_Init(); |
- | |
| 50 | ADC_Init(); |
48 | ADC_Init(); |
| 51 | 49 | ||
| 52 | unsigned long time; |
50 | unsigned long time; |
| 53 | 51 | ||
| 54 | Can_Message_t txMsg; |
52 | Can_Message_t txMsg; |
| Line 82... | Line 80... | ||
| 82 | PORTC |= (1<<PC2); //set EXP_N to pullup |
80 | PORTC |= (1<<PC2); //set EXP_N to pullup |
| 83 | 81 | ||
| 84 | while (1) { |
82 | while (1) { |
| 85 | if (Timer_Expired(1)) { |
83 | if (Timer_Expired(1)) { |
| 86 | if (!(PINC & (1<<PC2))) { |
84 | if (!(PINC & (1<<PC2))) { |
| - | 85 | if (DUTconnectcnt < 10) { |
|
| 87 | DUTconnectcnt++; |
86 | DUTconnectcnt++; |
| - | 87 | } |
|
| 88 | } else { |
88 | } else { |
| 89 | DUTconnected = 0; |
89 | DUTconnected = 0; |
| - | 90 | //DUTconnectcnt --; |
|
| 90 | DUTconnectcnt = 0; |
91 | DUTconnectcnt = 0; |
| 91 | } |
92 | } |
| 92 | if (DUTconnectcnt |
93 | if (DUTconnectcnt == 10) { |
| 93 | DUTconnected = 1; |
94 | DUTconnected = 1; |
| - | 95 | } //else if (DUTconnectcnt == 0) { |
|
| - | 96 | //DUTconnected = 0; |
|
| 94 |
|
97 | //} |
| 95 | 98 | ||
| 96 | reg5Vfeedback = ADC_Get(ADREG5VFEEDBACK); |
99 | reg5Vfeedback = ADC_Get(ADREG5VFEEDBACK); |
| 97 | reg5Vfeedback = (reg5Vfeedback & 0x03ff) * ADC_FACTOR; //get voltage in mV (typical 5000mV) |
100 | reg5Vfeedback = (reg5Vfeedback & 0x03ff) * ADC_FACTOR; //get voltage in mV (typical 5000mV) |
| 98 | currentfeedback = ADC_Get(ADCURRENTFEEDBACK); |
101 | currentfeedback = ADC_Get(ADCURRENTFEEDBACK); |
| 99 | currentfeedback = (currentfeedback>>1); //get current in mA ( cur [A] = (ad*Vcc /1024)/R, R=10 ) (typical 20mA) |
102 | currentfeedback = (currentfeedback>>1); //get current in mA ( cur [A] = (ad*Vcc /1024)/R, R=10 ) (typical 20mA) |
| 100 | 103 | ||
| 101 |
|
104 | if (reg5Vfeedback > 6000 || currentfeedback > 40) { |
| 102 | PORTD &= ~(1<<PD7); //turn off output |
105 | PORTD &= ~(1<<PD7); //turn off output |
| 103 |
|
106 | } |
| 104 | } |
107 | } |
| 105 | if (Timer_Expired(0)) { |
108 | if (Timer_Expired(0)) { |
| 106 | /*reg5Vfeedback = ADC_Get(ADREG5VFEEDBACK); |
109 | /*reg5Vfeedback = ADC_Get(ADREG5VFEEDBACK); |
| 107 | reg5Vfeedback = (reg5Vfeedback & 0x03ff) * ADC_FACTOR; //get voltage in mV (typical 5000mV) |
110 | reg5Vfeedback = (reg5Vfeedback & 0x03ff) * ADC_FACTOR; //get voltage in mV (typical 5000mV) |
| 108 | currentfeedback = ADC_Get(ADCURRENTFEEDBACK); |
111 | currentfeedback = ADC_Get(ADCURRENTFEEDBACK); |
| 109 | currentfeedback = (currentfeedback>>1); //get current in mA ( cur [A] = (ad*Vcc /1024)/R, R=10 ) (typical 20mA) |
112 | currentfeedback = (currentfeedback>>1); //get current in mA ( cur [A] = (ad*Vcc /1024)/R, R=10 ) (typical 20mA) |
| 110 | */ |
113 | */ |
| 111 | PORTB |
114 | //PORTB ^= (1<<PB7); |
| 112 | PORTD |
115 | //PORTD ^= (1<<PD7); //toggle output |
| 113 | 116 | ||
| - | 117 | /*if (DUTconnected) { |
|
| - | 118 | PORTD |= (1<<PD7); //toggle output |
|
| - | 119 | }*/ |
|
| 114 | 120 | ||
| 115 | txMsg.Id = 0; |
121 | txMsg.Id = 0; |
| 116 | txMsg.DataLength = |
122 | txMsg.DataLength = 6; |
| 117 | txMsg.RemoteFlag = 0; |
123 | txMsg.RemoteFlag = 0; |
| 118 | txMsg.ExtendedFlag = 1; |
124 | txMsg.ExtendedFlag = 1; |
| 119 | txMsg.Data.bytes[0] = (reg5Vfeedback>>8)&0xff; |
125 | txMsg.Data.bytes[0] = (reg5Vfeedback>>8)&0xff; |
| 120 | txMsg.Data.bytes[1] = reg5Vfeedback&0xff; |
126 | txMsg.Data.bytes[1] = reg5Vfeedback&0xff; |
| 121 | txMsg.Data.bytes[2] = (currentfeedback>>8)&0xff; |
127 | txMsg.Data.bytes[2] = (currentfeedback>>8)&0xff; |
| 122 | txMsg.Data.bytes[3] = currentfeedback&0xff; |
128 | txMsg.Data.bytes[3] = currentfeedback&0xff; |
| 123 | 129 | ||
| 124 | txMsg.Data.bytes[4] = DUTconnected; |
130 | txMsg.Data.bytes[4] = DUTconnected; |
| - | 131 | txMsg.Data.bytes[5] = ((PORTD & (1<<PD7))>>PD7); |
|
| 125 | 132 | ||
| 126 | // Send CAN_NMT_APP_START |
133 | // Send CAN_NMT_APP_START |
| 127 | BIOS_CanSend(&txMsg); |
134 | BIOS_CanSend(&txMsg); |
| 128 | } |
135 | } |
| 129 | 136 | ||