Are interrupts enabled by default in OpenMSP430, where is this defined in the code, apart from the watchdog enable/disable flag in _defines.v.
In any msp430 I remeber gie is not enabled by default. The same seems to happen in OpenMSP430, see omsp_register_file.v
always #(posedge mclk_r2 or posedge puc_rst)
if (puc_rst) r2 <= 16'h0000;
Related
I set the dataroom of the mbuf from 2048 to 64B. To receive large packets(>64B) with a 64B size dataroom mbuf, DPDK reminds me that I need to enable scattered mode. So how can I enable scattered mode?
Rx scatter can be enabled at the stage when rte_eth_dev_configure() is invoked. To do that, one should pass flag RTE_ETH_RX_OFFLOAD_SCATTER via dev_conf.rx_mode.offloads, with dev_conf being passed by pointer as the last argument to rte_eth_dev_configure().
To check the feature with testpmd, one can pass command-line argument --enable-scatter.
In my project I need to measure distances up to 3-4m, so I am using a HC-SR04P sensor hooked up to an ESP32 dev board.
The code is written without any third-party library (was inspired by a very simple HC-SR04 arduino library, though), in plain C, within a project created from the ESP32 eclipse IDF plugin; no extra libraries or arduino code; just the RTOS.
Everything works fine when the device boots and measurements are pretty accurate, but after a while (can't say exactly what triggers this), the sensor/devboard circuit (can't say which) starts behaving strangely : after the TRIG pulse, the ECHO pin does not go HIGH within a reasonable 1s timeout, and no measurement is performed.
Once this happens, no new measurement is performed again unless reboot/power on; it looks like something happens and somehow there is a faulty state either for the sensor or within the communication code.
A couple of observations :
sensor is the right version to be powered at 3.3V.
HC-SR04P uses GPIO2 and GPIO4 for TRIG and ECHO.
measurements are not required to be frequent, hence the 30s timer for the measurement task.
at power on, everything works fine.
after reset by dev board micro-switch, everything works correctly again.
when timeout occurs, re-init the sensor (settings up GPIOs, etc.), but nothing happens; still timeouts.
For reference, the timing function is below (the HCSR04_Info struct holds only pin and measurement data); it is called from a timed task every 30s.
uint32_t hcsr04_timing(HCSR04_Info* pDevice)
{
// TRIG pulse for 10ms
gpio_set_level(pDevice->trig, 1);
ets_delay_us(10);
gpio_set_level(pDevice->trig, 0);
pDevice->startMicros = esp_timer_get_time();
// wait for the echo pin HIGH or timeout
while ((!gpio_get_level(pDevice->echo)) && (esp_timer_get_time() - pDevice->startMicros) <= pDevice->timeout);
if (!gpio_get_level(pDevice->echo)) {
pDevice->status = STATUS_OFFLINE;
ESP_LOGE(TAG, "hcsr04_timing timeout (1)");
return 0;
}
pDevice->startMicros = esp_timer_get_time();
// wait for the echo pin LOW or timeout
while ((gpio_get_level(pDevice->echo)) && (esp_timer_get_time() - pDevice->startMicros) <= pDevice->timeout);
if (gpio_get_level(pDevice->echo)) {
pDevice->status = STATUS_OFFLINE;
ESP_LOGE(TAG, "hcsr04_timing timeout (2)");
return 0;
}
pDevice->status = STATUS_ONLINE;
pDevice->endMicros = esp_timer_get_time();
return pDevice->endMicros - pDevice->startMicros;
}
Any help is appreciated. Thank you.
This does not generate a pulse of 10 ms; it's 10 us. Probably takes your device into an undetermined state eventually.
// TRIG pulse for 10ms
gpio_set_level(pDevice->trig, 1);
ets_delay_us(10);
gpio_set_level(pDevice->trig, 0);
The comment in the header file where ets_delay_us() is defined says: In FreeRTOS task, please call FreeRTOS apis.
Anyway, use delay(10) if in Arduino-land; or vTaskDelay(pdMS_TO_TICKS(10)) if in FreeRTOS-land.
Following up on campescassiano suggestions on overflow, the solution finally presented itself. Not really an overflow in the exact sense of the problem, but closely related.
It's finally a stupid bug in the code, so please close or delete the question if appropriate.
The problem was that pDevice->startMicros was defined as an uint32_t (probably because of a copy/paste or bad habit error), while esp_timer_get_time() returns microseconds as an uint64_t.
So it 'overflows' at about 1h 11m 34s (which is about 232 microseconds) after boot, and timeout calculations become off since (esp_timer_get_time() - pDevice->startMicros) will obviously be an uint64_t.
Because of that (esp_timer_get_time() - pDevice->startMicros) <= pDevice->timeout will always be false after 1h 11m 34s, so the loop breaks before getting an ECHO input.
I am trying to control a servo motor on a timer using buttons and the ATtiny85. I am able to use the ATtiny to make an LED blink at the push of a button but once I include the servo library my code does not work.
I have tried using the Servo.h library and the Servo8Bit.h library but neither work. I thought that the issue might be coming from one timer being used for two different things so I went into the Servo8Bit.h and Servo8Bit.cpp source files and changed all Timer0 to Timer1 and all TCCR0B to TCCR1B.
I receive these error messages when I try to upload my code:
/private/var/folders/kd/6b3mdhb90xl1rm2j9_dvn7vr0000gn/T/AppTranslocation/EDE8B1E7-9D65-436D-87B1-4534CFB3B4CF/d/Arduino.app/Contents/Java/libraries/Servo8Bit-master/Servo8Bit.cpp: In static member function 'static void ServoSequencer::setupTimerPrescaler()':
/private/var/folders/kd/6b3mdhb90xl1rm2j9_dvn7vr0000gn/T/AppTranslocation/EDE8B1E7-9D65-436D-87B1-4534CFB3B4CF/d/Arduino.app/Contents/Java/libraries/Servo8Bit-master/Servo8Bit.cpp:493:9: error: 'TCCR1A' was not declared in this scope
TCCR1A = 0;
^
/private/var/folders/kd/6b3mdhb90xl1rm2j9_dvn7vr0000gn/T/AppTranslocation/EDE8B1E7-9D65-436D-87B1-4534CFB3B4CF/d/Arduino.app/Contents/Java/libraries/Servo8Bit-master/Servo8Bit.cpp:498:13: error: 'TCCR1B' was not declared in this scope
TCCR1B &= ~(1<< CS02); //clear
^
Using library Servo8Bit-master in folder: /private/var/folders/kd/6b3mdhb90xl1rm2j9_dvn7vr0000gn/T/AppTranslocation/EDE8B1E7-9D65-436D-87B1-4534CFB3B4CF/d/Arduino.app/Contents/Java/libraries/Servo8Bit-master (legacy)
exit status 1
Error compiling for board ATtiny25/45/85.
The expected result is that after uploading the code I will press a button. After a specified amount of time, 10 minutes in this case, the motor should move but the code doesn't even upload.
All you have to do is comment/uncomment the right choice in the header file Servo8Bit.h:
//Options
//pick one, comment out the other one out:
//#define USE_TIMER0
#define USE_TIMER1
and it'll be compiled with correct settings and so on.
You've probably tried to change 0 to 1 everywhere and failed because the timer0 and timer1 aren't the same. The timer1 doesn't have two control registers A and B unlike timer0.
I'm using a Cortex-M3 LPC1548 from NXP with uVision IDE.
In the main() function, if I use:
SysTick_Config(SystemCoreClock * SYSTICK_INT_FREQ);
NVIC_EnableIRQ(SysTick_IRQn); // <--- HardFault happens in this line.
I got a HardFault exception everytime.
However, if I remove the NVIC_EnableIRQ(...) like this:
SysTick_Config(SystemCoreClock * SYSTICK_INT_FREQ);
code runs fine.
Does anyone knows why enabling Systick interrupt causes a HardFault?
I've done this before in a Cortex-M0 and never had problems.
Systick_IRQn is a negative value, you cannot use NVIC_EnableIRQ() with Systick. The out-of-bounds register access probably causes your hardfault.
The systick interrupt is enabled as soon as the corresponding bit in Systick->CTRL is set.
However, NVIC_SetPriority() supports Systick_IRQn among others like PendSV_IRQn.
What needs to be very clear here is that NVIC_EnableIRQ() can only be used to enable/disable exceptions numbers with values greater than 16.
Exceptions with numbers greater than 16 are called interrupt inputs while below 16 are system exceptions.
That means that the system exceptions listed below (example for Cortex-M3) cannot be used with NVIC_EnableIRQn():
1 Reset
2.NMU
3.HardFault
4.MemManage Fault
5.Bus Fault
6.Usage Fault
7-10. Reserved
11 SVC
12 Debug Monitor
13 Reserved
14 PendSV
15 Systick
So, the Systick Interrupt should never be activated using NVIC_EnableIRQ because it's an system exception. If one is using the CMSIS function SysTick_Config() no interrupt activation is needed since this function takes care of activating the Systick interrupt.
P.S. Information was taken from the excelent book from Joseph Yiu, The Definitive Guide to ARM Cortex-M3 and Cortex-M4 Processors and by analysing the function NVIC_EnableIRQ().
I'm having trouble with what should be a very simple piece of code. My objective is to turn an LED on while a button is being pressed. In this case the input logic will go low when I press the button. The LED is connected to PORTC.2 and the button is connected to PORTC.0. Here is the code:
dim test as bit
main:
TRISC = %00000001
ANSEL = %00000000
PORTC= 0
cmcon0=0
Testbutton:
test = PORTC.0
if test = 0 then
PORTC = %00000100
goto Testbutton
end if
PORTC = %00000000
end.
The problem is the PIC always outputs high no matter what the input is. So far I have used a multimeter to verify that the input is indeed changing from 5V to 0V when the button is pressed, I have tried using a different input pin, and I have tried using a different PIC. I suspect that since the input is always being read as low that the PIC may not be properly initialized but I'm not entirely sure.
Thanks for any insight that you might be able to give me
The datasheet of 16f684 states on page 42 that :
The ANSEL and CMCON0 registers must be initialized to configure an analog channel as a digital input. Pins configured as analog inputs will read ‘0’.
These registers are actually initialized in your code. ANSEL is initialized to 0, so all analog input are deactivated. Yet, the CMCON0 register should be initialized to xxxxx111 or 07h. See the example 4.3 on page 42. The last three bits of CMCON0 correspond to the mode of operation of comparators and choosing 111 turns them off. See page 60.
Don't forget to add goto Testbutton if you want the led to light up again as the button is released. It may be intentional though : it's up to you !