~gabe/flashlight-firmware/anduril2

« back to all changes in this revision

Viewing changes to ToyKeeper/battcheck/offtime-cap.c

  • Committer: Selene Scriven
  • Date: 2015-09-11 00:57:48 UTC
  • mfrom: (153.1.5 tiny25)
  • Revision ID: ubuntu@toykeeper.net-20150911005748-jxfkdi9ggulmaf1y
Merged attiny25 support for blf-a6, battcheck, and offtime-cap.
Added some attiny25-related scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 * STARS (not used)
35
35
 *
36
36
 */
 
37
// set some hardware-specific values...
 
38
// (while configuring this firmware, skip this section)
 
39
#if (ATTINY == 13)
37
40
#define F_CPU 4800000UL
 
41
#define EEPLEN 64
 
42
#define DELAY_TWEAK 950
 
43
#elif (ATTINY == 25)
 
44
#define F_CPU 8000000UL
 
45
#define EEPLEN 128
 
46
#define DELAY_TWEAK 2000
 
47
#else
 
48
Hey, you need to define ATTINY.
 
49
#endif
 
50
 
38
51
 
39
52
/*
40
53
 * =========================================================================
55
68
static void _delay_ms(uint16_t n)
56
69
{
57
70
    while(n-- > 0)
58
 
        _delay_loop_2(950);
 
71
        _delay_loop_2(DELAY_TWEAK);
59
72
}
60
73
#else
61
74
#include <util/delay.h>
82
95
#define PWM_LVL     OCR0B   // OCR0B is the output compare register for PB1
83
96
 
84
97
inline void ADC_on() {
 
98
#if (ATTINY == 13)
85
99
    ADMUX  = (1 << REFS0) | (1 << ADLAR) | ADC_CHANNEL; // 1.1v reference, left-adjust, ADC1/PB2
 
100
#elif (ATTINY == 25)
 
101
    ADMUX  = (1 << REFS1) | (1 << ADLAR) | ADC_CHANNEL; // 1.1v reference, left-adjust, ADC1/PB2
 
102
#endif
86
103
    DIDR0 |= (1 << ADC_DIDR);                           // disable digital input on ADC pin to reduce power consumption
87
104
    ADCSRA = (1 << ADEN ) | (1 << ADSC ) | ADC_PRSCL;   // enable, start, prescale
88
105
}
94
111
uint8_t get_reading() {
95
112
    // Start up ADC for capacitor pin
96
113
    DIDR0 |= (1 << CAP_DIDR);                           // disable digital input on ADC pin to reduce power consumption
 
114
#if (ATTINY == 13)
97
115
    ADMUX  = (1 << REFS0) | (1 << ADLAR) | CAP_CHANNEL; // 1.1v reference, left-adjust, ADC3/PB3
 
116
#elif (ATTINY == 25)
 
117
    ADMUX  = (1 << REFS1) | (1 << ADLAR) | CAP_CHANNEL; // 1.1v reference, left-adjust, ADC3/PB3
 
118
#endif
98
119
    ADCSRA = (1 << ADEN ) | (1 << ADSC ) | ADC_PRSCL;   // enable, start, prescale
99
120
    // Wait for completion
100
121
    while (ADCSRA & (1 << ADSC));
125
146
int main(void)
126
147
{
127
148
    uint16_t value;
128
 
    uint8_t i;
129
149
 
130
150
    // Set PWM pin to output
131
151
    DDRB = (1 << PWM_PIN);
140
160
 
141
161
    // get an average of several readings
142
162
    /*
 
163
    uint8_t i;
143
164
    value = 0;
144
165
    for (i=0; i<8; i++) {
145
166
        value += get_reading();