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.

Functions needed for ATmega644

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Joined
Dec 4, 2011
Messages
817
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Activity points
6,492
Please let me know that what is the working of given below functions and how to make it or where I find its functions

void init_mcu(void);
void debounce_machine(void);



//Debounce State Machine Variables
unsigned char maybe, PushState;
unsigned char button_pressed, button_mask;



I have program I downloaded from google search but its missing two functions only prototype is given.
 
Last edited:

The following appears to be a typical button/switch debouncing routine:

Code:
void debounce_machine(void);


//Debounce State Machine Variables
unsigned char maybe, PushState;
unsigned char button_pressed, button_mask;

The following routine is most likely a typically initialization routine for the device:

Code:
void init_mcu(void);

Configure the oscillator, PORT pin direction, any peripheral modules, etc.

You should be able to implement your own routines in place of the missing code without too much difficultly.

If you post the entire code, we should be able to give you more insight into what routines you'll need to implement.

BigDog
 
Please find the attachment file I attached the full code.
 

Attachments

  • ELM327.txt
    34.9 KB · Views: 39

It appears the routine:

Code:
void init_mcu(void);

Exists only as a function prototype and is neither implement nor call in the remainder of the code.

It appears to have been replace by the following routine:

Code:
void initialize(void){
	rx_buffer_index = 0;
	DDRD = 0xFF;
	PORTD = 0xFF;

	//init pushbuttonsf
	DDRA = 0xF0;
	PushState = Release;

	init_uart0_rxtx();		// Initialize UART TX
	init_lcd();

	state = St_Initial;
	mph = 0;
	rpm = 0;
	mpg = 0;
	kph = 0;
	kpl = 0;
	temp_rpm1 = 0;
	temp_rpm2 = 0;
	maf = 0;
	temperature = 0;
	milli_temp = 0;
	seconds = 0;
	about_flag = 0;

	menu = 1;
	menu_cursor = 1;
	button_pressed = 0;
	metric_flag = 0;
	trial_flag = 0;
	timeOn = 0;
	button_timer = 0;

	// set up timer 0     
  	OCR0A = 249;	   			// clear after 250 counts
  	TIMSK0 = (1<<OCIE0A) ;	//turn on timer 0 cmp-match ISR 

  	// turn on timer 0 clear on match
  	TCCR0A = (1<<WGM01) ;
  	// timer 0 prescalar to 64 
  	TCCR0B = 3 ;	

	sei();
}

Which you may or may not need to modify depending on the actual model of AVR utilized.

The same applies to the debouncing routine as it exists only as a function prototype and is not utilized in the remainder of the code.

The debouncing scheme appears to have been incorporated into other sections of the code.


BigDog
 
But in Proteus 7.8 simulation the buttons connect to PORTA (A0-A3) did not work what should it cause please let me know.
 

The debounce scheme appears to be primarily handled by the use of TMR0, its associated ISR and code located in the Superloop of main():

Code:
//timer 0 overflow ISR
ISR (TIMER0_COMPA_vect){
   if(timeOn == 1){
	milliseconds++;
		if(milliseconds%1000 == 0){
			seconds = seconds + 1;
			milliseconds = 0;
			}
	}
	if (button_timer != 0)
		button_timer--;
}

/**
 * Main program
 */
int main(void) {
	initialize();
	// Main program loop
	while(1) {
		if ((button_timer == 0) && (PINA != 15)){
			button_pressed = PINA;
			button_timer = 0;
			}
		else 
			button_pressed = 15;
		state_machine();
	}
}

A button closure triggers the debounce scheme after which the value of specific button pressed, on PORTA, is loaded into the state variable button_pressed before execution is passed to the state machine.

I would suggest starting with the debounce scheme and replacing the state machine with some method of reporting the specific button pressed.

Perhaps the TMR0 is not being configured properly or your PORTA is not be properly initialized for your specific AVR.

You could always temporarily disable the debounce scheme and see if any button closures are detected.

BigDog
 

But thing I read in project page is that "When the device is first powered, an initialization sequence takes place, as shown by the node 'power off'. The first command, echo off (refer to table for details on command), disables the ELM327 from echoing back the received characters to the host, the ATmega644. The power up splash screen shown below is completed after requesting the version identification from the ELM327. The screen is held for two seconds, and forwarded to the main menu. "

I think after connection to ELM327 the buttons would active.

- - - Updated - - -

I disabled the debounce scheme but it does not effect on any button.

Please let me know can you try to simulate and find any problem with code.
 

Well, according to main(), PORTA is first checked for any button closure, which are pulled low not high by the way, before execution is passed to the statement machine.

If none of PORTAs pins are pulled low, a button closure, the state variable is loaded with a default value of 15 or St_Rec_Mpg.

BigDog
 
I tried connect all buttons to ground with pull-up resistors of 10k but it was also no effect.

It should possible or not that buttons will active after connect to ELM327,please let me know.
 
Last edited:

Dear bigdogguru,

Please let me know about pasted function and its working.

Code:
//timer 0 overflow ISR
ISR (TIMER0_COMPA_vect){
   if(timeOn == 1){
	milliseconds++;
		if(milliseconds%1000 == 0){
			seconds = seconds + 1;
			milliseconds = 0;
			}
	}
	if (button_timer != 0)
		button_timer--;
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top