-
Notifications
You must be signed in to change notification settings - Fork 211
/
Copy pathrst_vpp.cpp
52 lines (48 loc) · 1.17 KB
/
rst_vpp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "rst_vpp.h"
/*
* Command: setup charge pump
* Enable Timer2 Fast PWM on pin 3, 11
* NB: pins must be set to OUTPUT for PWM to appear on the pins
* Fast PWM : WGM21 WGM20
* Clear OC2A on Compare Match (COM2A1)
* Set OC2B on Compare Match (COM2B1 + COM2B0)
* Frequency : 16MHz/1/256 = 62.5kHz (CS20)
* Pin 11 : (127+1)/256 = 50% duty cycle (OCR2A)
* Pin 3 : (127+1)/256 = 50% duty cycle (OCR2B)
*/
void RST_VPP::setup(void) {
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(COM2B0) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(CS20);
OCR2A = 127;
OCR2B = 127;
pinMode(RST_PIN, OUTPUT);
setVoltage(0);
}
// set RST/VPP pin to 12V, 5V or (default) 0V
void RST_VPP::setVoltage(uint8_t voltage) {
delay(1);
switch(voltage) {
case 12:
digitalWrite(RST_PIN, HIGH);
on();
break;
case 5:
off();
digitalWrite(RST_PIN, HIGH);
break;
default:
off();
digitalWrite(RST_PIN, LOW);
}
delay(1);
}
// enable charge pump
void RST_VPP::on(void) {
pinMode(PUMP_A_PIN, OUTPUT);
pinMode(PUMP_B_PIN, OUTPUT);
}
// disable charge pump
void RST_VPP::off(void) {
pinMode(PUMP_A_PIN, INPUT);
pinMode(PUMP_B_PIN, INPUT);
}