Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Need Help: Problem with time slicing avr

Status
Not open for further replies.
I've also debug it in proteus. When ADC value is decreased below the predetermined valeu, x,y,z are equal to 0. Is this causing the pulse gone?

Any other suggestions?
 
you have
Code:
if(x >= 1)
        {
            x = x - 1;
        }

so when x=1 it can become 0.

Maybe you intended
Code:
if(x > 1)
        {
            x = x - 1;
        }
 

Ok it's working now but not for a long time. It operates as what I want but not more than about 3 minutes. After that, the pulses are appear together at once in every two seconds (around two seconds).
 
Here it is:
 

Attachments

  • Sat.zip
    86.4 KB · Views: 72
No, it should work continuously as long as the MCU is ON. I just let it works and do not touch anything, but somehow after around 3 seconds, everything goes abnormally.
 
Sorry, 3 minutes. And they are appear once every 2~3 seconds.
Do you know what's wrong?
 
x,y,z are all used in both main and interrupt, make them volatile

Code:
volatile unsigned int x = 0;
volatile unsigned int y = 0;
volatile unsigned int z = 0;

There may also be a problem if main is interrupted at the wrong time, for example

Code:
if((PORTB.0 == 1) && (ldr1 <= 300))   [B]// [COLOR="#FF0000"]suppose that when this line is executed PORTB.0 = 1 so the condition is true[/COLOR][/B]
        {      [B] // [COLOR="#FF0000"]in this line you may get an interrupt and set  PORTB.0 = 0 so now when you return here the following line will execute although it shouldn't and can mess things up[/COLOR] [/B]
            if(x > 1)
                {
                    x = x - 1;
                }
        }
 
Hhhhhmm I'm getting bored with this. It still works well for a short time, but not for a long time. I tried to give more delay for ADC stabilization but It does not affect anything.

Well, actually I use this code to change the firing delay of triac that control 220V 50Hz AC lamps (many lamps). Do you know any information or another methods to do this instead of time slicing?
 
Hi, Hope somebody still checking this thread.

This is the main problem that I just found. This made the hardware does not operate for a long time.

ERR.png

It will be normal again if I re-start it from the beginning.
 
Use the debug capability and run the code until it reaches the time where the problem appears , then use breakpoints and step the code to see what goes wrong
 
Yap, I debug it and get this:

res.png

Now, from here I dont know how to find the bugs
 

You have to stop it before that and see what happens when the blue line goes low and never returns high
 

Hi, please look at this:

ini.png

Maybe the problem is with the "pulse_flag"
 

I'm not sure how the variable can have a value higher than 3 when you expect a single pulse for each of x,y,z.
To get a pulse_flag higher than 3 means that one of them gave a double pulse.

Anyway use
Code:
if(pulse_flag >= 3)

- - - Updated - - -

but there is probably a cause for a value >3 and if so you should fix it
 

can I write pulse_flag = pulse_flag + 1; instead of pulse_flag++; ?
 

pulse_flag++ is the shortcut version of pulse_flag = pulse_flag + 1; , I 'm not sure what difference you expect with this change
 

On the previous picture, it says: " Item (2 bytes at 0xFFFF0504) not within memory block..."
can this be a problem too?

Also, previously:

Code:
volatile unsigned int x = 0;   // This never give me any pulse if I start with smaller adc value than the predetermined limit
volatile unsigned int y = 0;   // If I start with high adc value (higher than the predetermined limit), everything is OK
volatile unsigned int z = 0;

So I change it into:
Code:
volatile unsigned int x = 2;
volatile unsigned int y = 2;
volatile unsigned int z = 2;
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top