Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Unable to understand the code with repect to LED blinking when a timer expires

Status
Not open for further replies.

phanideepak007

New Member
I am working on a Project . I am in a situation where i have to edit code which has no documentation. I am unable to understand a concept which the code claims to be.

// Prototype code
// internal clock running at 10MHZ

#define ERROR1 500 // frequency of the LED flashing on error1 (f=1Hz)
#define ERROR2 100 // frequency of the LED flashing on error2 (f=5Hz)

//To turn on millisec timer assign a value and timer will run for specified amount of time

mtimer failure // declaring failure as a millisectimer .

if (i==1)
failure = ERROR1;

if(i==2)
failure = ERROR2;

if(//failure expires)
{
blink green led;
blink red led;

}

Q1) Why frequency of LED blinking is given 1HZ and 5 HZ repectively.?
Q2) How led is able to blink with those frequencies while the code is executed only after timer is expired..?
 
im sorry,i cannot post the code but i can help you understand . i almost need yes or no kind of answer.. i have less experience in working with mc's so i have less idea on their behavior. The neuron firmware supports many inbuilt functions.one of them is like you can declare a timer as i did above and this name starts the timer for the specified length of time when time is loaded. So when 500 is loaded the timer starts and when it expires the if condition (failure expires)executes but the code claims that when its loaded 500ms it not only executes the (failure expires)but also blinks led with 1hz and same when loaded with 100ms but it blinks led with 5hz.. the effect of timer is still there even after its expired ..??? if so, it should be 2hz with 500ms and 10z with 100ms... or what i assumed is wrong..??
 
Looks to me as though 100 sets the LED 'on' time, in msec, for a 5Hz blink. There will likewise be a 100 msec 'off' time.
Similarly, for a 1Hz blink there will be a 500msec 'on' time and a 500msec 'off' time.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top