voltage scaling
This commit is contained in:
parent
93c76775ca
commit
1ec0f63696
1 changed files with 31 additions and 3 deletions
34
main.c
34
main.c
|
@ -35,6 +35,21 @@ volatile uint8_t drawRequested = 1;
|
||||||
#define WIDTH LCD_HORIZONTAL_MAX
|
#define WIDTH LCD_HORIZONTAL_MAX
|
||||||
#define PIXELS_PER_DIV 20
|
#define PIXELS_PER_DIV 20
|
||||||
|
|
||||||
|
#define VIN_RANGE 3.3 // volts
|
||||||
|
#define ADC_BITS 12
|
||||||
|
#define ADC_OFFSET 30
|
||||||
|
|
||||||
|
#define VOLTAGE_SCALES 5
|
||||||
|
const char * const gVoltageScaleStr[VOLTAGE_SCALES] = {
|
||||||
|
"100 mV", "200 mV", "500 mV", " 1 V", " 2 V"
|
||||||
|
};
|
||||||
|
|
||||||
|
const float gVoltageScale[VOLTAGE_SCALES] = {
|
||||||
|
0.1, 0.2, 0.5, 1., 2.
|
||||||
|
};
|
||||||
|
|
||||||
|
int RisingTrigger(void);
|
||||||
|
|
||||||
// start a pwm test signal
|
// start a pwm test signal
|
||||||
void start_signal() {
|
void start_signal() {
|
||||||
// configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2
|
// configure M0PWM2, at GPIO PF2, BoosterPack 1 header C1 pin 2
|
||||||
|
@ -87,14 +102,22 @@ int main(void) {
|
||||||
ButtonInit();
|
ButtonInit();
|
||||||
IntMasterEnable();
|
IntMasterEnable();
|
||||||
|
|
||||||
|
uint8_t voltage_scale = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// handle buttons
|
// handle buttons
|
||||||
Button button = (Button) 0;
|
Button button = (Button) 0;
|
||||||
while (fifo_get(&button)) {
|
while (fifo_get(&button)) {
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case S2:
|
case S2: // draw
|
||||||
drawRequested = 1;
|
drawRequested = 1;
|
||||||
break;
|
break;
|
||||||
|
case Up: // next scale
|
||||||
|
voltage_scale = (voltage_scale + 1) % VOLTAGE_SCALES;
|
||||||
|
break;
|
||||||
|
case Down: // previous scale
|
||||||
|
voltage_scale = (voltage_scale + VOLTAGE_SCALES - 1) % VOLTAGE_SCALES;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,9 +153,15 @@ int main(void) {
|
||||||
drawRequested = 0;
|
drawRequested = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GrContextForegroundSet(&sContext, ClrWheat);
|
||||||
|
GrStringDraw(&sContext, gVoltageScaleStr[voltage_scale], /*length*/ -1, /*x*/ 0, /*y*/ 0, /*opaque*/ false);
|
||||||
|
|
||||||
|
float fVoltsPerDiv = gVoltageScale[voltage_scale];
|
||||||
|
float fScale = (VIN_RANGE * PIXELS_PER_DIV)/((1 << ADC_BITS) * fVoltsPerDiv);
|
||||||
|
|
||||||
GrContextForegroundSet(&sContext, ClrPink);
|
GrContextForegroundSet(&sContext, ClrPink);
|
||||||
for(j=0; j<LOCAL_BUF_LEN; j++) {
|
for(j=0; j<LOCAL_BUF_LEN; j++) {
|
||||||
#define TRANSPOSE(x) (HEIGHT/2) - (x >> 6) // reduce from twelve to six bits, then flip and center
|
#define TRANSPOSE(x) (HEIGHT/2) - (int)roundf(fScale * ((int)x - ADC_OFFSET));
|
||||||
uint32_t upper,lower, current, last;
|
uint32_t upper,lower, current, last;
|
||||||
|
|
||||||
if (j==0) {
|
if (j==0) {
|
||||||
|
@ -191,7 +220,6 @@ int main(void) {
|
||||||
|
|
||||||
int RisingTrigger(void) // search for rising edge trigger
|
int RisingTrigger(void) // search for rising edge trigger
|
||||||
{
|
{
|
||||||
#define ADC_OFFSET 20
|
|
||||||
int x = gADCBufferIndex - (WIDTH / 2); // half screen width
|
int x = gADCBufferIndex - (WIDTH / 2); // half screen width
|
||||||
int x_stop = x - ADC_BUFFER_SIZE/2;
|
int x_stop = x - ADC_BUFFER_SIZE/2;
|
||||||
for (; x > x_stop; x--) {
|
for (; x > x_stop; x--) {
|
||||||
|
|
Loading…
Reference in a new issue