How change PCNT threshold value?

clarkster
Posts: 47
Joined: Sat Sep 23, 2017 12:36 pm

How change PCNT threshold value?

Postby clarkster » Thu Apr 05, 2018 2:00 am

I need to sometimes change the value for PCNT_EVT_THRES_0. I initially set it when I configure the PCNT and if I try to change it anywhere else in my program I get this crash....

Code: Select all

Guru Meditation Error: Core  0 panic'ed (IllegalInstruction)
. Exception was unhandled.
Core 0 register dump:
PC      : 0x400d212c  PS      : 0x00060330  A0      : 0x00000000  A1      : 0x3ffb6750  
0x400d212c: change_threshold at /Users/clark/Documents/EclipseWorkspaces/esp32-workspace/PCNTExample/main/./pcnt_example_main.c:175

A2      : 0x00000000  A3      : 0x00000000  A4      : 0x00000000  A5      : 0x00000000  
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x800d212c  A9      : 0x3ffb6720  
A10     : 0x00000000  A11     : 0x3ffb1154  A12     : 0x0005fff8  A13     : 0x3ffb67e4  
A14     : 0x00000000  A15     : 0x00000000  SAR     : 0x0000001f  EXCCAUSE: 0x00000000  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  

Backtrace: 0x400d212c:0x3ffb6750 0x7ffffffd:0x3ffb6770
0x400d212c: change_threshold at /Users/clark/Documents/EclipseWorkspaces/esp32-workspace/PCNTExample/main/./pcnt_example_main.c:175
I have tried pausing the counter and disabling the interrupt before making the Threshold change, but nothing helps. I don't see anything in the TRM or in the ESP IDF documentation about how to do this.

ESP_Sprite
Posts: 9766
Joined: Thu Nov 26, 2015 4:08 am

Re: How change PCNT threshold value?

Postby ESP_Sprite » Thu Apr 05, 2018 2:22 am

That's a weird bug... can you post the code that triggers it here?

clarkster
Posts: 47
Joined: Sat Sep 23, 2017 12:36 pm

Re: How change PCNT threshold value?

Postby clarkster » Thu Apr 05, 2018 2:29 am

Here you go...

Code: Select all

/* Pulse counter module - Example

   For other examples please check:
   https://github.com/espressif/esp-idf/tree/master/examples

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/portmacro.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/periph_ctrl.h"
#include "driver/ledc.h"
#include "driver/gpio.h"
#include "driver/pcnt.h"
#include "esp_attr.h"
#include "esp_log.h"
#include "soc/gpio_sig_map.h"

/**
 * TEST CODE BRIEF
 *
 * Use PCNT module to count rising edges generated by LEDC module.
 *
 * Functionality of GPIOs used in this example:
 *   - GPIO18 - output pin of a sample 1 Hz pulse generator,
 *   - GPIO4 - pulse input pin,
 *   - GPIO5 - control input pin.
 *
 * Load example, open a serial port to view the message printed on your screen.
 *
 * To do this test, you should connect GPIO18 with GPIO4.
 * GPIO5 is the control signal, you can leave it floating with internal pull up,
 * or connect it to ground. If left floating, the count value will be increasing.
 * If you connect GPIO5 to GND, the count value will be decreasing.
 *
 * An interrupt will be triggered when the counter value:
 *   - reaches 'thresh1' or 'thresh0' value,
 *   - reaches 'l_lim' value or 'h_lim' value,
 *   - will be reset to zero.
 */
#define PCNT_TEST_UNIT      PCNT_UNIT_0
#define PCNT_H_LIM_VAL      10
#define PCNT_L_LIM_VAL     -10
#define PCNT_THRESH1_VAL    5
#define PCNT_THRESH0_VAL   -5
#define PCNT_INPUT_SIG_IO   18  // Pulse Input GPIO, was 4
#define PCNT_INPUT_CTRL_IO  5  // Control GPIO HIGH=count up, LOW=count down
#define LEDC_OUTPUT_IO      18 // Output GPIO of a sample 1 Hz pulse generator

xQueueHandle pcnt_evt_queue;   // A queue to handle pulse counter events

/* A sample structure to pass events from the PCNT
 * interrupt handler to the main program.
 */
typedef struct {
    int unit;  // the PCNT unit that originated an interrupt
    uint32_t status; // information on the event type that caused the interrupt
} pcnt_evt_t;

/* Decode what PCNT's unit originated an interrupt
 * and pass this information together with the event type
 * the main program using a queue.
 */
static void IRAM_ATTR pcnt_example_intr_handler(void *arg)
{
    uint32_t intr_status = PCNT.int_st.val;
    int i;
    pcnt_evt_t evt;
    portBASE_TYPE HPTaskAwoken = pdFALSE;

    for (i = 0; i < PCNT_UNIT_MAX; i++) {
        if (intr_status & (BIT(i))) {
            evt.unit = i;
            /* Save the PCNT event type that caused an interrupt
               to pass it to the main program */
            evt.status = PCNT.status_unit[i].val;
            PCNT.int_clr.val = BIT(i);
            xQueueSendFromISR(pcnt_evt_queue, &evt, &HPTaskAwoken);
            if (HPTaskAwoken == pdTRUE) {
                portYIELD_FROM_ISR();
            }
        }
    }
}

/* Configure LED PWM Controller
 * to output sample pulses at 1 Hz with duty of about 10%
 */
static void ledc_init(void)
{
    // Prepare and then apply the LEDC PWM timer configuration
    ledc_timer_config_t ledc_timer;
    ledc_timer.speed_mode       = LEDC_HIGH_SPEED_MODE;
    ledc_timer.timer_num        = LEDC_TIMER_1;
    ledc_timer.duty_resolution  = LEDC_TIMER_10_BIT;
    ledc_timer.freq_hz          = 1;  // set output frequency at 1 Hz
    ledc_timer_config(&ledc_timer);

    // Prepare and then apply the LEDC PWM channel configuration
    ledc_channel_config_t ledc_channel;
    ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
    ledc_channel.channel    = LEDC_CHANNEL_1;
    ledc_channel.timer_sel  = LEDC_TIMER_1;
    ledc_channel.intr_type  = LEDC_INTR_DISABLE;
    ledc_channel.gpio_num   = LEDC_OUTPUT_IO;
    ledc_channel.duty       = 100; // set duty at about 10%
    ledc_channel_config(&ledc_channel);
}

/* Initialize PCNT functions:
 *  - configure and initialize PCNT
 *  - set up the input filter
 *  - set up the counter events to watch
 */
static void pcnt_example_init(void)
{
    /* Prepare configuration for the PCNT unit */
    pcnt_config_t pcnt_config = {
        // Set PCNT input signal and control GPIOs
        .pulse_gpio_num = 4, //LEDC_OUTPUT_IO,
        .ctrl_gpio_num = PCNT_INPUT_CTRL_IO,
        .channel = PCNT_CHANNEL_0,
        .unit = PCNT_TEST_UNIT,
        // What to do on the positive / negative edge of pulse input?
        .pos_mode = PCNT_COUNT_INC,   // Count up on the positive edge
        .neg_mode = PCNT_COUNT_DIS,   // Keep the counter value on the negative edge
        // What to do when control input is low or high?
        .lctrl_mode = PCNT_MODE_REVERSE, // Reverse counting direction if low
        .hctrl_mode = PCNT_MODE_KEEP,    // Keep the primary counter mode if high
        // Set the maximum and minimum limit values to watch
        .counter_h_lim = PCNT_H_LIM_VAL,
        .counter_l_lim = PCNT_L_LIM_VAL,
    };
    /* Initialize PCNT unit */
    pcnt_unit_config(&pcnt_config);

    /* Configure and enable the input filter */
    pcnt_set_filter_value(PCNT_TEST_UNIT, 100);
    pcnt_filter_enable(PCNT_TEST_UNIT);

    /* Set threshold 0 and 1 values and enable events to watch */
    pcnt_set_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_1, PCNT_THRESH1_VAL);
    pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_THRES_1);
    pcnt_set_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_0, PCNT_THRESH0_VAL);
    pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_THRES_0);
    /* Enable events on zero, maximum and minimum limit values */
//    pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_ZERO);
//    pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_H_LIM);
//    pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_L_LIM);

    /* Initialize PCNT's counter */
    pcnt_counter_pause(PCNT_TEST_UNIT);
    pcnt_counter_clear(PCNT_TEST_UNIT);

    /* Register ISR handler and enable interrupts for PCNT unit */
    pcnt_isr_register(pcnt_example_intr_handler, NULL, 0, NULL);
    pcnt_intr_enable(PCNT_TEST_UNIT);

    /* Everything is set up, now go to counting */
    pcnt_counter_resume(PCNT_TEST_UNIT);
}

void change_threshold() {
	vTaskDelay(5000 / portTICK_PERIOD_MS);
	pcnt_counter_pause(PCNT_TEST_UNIT);
	pcnt_intr_disable(PCNT_TEST_UNIT);
	pcnt_set_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_0, -8);
	pcnt_intr_enable(PCNT_TEST_UNIT);
	pcnt_counter_resume(PCNT_TEST_UNIT);
}

void app_main()
{
    /* Initialize PCNT event queue and PCNT functions */
    pcnt_evt_queue = xQueueCreate(10, sizeof(pcnt_evt_t));
    pcnt_example_init();

    /* Initialize LEDC to generate sample pulse signal */
    ledc_init();

    xTaskCreate(change_threshold, "change_threshold", 2048, NULL, 10, NULL);

    int16_t count = 0;
    pcnt_evt_t evt;
    portBASE_TYPE res;
    while (1) {
        /* Wait for the event information passed from PCNT's interrupt handler.
         * Once received, decode the event type and print it on the serial monitor.
         */
        res = xQueueReceive(pcnt_evt_queue, &evt, 1000 / portTICK_PERIOD_MS);
        if (res == pdTRUE) {
            pcnt_get_counter_value(PCNT_TEST_UNIT, &count);
            printf("Event PCNT unit[%d]; cnt: %d\n", evt.unit, count);
            if (evt.status & PCNT_STATUS_THRES1_M) {
                printf("THRES1 EVT\n");
            }
            if (evt.status & PCNT_STATUS_THRES0_M) {
                printf("THRES0 EVT\n");
            }
            if (evt.status & PCNT_STATUS_L_LIM_M) {
                printf("L_LIM EVT\n");
            }
            if (evt.status & PCNT_STATUS_H_LIM_M) {
                printf("H_LIM EVT\n");
            }
            if (evt.status & PCNT_STATUS_ZERO_M) {
                printf("ZERO EVT\n");
            }
        } else {
            pcnt_get_counter_value(PCNT_TEST_UNIT, &count);
            printf("Current counter value :%d\n", count);
        }
    }
}
I took the PCNT example, added a task to change the threshold. I'm trying to simulate what I'm doing in another program. I don't get that same crash in my other program. In it, the change of threshold value never seems to take effect. I can change the threshold value from 1000 to 200 and the PCNT continues interrupting at 1000.

clarkster
Posts: 47
Joined: Sat Sep 23, 2017 12:36 pm

Re: How change PCNT threshold value?

Postby clarkster » Thu Apr 05, 2018 2:19 pm

I modified the program a bit by removing the task and causing the PCNT threshold to change on the main thread. Now I am getting the same result I see in my program....the change in the threshold is ignored.

I'm guessing that trying to change a threshold in another thread is what causes the crash.

Here is a simple program demonstrating this slightly different problem:

Code: Select all

/* Pulse counter module - Example

   For other examples please check:
   https://github.com/espressif/esp-idf/tree/master/examples

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/portmacro.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/periph_ctrl.h"
#include "driver/ledc.h"
#include "driver/gpio.h"
#include "driver/pcnt.h"
#include "esp_attr.h"
#include "esp_log.h"
#include "soc/gpio_sig_map.h"

/**
 * TEST CODE BRIEF
 *
 * Use PCNT module to count rising edges generated by LEDC module.
 *
 * Functionality of GPIOs used in this example:
 *   - GPIO18 - output pin of a sample 1 Hz pulse generator,
 *   - GPIO4 - pulse input pin,
 *   - GPIO5 - control input pin.
 *
 * Load example, open a serial port to view the message printed on your screen.
 *
 * To do this test, you should connect GPIO18 with GPIO4.
 * GPIO5 is the control signal, you can leave it floating with internal pull up,
 * or connect it to ground. If left floating, the count value will be increasing.
 * If you connect GPIO5 to GND, the count value will be decreasing.
 *
 * An interrupt will be triggered when the counter value:
 *   - reaches 'thresh1' or 'thresh0' value,
 *   - reaches 'l_lim' value or 'h_lim' value,
 *   - will be reset to zero.
 */
#define PCNT_TEST_UNIT      PCNT_UNIT_0
#define PCNT_H_LIM_VAL      10
#define PCNT_L_LIM_VAL     -10
#define PCNT_THRESH1_VAL    5
#define PCNT_THRESH0_VAL   -5
#define PCNT_INPUT_SIG_IO   18  // Pulse Input GPIO, was 4
#define PCNT_INPUT_CTRL_IO  5  // Control GPIO HIGH=count up, LOW=count down
#define LEDC_OUTPUT_IO      18 // Output GPIO of a sample 1 Hz pulse generator

xQueueHandle pcnt_evt_queue;   // A queue to handle pulse counter events

/* A sample structure to pass events from the PCNT
 * interrupt handler to the main program.
 */
typedef struct {
    int unit;  // the PCNT unit that originated an interrupt
    uint32_t status; // information on the event type that caused the interrupt
} pcnt_evt_t;

/* Decode what PCNT's unit originated an interrupt
 * and pass this information together with the event type
 * the main program using a queue.
 */
static void IRAM_ATTR pcnt_example_intr_handler(void *arg)
{
    uint32_t intr_status = PCNT.int_st.val;
    int i;
    pcnt_evt_t evt;
    portBASE_TYPE HPTaskAwoken = pdFALSE;

    for (i = 0; i < PCNT_UNIT_MAX; i++) {
        if (intr_status & (BIT(i))) {
            evt.unit = i;
            /* Save the PCNT event type that caused an interrupt
               to pass it to the main program */
            evt.status = PCNT.status_unit[i].val;
            PCNT.int_clr.val = BIT(i);
            xQueueSendFromISR(pcnt_evt_queue, &evt, &HPTaskAwoken);
            if (HPTaskAwoken == pdTRUE) {
                portYIELD_FROM_ISR();
            }
        }
    }
}

/* Configure LED PWM Controller
 * to output sample pulses at 1 Hz with duty of about 10%
 */
static void ledc_init(void)
{
    // Prepare and then apply the LEDC PWM timer configuration
    ledc_timer_config_t ledc_timer;
    ledc_timer.speed_mode       = LEDC_HIGH_SPEED_MODE;
    ledc_timer.timer_num        = LEDC_TIMER_1;
    ledc_timer.duty_resolution  = LEDC_TIMER_10_BIT;
    ledc_timer.freq_hz          = 1;  // set output frequency at 1 Hz
    ledc_timer_config(&ledc_timer);

    // Prepare and then apply the LEDC PWM channel configuration
    ledc_channel_config_t ledc_channel;
    ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
    ledc_channel.channel    = LEDC_CHANNEL_1;
    ledc_channel.timer_sel  = LEDC_TIMER_1;
    ledc_channel.intr_type  = LEDC_INTR_DISABLE;
    ledc_channel.gpio_num   = LEDC_OUTPUT_IO;
    ledc_channel.duty       = 100; // set duty at about 10%
    ledc_channel_config(&ledc_channel);
}

/* Initialize PCNT functions:
 *  - configure and initialize PCNT
 *  - set up the input filter
 *  - set up the counter events to watch
 */
static void pcnt_example_init(void)
{
    /* Prepare configuration for the PCNT unit */
    pcnt_config_t pcnt_config = {
        // Set PCNT input signal and control GPIOs
        .pulse_gpio_num = 4, //LEDC_OUTPUT_IO,
        .ctrl_gpio_num = PCNT_INPUT_CTRL_IO,
        .channel = PCNT_CHANNEL_0,
        .unit = PCNT_TEST_UNIT,
        // What to do on the positive / negative edge of pulse input?
        .pos_mode = PCNT_COUNT_INC,   // Count up on the positive edge
        .neg_mode = PCNT_COUNT_DIS,   // Keep the counter value on the negative edge
        // What to do when control input is low or high?
        .lctrl_mode = PCNT_MODE_REVERSE, // Reverse counting direction if low
        .hctrl_mode = PCNT_MODE_KEEP,    // Keep the primary counter mode if high
        // Set the maximum and minimum limit values to watch
        .counter_h_lim = PCNT_H_LIM_VAL,
        .counter_l_lim = PCNT_L_LIM_VAL,
    };
    /* Initialize PCNT unit */
    pcnt_unit_config(&pcnt_config);

    /* Configure and enable the input filter */
    pcnt_set_filter_value(PCNT_TEST_UNIT, 100);
    pcnt_filter_enable(PCNT_TEST_UNIT);

    /* Set threshold 0 and 1 values and enable events to watch */
    pcnt_set_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_1, PCNT_THRESH1_VAL);
    pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_THRES_1);
    pcnt_set_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_0, PCNT_THRESH0_VAL);
    pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_THRES_0);
    /* Enable events on zero, maximum and minimum limit values */
//    pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_ZERO);
//    pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_H_LIM);
//    pcnt_event_enable(PCNT_TEST_UNIT, PCNT_EVT_L_LIM);

    /* Initialize PCNT's counter */
    pcnt_counter_pause(PCNT_TEST_UNIT);
    pcnt_counter_clear(PCNT_TEST_UNIT);

    /* Register ISR handler and enable interrupts for PCNT unit */
    pcnt_isr_register(pcnt_example_intr_handler, NULL, 0, NULL);
    pcnt_intr_enable(PCNT_TEST_UNIT);

    /* Everything is set up, now go to counting */
    pcnt_counter_resume(PCNT_TEST_UNIT);
}

void change_threshold() {
//	vTaskDelay(5000 / portTICK_PERIOD_MS);
//	pcnt_counter_pause(PCNT_TEST_UNIT);
//	pcnt_intr_disable(PCNT_TEST_UNIT);
	pcnt_set_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_0, -8);
//	pcnt_intr_enable(PCNT_TEST_UNIT);
//	pcnt_counter_resume(PCNT_TEST_UNIT);
}

void app_main()
{
    /* Initialize PCNT event queue and PCNT functions */
    pcnt_evt_queue = xQueueCreate(10, sizeof(pcnt_evt_t));
    pcnt_example_init();

    /* Initialize LEDC to generate sample pulse signal */
    ledc_init();

//    xTaskCreate(change_threshold, "change_threshold", 2048, NULL, 10, NULL);

    int16_t count = 0;
    pcnt_evt_t evt;
    portBASE_TYPE res;
    while (1) {
        /* Wait for the event information passed from PCNT's interrupt handler.
         * Once received, decode the event type and print it on the serial monitor.
         */
        res = xQueueReceive(pcnt_evt_queue, &evt, 1000 / portTICK_PERIOD_MS);
        if (res == pdTRUE) {
            pcnt_get_counter_value(PCNT_TEST_UNIT, &count);
            printf("Event PCNT unit[%d]; cnt: %d\n", evt.unit, count);
            if (evt.status & PCNT_STATUS_THRES1_M) {
                printf("THRES1 EVT\n");
            }
            if (evt.status & PCNT_STATUS_THRES0_M) {
                printf("THRES0 EVT\n");
            }
            if (evt.status & PCNT_STATUS_L_LIM_M) {
                printf("L_LIM EVT\n");
            }
            if (evt.status & PCNT_STATUS_H_LIM_M) {
                printf("H_LIM EVT\n");
            }
            if (evt.status & PCNT_STATUS_ZERO_M) {
                printf("ZERO EVT\n");
            }
        } else {
            pcnt_get_counter_value(PCNT_TEST_UNIT, &count);
            printf("Current counter value :%d\n", count);
            if (count == -6) change_threshold();
        }
    }
}
No matter what I try, I cannot figure out how to change the PCNT threshold level.

Thanks for looking into this!

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: How change PCNT threshold value?

Postby WiFive » Fri Apr 06, 2018 7:01 am

It looks like the new value does not get latched into the comparator until the next threshhold event or zero event... or something

Code: Select all

Current counter value :1
Current counter value :2
Current counter value :3
Current counter value :4
Event PCNT unit[1]; cnt: 5
THRES1 EVT
Current counter value :5
Current counter value :6
Current counter value :7
Current counter value :8
Current counter value :9
Event PCNT unit[1]; cnt: 0
H_LIM EVT
ZERO EVT
THRES_1 val: 5
Setting THRES_1 val to: 6
THRES_1 val: 6
Current counter value :0
Current counter value :1
Current counter value :2
Current counter value :3
Current counter value :4
Event PCNT unit[1]; cnt: 5
THRES1 EVT
Current counter value :5
Current counter value :6
Current counter value :7
Current counter value :8
Current counter value :9
Event PCNT unit[1]; cnt: 0
H_LIM EVT
ZERO EVT
THRES_1 val: 6
Setting THRES_1 val to: 7
THRES_1 val: 7
Current counter value :0
Current counter value :1
Current counter value :2
Current counter value :3
Current counter value :4
Current counter value :5
Event PCNT unit[1]; cnt: 6
THRES1 EVT
Current counter value :6
Current counter value :7
Current counter value :8
Current counter value :9
Event PCNT unit[1]; cnt: 0
H_LIM EVT
ZERO EVT
THRES_1 val: 7
Setting THRES_1 val to: 8
THRES_1 val: 8
Current counter value :0
Current counter value :1
Current counter value :2
Current counter value :3
Current counter value :4
Current counter value :5
Current counter value :6
Event PCNT unit[1]; cnt: 7
THRES1 EVT
Current counter value :7
Current counter value :8
Current counter value :9

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: How change PCNT threshold value?

Postby WiFive » Fri Apr 06, 2018 7:51 am

This works so the counter has to hit zero to reload the threshold value.

Code: Select all

int16_t th;
pcnt_get_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_1, &th);
printf("THRES_1 val: %i\n", th);
pcnt_set_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_1, ++th);
printf("Setting THRES_1 val to: %i\n", th);
pcnt_get_event_value(PCNT_TEST_UNIT, PCNT_EVT_THRES_1, &th);
printf("THRES_1 val: %i\n", th);
pcnt_counter_clear(PCNT_TEST_UNIT);

Code: Select all

Current counter value :1
Current counter value :2
Current counter value :3
Current counter value :4
Event PCNT unit[1]; cnt: 5
THRES1 EVT
THRES_1 val: 5
Setting THRES_1 val to: 6
THRES_1 val: 6
Current counter value :0
Current counter value :1
Current counter value :2
Current counter value :3
Current counter value :4
Current counter value :5
Event PCNT unit[1]; cnt: 6
THRES1 EVT
THRES_1 val: 6
Setting THRES_1 val to: 7
THRES_1 val: 7
Current counter value :0
Current counter value :1
Current counter value :2
Current counter value :3
Current counter value :4
Current counter value :5
Current counter value :6
Event PCNT unit[1]; cnt: 7
THRES1 EVT
THRES_1 val: 7
Setting THRES_1 val to: 8
THRES_1 val: 8
Current counter value :0
Current counter value :1
Current counter value :2
Current counter value :3
Current counter value :4
Current counter value :5
Current counter value :6
Current counter value :7
Event PCNT unit[1]; cnt: 8
THRES1 EVT

clarkster
Posts: 47
Joined: Sat Sep 23, 2017 12:36 pm

Re: How change PCNT threshold value?

Postby clarkster » Fri Apr 06, 2018 10:22 pm

Thanks for looking into this. This behavior will make it harder to properly control the PCNT.

Is it possible to fix it so you don't have to reset the counter to update the threshold values? I'm guessing this is not in the IDF but rather at a lower level? And doesn't that mean it will be hard to fix?

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: How change PCNT threshold value?

Postby WiFive » Fri Apr 06, 2018 10:51 pm

A lower level like hardware so it is not going to change.

Pe3ucTop
Posts: 2
Joined: Fri Dec 10, 2021 1:55 pm

Re: How change PCNT threshold value?

Postby Pe3ucTop » Fri Dec 10, 2021 1:59 pm

Any update from official staff ?
I also stuck with this problem .
Maybe there is some additional registers to force update or etc ?

ESP_morris
Posts: 290
Joined: Wed Sep 05, 2018 6:23 am

Re: How change PCNT threshold value?

Postby ESP_morris » Thu Dec 16, 2021 3:12 am

Yes, confirmed by the digital design team, the threshold value will only take effect at some specific event (e.g. zero across, overflow). The hardware doesn't provide an async way to force update the register immediately.

Who is online

Users browsing this forum: iParcelBox and 98 guests