swap between rising and falling edge detection
This commit is contained in:
parent
808d474ec3
commit
b091f216e8
1 changed files with 24 additions and 6 deletions
26
main.c
26
main.c
|
@ -51,7 +51,7 @@ const float gVoltageScale[VOLTAGE_SCALES] = {
|
|||
|
||||
uint32_t cputime_unloaded;
|
||||
|
||||
int RisingTrigger(void);
|
||||
int Trigger(bool rising);
|
||||
|
||||
// start a pwm test signal
|
||||
void start_signal() {
|
||||
|
@ -129,6 +129,7 @@ int main(void) {
|
|||
IntMasterEnable();
|
||||
|
||||
uint8_t voltage_scale = 0;
|
||||
uint8_t rising = 1;
|
||||
|
||||
while (true) {
|
||||
// calculate cpu usage
|
||||
|
@ -141,6 +142,9 @@ int main(void) {
|
|||
Button button = (Button) 0;
|
||||
while (fifo_get(&button)) {
|
||||
switch (button) {
|
||||
case S1: // toggle edge
|
||||
rising = !rising;
|
||||
break;
|
||||
case S2: // draw
|
||||
refresh = !refresh;
|
||||
break;
|
||||
|
@ -175,13 +179,19 @@ int main(void) {
|
|||
snprintf(str, sizeof(str), "CPU Load %.1f%%", usage_percent);
|
||||
GrStringDraw(&sContext, str, /*length*/ -1, /*x*/ 0, /*y*/ HEIGHT - 10, /*opaque*/ false);
|
||||
|
||||
if (rising) {
|
||||
GrStringDraw(&sContext, "^", /*length*/ -1, /*x*/ WIDTH - 10, /*y*/ 0, /*opaque*/ false);
|
||||
} else {
|
||||
GrStringDraw(&sContext, "v", /*length*/ -1, /*x*/ WIDTH - 10, /*y*/ 0, /*opaque*/ false);
|
||||
}
|
||||
|
||||
// display graph
|
||||
#define LOCAL_BUF_LEN 128
|
||||
uint16_t local_adc_buffer[LOCAL_BUF_LEN]; // copy of adc buffer
|
||||
int32_t adc_current_index;
|
||||
int32_t j;
|
||||
if (refresh) {
|
||||
int trigger = RisingTrigger();
|
||||
int trigger = Trigger(rising);
|
||||
|
||||
adc_current_index = trigger - (WIDTH / 2);
|
||||
for (j=0; j<LOCAL_BUF_LEN; j++) {
|
||||
|
@ -251,15 +261,23 @@ int main(void) {
|
|||
}
|
||||
}
|
||||
|
||||
int RisingTrigger(void) // search for rising edge trigger
|
||||
int Trigger(bool rising) // search for edge trigger
|
||||
{
|
||||
int x = gADCBufferIndex - (WIDTH / 2); // half screen width
|
||||
int x_stop = x - ADC_BUFFER_SIZE/2;
|
||||
for (; x > x_stop; x--) {
|
||||
if (rising) {
|
||||
if ( gADCBuffer[ADC_BUFFER_WRAP(x)] >= ADC_OFFSET &&
|
||||
gADCBuffer[ADC_BUFFER_WRAP(x-1)] < ADC_OFFSET)
|
||||
gADCBuffer[ADC_BUFFER_WRAP(x-1)] < ADC_OFFSET) {
|
||||
break;
|
||||
}
|
||||
} else { // falling edge trigger
|
||||
if ( gADCBuffer[ADC_BUFFER_WRAP(x)] <= ADC_OFFSET &&
|
||||
gADCBuffer[ADC_BUFFER_WRAP(x-1)] > ADC_OFFSET) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x == x_stop) // for loop ran to the end
|
||||
x = x = gADCBufferIndex - (WIDTH / 2); // reset x back to how it was initialized
|
||||
return x;
|
||||
|
|
Loading…
Reference in a new issue