simulation behaves unexpected-motor control

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

this is the continuation of my previous post motor switching control.
i write a code in avr studio4.
i load the hex file into proteus isis professional 7.6
but the o/p of lcd is unexpected.
wasting so much time to debug the problem,but no use
i attached the full files below.
please help

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My copy of ark (Linux archive extractor) says that .rar is corrupt.

Anyway all I was going to check was which standard LCD library it is you are trying to use. Perhaps you can just say?

Also how sure are you that any fault in simulation is not simply a fault in the simulator itself?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Also how sure are you that any fault in simulation is not simply a fault in the simulator itself?

no , error can be occur due to the error in program logic

the lcd code i used is from exteemelectronics.com

i just re attach the post again

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try the LCD code that came with your C compiler:

http://www.nongnu.org/avr-libc/u...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Try the LCD code that came with your C compiler:

http://www.nongnu.org/avr-libc/u... ... odemo.html


yes i will try

but i feel the below attached is more easy to use for a beginer like me.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

below attached is more easy to use for a beginer like me.

Not if it doesn't work.

As JFK almost once said:

Quote:
We choose to use the AVR-LibC LCD code. We choose to use the AVR-LibC LCD code in this project and do the other things, not because they are easy, but because they are hard

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

my 1 sec timer is r is as follows

ISR ( TIMER1_COMPA_vect )
{
	if((clock_minute==00)&&(clock_second==00))
	{
		clock_hour--;
	}
	
	clock_second--;
	
	if(clock_second==00)
	{
		clock_minute--;
		clock_second=59;
	}
	if(clock_minute==00)
	{
		clock_hour--;
		clock_minute=59;	
	}
	if((clock_hour==00)&&(clock_minute==00)&&(clock_second==00))
	{
		change_motor();
	}
		
		
	

but when the sec reaches 0, it restart from 99 instead of 59

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So what happens when clock_second is zero and you do clock_second-- ?

Do you think it changes to 59?

Suggest you trace, with a pencil and paper, what your code does for different values of clock_xxx values...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MartinM57

are you simulate my code
i already atttach the complete simulation files(proteus)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no one interested in lcd program

i just put down the full code here.
the problem is
for testing i put 2 min as timer value
it start as i expected

Quote:
Motor Change in
00:01:59

but when second comes to 0 then
it shows like below
Quote:
Motor Change in
55:00:59

and count down.

icant find out the problem.
plz help.

#include "template.h"
#include "lcd.h"

char n;
volatile char  clock_second;
volatile char  clock_minute=2;
volatile char  clock_hour;

void init_ports(void)
{
	//motor ports
	OUT(C,0);
	OUT(C,1);
	OUT(C,2);
	OUT(C,3);
	//button
	IN(B,0);
	IN(B,1);
}

void motor_off(void)
{
	CLR(C,0);
	CLR(C,1);
	CLR(C,2);
	CLR(C,3);
}

void init_timer(void)
{
	TCCR1B |= (1 << WGM12 ); // Configure timer 1 for CTC mode
	TIMSK1 |= (1 << OCIE1A ); // Enable CTC interrupt
	OCR1A = 15624; // Set CTC compare value to 1Hz at 1 MHz AVR clock , with a prescaler of 64
	TCCR1B |= ((1 << CS10 ) | (1 << CS11 )); // Start timer at Fcpu /64
}

void start_motor(void)
{
	switch(n)
	{
		case 0:
			SET(C,0);
			break;
		case 1:
			SET(C,1);
			break;
		case 2:
			SET(C,2);
			break;
		case 3:
			SET(C,3);
			break;
	}
}


//Change Motor
void change_motor(void)
{
	switch(n)
	{
		case 0:
			CLR(C,0);
			SET(C,1);
			n++;
			break;
		case 1:
			CLR(C,1);
			SET(C,2);
			n++;
			break;
		case 2:
			CLR(C,2);
			SET(C,3);
			n++;
			break;
		case 3:
			CLR(C,3);
			SET(C,0);
			n=0;
			break;
	}
}
//LCD Display function
void show_lcd_hour(void)
{
	LCDWriteIntXY(4,1,clock_hour,2);
	LCDWriteString(":");
}	
void show_lcd_minute(void)
{
	LCDWriteIntXY(7,1,clock_minute,2);
	LCDWriteString(":");
}
void show_lcd_second(void)
{	
	LCDWriteIntXY(10,1,clock_second,2);
}

void initial_lcd_show(void)
{
	clock_second=59;
	if((clock_minute==0)&&(clock_second==0))
	{
		clock_hour--;
	}
	clock_minute--;
	show_lcd_hour();
	show_lcd_minute();
	show_lcd_second();
}

ISR ( TIMER1_COMPA_vect )
{
	clock_second--;

	if((clock_hour==0)&&(clock_minute==0)&&(clock_second==0))
	{
		change_motor();
		cli;
	}
	
	show_lcd_second();
	if(clock_second==-1)
	{
		clock_minute--;
		clock_second=59;
		show_lcd_minute();
		if(clock_minute==-1)
		{
			clock_hour--;
			clock_minute=59;
			show_lcd_hour();			
		}
		
	}
	
	
}

void main()
{
	unsigned char i;
	//Initialize LCD module
	InitLCD(LS_BLINK|LS_ULINE);
	//Clear the screen
	LCDClear();
	//Simple string printing
	LCDWriteString("    Welcome   ");
	//A string on line 2
	LCDWriteStringXY(0,1,"Loading ");
	 //Print some numbers
	for (i=0;i<100;i+=1)
	{
		  LCDWriteIntXY(9,1,i,3);
		  LCDWriteStringXY(12,1," % ");
		  _delay_ms(100);
	}
	LCDClear();
	LCDWriteString("     Start    ");
	LCDWriteStringXY(0,1,"  Motor Timer  ");
	
	init_ports();
	motor_off();
	init_timer();
	sei();
	start_motor();
	LCDClear();
	LCDWriteString(" Motor Change in");
	initial_lcd_show();
	while(1)
	{
		
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why dont you just countdown seconds. If you need to display the time, then convert the seconds into hours,mins and secs. Your code will be much simpler.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kartman

thanks for your idea.I already think about that. but i need to put an option to setting the time using push button.i didnt write code for that.
didnt you see my schematic in the attachment.