91欧美超碰AV自拍|国产成年人性爱视频免费看|亚洲 日韩 欧美一厂二区入|人人看人人爽人人操aV|丝袜美腿视频一区二区在线看|人人操人人爽人人爱|婷婷五月天超碰|97色色欧美亚州A√|另类A√无码精品一级av|欧美特级日韩特级

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何利用計(jì)時器中斷來保持一切正常運(yùn)轉(zhuǎn)

454398 ? 來源:網(wǎng)絡(luò)整理 ? 作者:網(wǎng)絡(luò)整理 ? 2019-11-27 16:45 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

設(shè)置

對于本指南中的所有示例,將使用以下接線:

如何利用計(jì)時器中斷來保持一切正常運(yùn)轉(zhuǎn)

什么是中斷?

中斷是一個信號,告訴處理器立即停止其正在執(zhí)行的操作并處理一些高優(yōu)先級的處理。這種高優(yōu)先級處理稱為中斷處理程序。

中斷處理程序與任何其他void函數(shù)一樣。如果編寫一個并將其附加到中斷,則在觸發(fā)該中斷信號時將調(diào)用該中斷。當(dāng)您從中斷處理程序返回時,處理器將返回以繼續(xù)之前的操作。

它們來自何處?

可以生成中斷

來自一個Arduino定時器的定時器中斷。

外部中斷由于外部中斷引腳之一的狀態(tài)改變而引起的外部中斷。

Pin-change中斷是由于一組引腳中任何一個引腳的狀態(tài)改變。

它們有什么用?

使用中斷,您無需編寫循環(huán)代碼即可連續(xù)檢查高優(yōu)先級中斷條件。您不必?fù)?dān)心由于長時間運(yùn)行的子例程而反應(yīng)遲鈍或錯過了按鍵操作。

當(dāng)中斷發(fā)生時,處理器將自動停止正在執(zhí)行的操作并調(diào)用中斷處理程序。您只需編寫代碼以響應(yīng)中斷。

定時器中斷

請勿致電給我們,我們會打電話給您

在本系列的第1部分中,我們學(xué)習(xí)了如何使用millis()進(jìn)行計(jì)時。但是為了進(jìn)行這項(xiàng)工作,我們每次都要在循環(huán)中調(diào)用millis()來查看是否該做某事了。一毫秒多次調(diào)用millis()只是發(fā)現(xiàn)時間沒有改變,這是一種浪費(fèi)。如果只需要每毫秒檢查一次,那會不會很好?

計(jì)時器和計(jì)時器中斷讓我們可以做到這一點(diǎn)。我們可以設(shè)置一個計(jì)時器來每毫秒中斷一次。計(jì)時器實(shí)際上會打電話給我們,讓我們知道現(xiàn)在該檢查時鐘了!

Arduino計(jì)時器

Arduino Uno有3個計(jì)時器:Timer0,Timer1和Timer2。已經(jīng)將Timer0設(shè)置為生成毫秒中斷,以更新millis()報告的毫秒計(jì)數(shù)器。既然這就是我們要尋找的東西,我們也將得到Timer0來為我們生成一個中斷!

頻率和計(jì)數(shù)

定時器是簡單的計(jì)數(shù)器,它們以從16MHz系統(tǒng)時鐘。您可以配置時鐘分頻器以更改頻率和各種不同的計(jì)數(shù)模式。您還可以將它們配置為在計(jì)時器達(dá)到特定計(jì)數(shù)時生成中斷。

Timer0是8位,從0到255計(jì)數(shù),并在溢出時生成中斷。默認(rèn)情況下,它使用64的時鐘分頻比為我們提供976.5625 Hz的中斷率(就我們的目的而言,足夠接近1KHz)。我們不會弄亂Timer0的頻率,因?yàn)槟菢訒茐腷reakmillis()!

比較寄存器

Arduino定時器具有許多配置寄存器??梢允褂肁rduino IDE中定義的特殊符號來讀取或?qū)懭脒@些符號。 有關(guān)所有這些寄存器及其功能的詳細(xì)說明,請參見下面的“ 進(jìn)一步閱讀”中的鏈接。

我們將建立一個《計(jì)時器0的strong》比較寄存器(該寄存器稱為OCR0A),在該計(jì)數(shù)中間的某個位置產(chǎn)生另一個中斷。在每次滴答時,計(jì)時器計(jì)數(shù)器都會與比較寄存器進(jìn)行比較,并且當(dāng)它們相等時,將產(chǎn)生一個中斷。

只要計(jì)數(shù)器值超過0xAF,下面的代碼就會產(chǎn)生一個“ TIMER0_COMPA”中斷。

下載:文件

復(fù)制代碼

// Timer0 is already used for millis() - we‘ll just interrupt somewhere

// in the middle and call the “Compare A” function below

OCR0A = 0xAF;

TIMSK0 |= _BV(OCIE0A); // Timer0 is already used for millis() - we’ll just interrupt somewhere

// in the middle and call the “Compare A” function below

OCR0A = 0xAF;

TIMSK0 |= _BV(OCIE0A);

然后,我們將為定時器中斷向量(稱為“ TIMER0_COMPA_vect”)定義一個中斷處理程序。在此中斷處理程序中,我們將完成循環(huán)中所有的工作。

下載:文件

復(fù)制代碼

// Interrupt is called once a millisecond,

SIGNAL(TIMER0_COMPA_vect)

{

unsigned long currentMillis = millis();

sweeper1.Update(currentMillis);

//if(digitalRead(2) == HIGH)

{

sweeper2.Update(currentMillis);

led1.Update(currentMillis);

}

led2.Update(currentMillis);

led3.Update(currentMillis);

} // Interrupt is called once a millisecond,

SIGNAL(TIMER0_COMPA_vect)

{

unsigned long currentMillis = millis();

sweeper1.Update(currentMillis);

//if(digitalRead(2) == HIGH)

{

sweeper2.Update(currentMillis);

led1.Update(currentMillis);

}

led2.Update(currentMillis);

led3.Update(currentMillis);

}

這給我們留下了一個完全空的循環(huán)。

下載:文件

復(fù)制代碼

void loop()

{

} void loop()

{

}

您現(xiàn)在可以在循環(huán)中做任何您想做的事情。您甚至可以decade廢并使用delay()!閃光燈和掃地機(jī)將不在乎。無論如何,它們?nèi)匀粫亢撩氡徽{(diào)用一次!

進(jìn)一步閱讀:

這只是計(jì)時器可以執(zhí)行的簡單示例。有關(guān)不同類型的計(jì)時器及其配置方式的更多詳細(xì)信息,請查看“庫和鏈接”頁面。

源代碼:

以下是整個代碼,包括閃光燈和掃地機(jī):

下載:文件

復(fù)制代碼

#include

class Flasher

{

// Class Member Variables

// These are initialized at startup

int ledPin; // the number of the LED pin

long OnTime; // milliseconds of on-time

long OffTime; // milliseconds of off-time

// These maintain the current state

int ledState; // ledState used to set the LED

unsigned long previousMillis; // will store last time LED was updated

// Constructor - creates a Flasher

// and initializes the member variables and state

public:

Flasher(int pin, long on, long off)

{

ledPin = pin;

pinMode(ledPin, OUTPUT);

OnTime = on;

OffTime = off;

ledState = LOW;

previousMillis = 0;

}

void Update(unsigned long currentMillis)

{

if((ledState == HIGH) && (currentMillis - previousMillis 》= OnTime))

{

ledState = LOW; // Turn it off

previousMillis = currentMillis; // Remember the time

digitalWrite(ledPin, ledState); // Update the actual LED

}

else if ((ledState == LOW) && (currentMillis - previousMillis 》= OffTime))

{

ledState = HIGH; // turn it on

previousMillis = currentMillis; // Remember the time

digitalWrite(ledPin, ledState); // Update the actual LED

}

}

};

class Sweeper

{

Servo servo; // the servo

int pos; // current servo position

int increment; // increment to move for each interval

int updateInterval; // interval between updates

unsigned long lastUpdate; // last update of position

public:

Sweeper(int interval)

{

updateInterval = interval;

increment = 1;

}

void Attach(int pin)

{

servo.attach(pin);

}

void Detach()

{

servo.detach();

}

void Update(unsigned long currentMillis)

{

if((currentMillis - lastUpdate) 》 updateInterval) // time to update

{

lastUpdate = millis();

pos += increment;

servo.write(pos);

if ((pos 》= 180) || (pos 《= 0)) // end of sweep

{

// reverse direction

increment = -increment;

}

}

}

};

Flasher led1(11, 123, 400);

Flasher led2(12, 350, 350);

Flasher led3(13, 200, 222);

Sweeper sweeper1(25);

Sweeper sweeper2(35);

void setup()

{

sweeper1.Attach(9);

sweeper2.Attach(10);

// Timer0 is already used for millis() - we‘ll just interrupt somewhere

// in the middle and call the “Compare A” function below

OCR0A = 0xAF;

TIMSK0 |= _BV(OCIE0A);

}

// Interrupt is called once a millisecond, to update the LEDs

// Sweeper2 s not updated if the button on digital 2 is pressed.

SIGNAL(TIMER0_COMPA_vect)

{

unsigned long currentMillis = millis();

sweeper1.Update(currentMillis);

if(digitalRead(2) == HIGH)

{

sweeper2.Update(currentMillis);

led1.Update(currentMillis);

}

led2.Update(currentMillis);

led3.Update(currentMillis);

}

void loop()

{

} #include

class Flasher

{

// Class Member Variables

// These are initialized at startup

int ledPin; // the number of the LED pin

long OnTime; // milliseconds of on-time

long OffTime; // milliseconds of off-time

// These maintain the current state

int ledState; // ledState used to set the LED

unsigned long previousMillis; // will store last time LED was updated

// Constructor - creates a Flasher

// and initializes the member variables and state

public:

Flasher(int pin, long on, long off)

{

ledPin = pin;

pinMode(ledPin, OUTPUT);

OnTime = on;

OffTime = off;

ledState = LOW;

previousMillis = 0;

}

void Update(unsigned long currentMillis)

{

if((ledState == HIGH) && (currentMillis - previousMillis 》= OnTime))

{

ledState = LOW; // Turn it off

previousMillis = currentMillis; // Remember the time

digitalWrite(ledPin, ledState); // Update the actual LED

}

else if ((ledState == LOW) && (currentMillis - previousMillis 》= OffTime))

{

ledState = HIGH; // turn it on

previousMillis = currentMillis; // Remember the time

digitalWrite(ledPin, ledState); // Update the actual LED

}

}

};

class Sweeper

{

Servo servo; // the servo

int pos; // current servo position

int increment; // increment to move for each interval

int updateInterval; // interval between updates

unsigned long lastUpdate; // last update of position

public:

Sweeper(int interval)

{

updateInterval = interval;

increment = 1;

}

void Attach(int pin)

{

servo.attach(pin);

}

void Detach()

{

servo.detach();

}

void Update(unsigned long currentMillis)

{

if((currentMillis - lastUpdate) 》 updateInterval) // time to update

{

lastUpdate = millis();

pos += increment;

servo.write(pos);

if ((pos 》= 180) || (pos 《= 0)) // end of sweep

{

// reverse direction

increment = -increment;

}

}

}

};

Flasher led1(11, 123, 400);

Flasher led2(12, 350, 350);

Flasher led3(13, 200, 222);

Sweeper sweeper1(25);

Sweeper sweeper2(35);

void setup()

{

sweeper1.Attach(9);

sweeper2.Attach(10);

// Timer0 is already used for millis() - we’ll just interrupt somewhere

// in the middle and call the “Compare A” function below

OCR0A = 0xAF;

TIMSK0 |= _BV(OCIE0A);

}

// Interrupt is called once a millisecond, to update the LEDs

// Sweeper2 s not updated if the button on digital 2 is pressed.

SIGNAL(TIMER0_COMPA_vect)

{

unsigned long currentMillis = millis();

sweeper1.Update(currentMillis);

if(digitalRead(2) == HIGH)

{

sweeper2.Update(currentMillis);

led1.Update(currentMillis);

}

led2.Update(currentMillis);

led3.Update(currentMillis);

}

void loop()

{

}

外部中斷

最好是退出循環(huán)

與定時器中斷不同的是,外部事件會觸發(fā)外部中斷。例如,當(dāng)按下按鈕或從旋轉(zhuǎn)編碼器接收到脈沖時。但是,就像計(jì)時器中斷一樣,您不需要繼續(xù)輪詢GPIO引腳以進(jìn)行更改。

Arduino UNO有2個外部中斷引腳。在此示例中,我們將按鈕附加到其中一個按鈕,并使用它來重置我們的清掃器。首先,在我們的清除程序類中添加一個“ reset()”函數(shù)。 reset()函數(shù)將位置設(shè)置為0,并立即將伺服器放置在此處:

下載:文件

復(fù)制代碼

void reset()

{

pos = 0;

servo.write(pos);

increment = abs(increment);

} void reset()

{

pos = 0;

servo.write(pos);

increment = abs(increment);

}

接下來,我們將添加對AttachInterrupt()的調(diào)用以連接外部中斷

在UNO上,中斷0與數(shù)字引腳2相關(guān)聯(lián)。我們告訴它在該引腳上尋找信號的“ FALLING”沿。當(dāng)按下按鈕時,信號從HIGH降到LOW,并調(diào)用“重置”中斷處理程序。

下載:文件

復(fù)制代碼

pinMode(2, INPUT_PULLUP);

attachInterrupt(0, Reset, FALLING); pinMode(2, INPUT_PULLUP);

attachInterrupt(0, Reset, FALLING);

這是“重置”中斷處理程序。它僅調(diào)用清除程序重置功能:

下載:文件

復(fù)制代碼

void Reset()

{

sweeper1.reset();

sweeper2.reset();

} void Reset()

{

sweeper1.reset();

sweeper2.reset();

}

現(xiàn)在,每當(dāng)您按下按鈕時,伺服器就會停止其正在執(zhí)行的操作,并立即尋找到零位置。

源代碼:

這是帶有計(jì)時器和外部中斷的完整草圖:

下載:文件

復(fù)制代碼

#include

class Flasher

{

// Class Member Variables

// These are initialized at startup

int ledPin; // the number of the LED pin

long OnTime; // milliseconds of on-time

long OffTime; // milliseconds of off-time

// These maintain the current state

volatile int ledState; // ledState used to set the LED

volatile unsigned long previousMillis; // will store last time LED was updated

// Constructor - creates a Flasher

// and initializes the member variables and state

public:

Flasher(int pin, long on, long off)

{

ledPin = pin;

pinMode(ledPin, OUTPUT);

OnTime = on;

OffTime = off;

ledState = LOW;

previousMillis = 0;

}

void Update(unsigned long currentMillis)

{

if((ledState == HIGH) && (currentMillis - previousMillis 》= OnTime))

{

ledState = LOW; // Turn it off

previousMillis = currentMillis; // Remember the time

digitalWrite(ledPin, ledState); // Update the actual LED

}

else if ((ledState == LOW) && (currentMillis - previousMillis 》= OffTime))

{

ledState = HIGH; // turn it on

previousMillis = currentMillis; // Remember the time

digitalWrite(ledPin, ledState); // Update the actual LED

}

}

};

class Sweeper

{

Servo servo; // the servo

int updateInterval; // interval between updates

volatile int pos; // current servo position

volatile unsigned long lastUpdate; // last update of position

volatile int increment; // increment to move for each interval

public:

Sweeper(int interval)

{

updateInterval = interval;

increment = 1;

}

void Attach(int pin)

{

servo.attach(pin);

}

void Detach()

{

servo.detach();

}

void reset()

{

pos = 0;

servo.write(pos);

increment = abs(increment);

}

void Update(unsigned long currentMillis)

{

if((currentMillis - lastUpdate) 》 updateInterval) // time to update

{

lastUpdate = currentMillis;

pos += increment;

servo.write(pos);

if ((pos 》= 180) || (pos 《= 0)) // end of sweep

{

// reverse direction

increment = -increment;

}

}

}

};

Flasher led1(11, 123, 400);

Flasher led2(12, 350, 350);

Flasher led3(13, 200, 222);

Sweeper sweeper1(25);

Sweeper sweeper2(35);

void setup()

{

sweeper1.Attach(9);

sweeper2.Attach(10);

// Timer0 is already used for millis() - we‘ll just interrupt somewhere

// in the middle and call the “Compare A” function below

OCR0A = 0xAF;

TIMSK0 |= _BV(OCIE0A);

pinMode(2, INPUT_PULLUP);

attachInterrupt(0, Reset, FALLING);

}

void Reset()

{

sweeper1.reset();

sweeper2.reset();

}

// Interrupt is called once a millisecond,

SIGNAL(TIMER0_COMPA_vect)

{

unsigned long currentMillis = millis();

sweeper1.Update(currentMillis);

//if(digitalRead(2) == HIGH)

{

sweeper2.Update(currentMillis);

led1.Update(currentMillis);

}

led2.Update(currentMillis);

led3.Update(currentMillis);

}

void loop()

{

} #include

class Flasher

{

// Class Member Variables

// These are initialized at startup

int ledPin; // the number of the LED pin

long OnTime; // milliseconds of on-time

long OffTime; // milliseconds of off-time

// These maintain the current state

volatile int ledState; // ledState used to set the LED

volatile unsigned long previousMillis; // will store last time LED was updated

// Constructor - creates a Flasher

// and initializes the member variables and state

public:

Flasher(int pin, long on, long off)

{

ledPin = pin;

pinMode(ledPin, OUTPUT);

OnTime = on;

OffTime = off;

ledState = LOW;

previousMillis = 0;

}

void Update(unsigned long currentMillis)

{

if((ledState == HIGH) && (currentMillis - previousMillis 》= OnTime))

{

ledState = LOW; // Turn it off

previousMillis = currentMillis; // Remember the time

digitalWrite(ledPin, ledState); // Update the actual LED

}

else if ((ledState == LOW) && (currentMillis - previousMillis 》= OffTime))

{

ledState = HIGH; // turn it on

previousMillis = currentMillis; // Remember the time

digitalWrite(ledPin, ledState); // Update the actual LED

}

}

};

class Sweeper

{

Servo servo; // the servo

int updateInterval; // interval between updates

volatile int pos; // current servo position

volatile unsigned long lastUpdate; // last update of position

volatile int increment; // increment to move for each interval

public:

Sweeper(int interval)

{

updateInterval = interval;

increment = 1;

}

void Attach(int pin)

{

servo.attach(pin);

}

void Detach()

{

servo.detach();

}

void reset()

{

pos = 0;

servo.write(pos);

increment = abs(increment);

}

void Update(unsigned long currentMillis)

{

if((currentMillis - lastUpdate) 》 updateInterval) // time to update

{

lastUpdate = currentMillis;

pos += increment;

servo.write(pos);

if ((pos 》= 180) || (pos 《= 0)) // end of sweep

{

// reverse direction

increment = -increment;

}

}

}

};

Flasher led1(11, 123, 400);

Flasher led2(12, 350, 350);

Flasher led3(13, 200, 222);

Sweeper sweeper1(25);

Sweeper sweeper2(35);

void setup()

{

sweeper1.Attach(9);

sweeper2.Attach(10);

// Timer0 is already used for millis() - we’ll just interrupt somewhere

// in the middle and call the “Compare A” function below

OCR0A = 0xAF;

TIMSK0 |= _BV(OCIE0A);

pinMode(2, INPUT_PULLUP);

attachInterrupt(0, Reset, FALLING);

}

void Reset()

{

sweeper1.reset();

sweeper2.reset();

}

// Interrupt is called once a millisecond,

SIGNAL(TIMER0_COMPA_vect)

{

unsigned long currentMillis = millis();

sweeper1.Update(currentMillis);

//if(digitalRead(2) == HIGH)

{

sweeper2.Update(currentMillis);

led1.Update(currentMillis);

}

led2.Update(currentMillis);

led3.Update(currentMillis);

}

void loop()

{

}

庫和鏈接

有關(guān)計(jì)時器的更多信息

可以將計(jì)時器配置為以各種頻率運(yùn)行并以不同的模式運(yùn)行。除了產(chǎn)生中斷,它們還用于控制PWM引腳。以下鏈接是了解如何配置和使用計(jì)時器的出色資源:

Arduino PWM的機(jī)密

計(jì)時器/PWM速查表

計(jì)時器庫

網(wǎng)上有許多Arduino``計(jì)時器‘’庫可用與本系列第1部分中所做的一樣,許多人僅監(jiān)視millis()并要求進(jìn)行持續(xù)輪詢。但是實(shí)際上有一些配置可以讓您配置定時器以生成中斷。

Paul Stoffregan出色的TimerOne和TimerThree庫處理了許多定時器中斷配置的低級細(xì)節(jié)。 (請注意,TimerThree不適用于UNO。它可以與Leonardo,Mega和某些Teensy板一起使用)

TimerOne和Timer 3庫

引腳更改中斷

對于2個不足的情況

Arduino UNO只有2個外部中斷引腳。但是,如果您需要兩個以上的中斷,該怎么辦?幸運(yùn)的是,Arduino UNO在所有引腳上都支持“引腳更改”中斷。

引腳更改中斷類似于外部中斷。區(qū)別在于,在8個相關(guān)引腳中的任何一個引腳上都會因狀態(tài)變化而產(chǎn)生一個中斷。這些操作要稍微復(fù)雜一點(diǎn),因?yàn)槟仨毟櫵?個引腳的最后一個已知狀態(tài),以找出8個引腳中的哪個導(dǎo)致了中斷。

Arduino Playground的PinChangeInt庫實(shí)現(xiàn)了一個方便的引腳更改中斷接口:http://playground.arduino.cc/Main/PinChangeInt

PinChangeInt庫

計(jì)時器和中斷禮儀

中斷就像超市的快速通道??紤]周全,將其保持在10件以下,一切都會順利進(jìn)行。

如果一切都是高水平的,那么沒有什么是高度優(yōu)先的。

中斷處理程序應(yīng)僅用于處理高優(yōu)先級,對時間敏感的事件。請記住,在中斷處理程序中時,禁用了中斷。如果您嘗試在中斷級別執(zhí)行過多操作,則會降低對其他中斷的響應(yīng)。

一次僅一個中斷。

ISR,中斷被禁用。這有兩個非常重要的含義:

在ISR中完成的工作應(yīng)保持簡短,以免丟失任何中斷。

在ISR中的代碼不應(yīng)調(diào)用任何需要激活中斷(例如delay()或使用i2c總線的任何中斷)。這將導(dǎo)致程序掛起。

將冗長的處理推遲到循環(huán)中。

如果您需要進(jìn)行大量處理以響應(yīng)中斷,請使用中斷處理程序僅執(zhí)行必要的操作,然后設(shè)置易失性狀態(tài)變量(參見下文)以指示需要進(jìn)一步處理。當(dāng)您從循環(huán)中調(diào)用更新功能時,請檢查狀態(tài)變量以查看是否需要任何后續(xù)處理。

重新配置計(jì)時器之前需要檢查 《計(jì)時器是一種有限的資源。 UNO上只有3個,它們用于許多用途。如果您弄亂了計(jì)時器配置,則其他某些功能可能不再起作用。例如,在Arduino UNO上:

Timer0 -用于引腳5和6上的millis(),micros(),delay()和PWM

Timer1 -用于Servos,WaveHC庫和引腳9和10上的PWM

Timer2 -由Tone和PWM引腳上使用11&13

安全共享數(shù)據(jù)

因?yàn)橹袛鄬和?,無論處理器正在處理該中斷如何,我們必須小心在中斷處理程序和循環(huán)中的代碼之間共享數(shù)據(jù)。

易失性變量

有時,編譯器會嘗試優(yōu)化代碼以提高速度。有時,這些優(yōu)化會將常用變量的副本保留在寄存器中以便快速訪問。問題是,如果這些變量之一在中斷處理程序和循環(huán)代碼之間共享,則其中一個變量最終可能會查看陳舊的副本而不是真實(shí)的副本。將變量標(biāo)記為易失性會告訴編譯器不要對優(yōu)化進(jìn)行潛在的危險操作。

保護(hù)較大的變量

Evan標(biāo)記變量 volatile 是不夠的如果它的變量大于整數(shù)(例如字符串,數(shù)組,結(jié)構(gòu)等)。較大的變量需要幾個指令周期來更新,并且如果在更新的中間發(fā)生中斷,則數(shù)據(jù)可能會被破壞。如果您具有與中斷處理程序共享的較大變量或結(jié)構(gòu),則在從循環(huán)中更新中斷時應(yīng)禁用中斷。 (默認(rèn)情況下,已在中斷處理程序中禁用了中斷。)
責(zé)任編輯:wv

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 中斷
    +關(guān)注

    關(guān)注

    5

    文章

    918

    瀏覽量

    43800
  • 計(jì)時器
    +關(guān)注

    關(guān)注

    1

    文章

    434

    瀏覽量

    35239
  • Arduino
    +關(guān)注

    關(guān)注

    190

    文章

    6526

    瀏覽量

    197081
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點(diǎn)推薦

    漏電流檢測:充電樁安全中那道看不見的防線

    從充電樁“跳閘”說起去年冬天,南方某地座公共充電站出現(xiàn)種奇怪的充電中斷故障。后臺顯示故障原因是漏電保護(hù)動作。經(jīng)運(yùn)維人員現(xiàn)場檢查,充電樁絕緣一切正常,換
    的頭像 發(fā)表于 02-28 08:56 ?287次閱讀
    漏電流檢測:充電樁安全中那道看不見的防線

    CW32L083 IAP跳轉(zhuǎn)后中斷無響應(yīng)是什么原因?

    最近做個項(xiàng)目,需要IAP。按照官方的教程一切順利,軟件APP跳轉(zhuǎn)一切正常,但是跳轉(zhuǎn)后中斷沒有響應(yīng)。搜索了堆資料,APP在mian中找開了
    發(fā)表于 12-09 07:19

    從“車找電”到“電找車”:有源晶振,憑什么成為系統(tǒng)的節(jié)拍核心?

    能源補(bǔ)給、機(jī)器人、汽車……表面上不同,其實(shí)都樣:想順暢運(yùn)轉(zhuǎn),需要穩(wěn)定;想穩(wěn)定,需要時間。SJK?晶振就像看不見的指揮棒,讓一切保持節(jié)奏。
    的頭像 發(fā)表于 11-21 14:31 ?1549次閱讀
    從“車找電”到“電找車”:有源晶振,憑什么成為系統(tǒng)的節(jié)拍核心?

    MCU的嵌入式開發(fā)

    ); 當(dāng)軟件中斷外部中斷計(jì)時器中斷同時發(fā)生 外部中斷優(yōu)先級最高 軟件中斷其次
    發(fā)表于 10-28 08:02

    耐電痕化指數(shù)測定儀:滴液計(jì)時器設(shè)置與終點(diǎn)判據(jù)的深度解讀

    、滴液計(jì)時器:模擬環(huán)境的“節(jié)奏控制”? 耐電痕化測試的核心是復(fù)刻絕緣材料在潮濕污染環(huán)境中的劣化過程,滴液計(jì)時器則是把控這過程節(jié)奏的關(guān)鍵
    的頭像 發(fā)表于 10-16 09:46 ?366次閱讀
    耐電痕化指數(shù)測定儀:滴液<b class='flag-5'>計(jì)時器</b>設(shè)置與終點(diǎn)判據(jù)的深度解讀

    UART在freertos中斷時不接收數(shù)據(jù),怎么解決?

    我使用帶有 freeRTOS 的 nuvoton M453 mcu,一切都工作正常,除了 UART 在中斷時沒有接收數(shù)據(jù)意味著中斷沒有觸發(fā),但我在沒有 RTOS 代碼的情況下也是如此,
    發(fā)表于 08-15 06:44

    使用aicube進(jìn)行目標(biāo)檢測識別數(shù)字項(xiàng)目的時候,在評估環(huán)節(jié)卡住了,怎么解決?

    使用aicube進(jìn)行目標(biāo)檢測識別數(shù)字項(xiàng)目的時候,前面一切正常 但是在評估環(huán)節(jié)卡住了,直顯示正在測試,但是完全沒有測試結(jié)果, 在部署完模型后在k230上運(yùn)行也沒有任何識別結(jié)果 期待結(jié)果和實(shí)際結(jié)果
    發(fā)表于 08-13 06:45

    賽思高保持小型時鐘模塊:精確時間的守護(hù)者

    在我們的日常生活中,時間是一切的基礎(chǔ)。無論是工作、學(xué)習(xí)還是生活,我們都需要依賴于時間規(guī)劃和安排。而在這個快節(jié)奏的社會中,如何準(zhǔn)確地掌握時間成為了我們必須面對的問題。這時,高保持小型時鐘模塊應(yīng)運(yùn)而生
    的頭像 發(fā)表于 07-22 14:37 ?473次閱讀
    賽思高<b class='flag-5'>保持</b>小型時鐘模塊:精確時間的守護(hù)者

    零知開源——基于STM32F407VET6零知增強(qiáng)板的四路獨(dú)立計(jì)時器

    本帖最后由 PCB56242069 于 2025-7-1 11:24 編輯 項(xiàng)目概述本教程將指導(dǎo)你如何使用STM32F407VET6零知增強(qiáng)板實(shí)現(xiàn)個功能強(qiáng)大的四路獨(dú)立計(jì)時器。每個計(jì)時器可以
    發(fā)表于 07-01 10:31

    零知開源——基于STM32F407VET6零知增強(qiáng)板的四路獨(dú)立計(jì)時器

    本教程介紹基于STM32F407VET6零知增強(qiáng)板的四路獨(dú)立計(jì)時器實(shí)現(xiàn)方案。項(xiàng)目采用TFT顯示屏、蜂鳴器和按鈕構(gòu)建交互系統(tǒng),支持各計(jì)時器獨(dú)立控制(開始/暫停/重置)和智能報警(4小時及以上每小時觸發(fā)
    的頭像 發(fā)表于 07-01 10:13 ?1215次閱讀
    零知開源——基于STM32F407VET6零知增強(qiáng)板的四路獨(dú)立<b class='flag-5'>計(jì)時器</b>

    基于STM32F407VET6零知增強(qiáng)板的四路獨(dú)立計(jì)時器

    計(jì)時器
    PCB56242069
    發(fā)布于 :2025年07月01日 09:41:44

    納祥科技客戶案例 | 集計(jì)時、照明、裝飾于體的電子沙漏計(jì)時器方案

    傳統(tǒng)沙漏作為計(jì)時工具,雖具備儀式感,但存在功能單、無法實(shí)時調(diào)整具體定時等局限性。應(yīng)客戶需求,納祥科技推出了結(jié)合LED顯示、重力感應(yīng)、低功耗等技術(shù)的電子沙漏計(jì)時器方案,實(shí)現(xiàn)傳統(tǒng)沙漏的美學(xué)與現(xiàn)代
    的頭像 發(fā)表于 06-13 16:32 ?903次閱讀
    納祥科技客戶案例 | 集<b class='flag-5'>計(jì)時</b>、照明、裝飾于<b class='flag-5'>一</b>體的電子沙漏<b class='flag-5'>計(jì)時器</b>方案

    攝像頭傳感無法通過CX3進(jìn)行直播怎么解決?

    印框架。 但是,在計(jì)算機(jī)上打開的 gstreamer 窗口顯示為黑色,沒有圖像。 當(dāng)我用示波器查看 CX3 上的 PCLK、HSYNC、VSYNC 引腳時,我發(fā)現(xiàn)一切正常。 我在下面添加了 UART 的幀信息輸出。 有人對為什么會這樣有建議嗎?
    發(fā)表于 05-27 06:54

    有辦法讓SDK 1.3.5與JTAG調(diào)試配合使用嗎?

    其切換到 FX3 SDK 1.3.4,則一切正常。 看來 SDK 1.3.5 中的預(yù)置庫出了問題,因?yàn)檫@是唯真正發(fā)生變化的地方。 有辦法讓 SDK 1.3.5 與 JTAG 調(diào)試配合使用嗎?
    發(fā)表于 05-23 07:32

    模塊電源保持電容計(jì)算方式

    保持電容的容量可依據(jù)輸出直流電壓的紋波、電源中斷保持時間和過渡時間計(jì)算確定,如圖1所示。許多應(yīng)用中,輸入電壓中斷定時間時,要求電源
    的頭像 發(fā)表于 05-14 13:54 ?2.2w次閱讀
    模塊電源<b class='flag-5'>保持</b>電容計(jì)算方式