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.

speedometer and odometer combo circuit help.

Status
Not open for further replies.

david90

Advanced Member level 1
Advanced Member level 1
Joined
May 5, 2004
Messages
423
Helped
9
Reputation
18
Reaction score
4
Trophy points
1,298
Activity points
3,611
photointerrupter mcu

Here is my finished code (to me :|) This code is for WINAVR GCC compiler and it is for atmel MCU at90s2313.

Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>

void delay(void);
void display7seg(void);

volatile uint16_t pulses=0,mph=0,mph_result=0;
int hun_mi,ten_mi,one_mi,hun_mph,ten_mph,one_mph;
const char segment_table[10]=
{
   0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x2, 0x78, 0, 0x10
};

int main (void)
{
	DDRB = 0xff;// set PORTB as output
	DDRD = 0x77;
	TCCR0 = 0x03;// delay timer

	TCNT1H=0xC9;
	TCNT1L=0x85;
	TCCR1B=0x5; // clk/1024 TCCR1B=0x5; // clk/1024
	TIMSK=0x80;

	
	MCUCR=0x08;
	SREG=0x80;
	GIMSK=0x80;
	while (1) // Forever
	{
	display7seg();
	}
return 0;
}

void delay(void) //Produce a delay of 65 ms at 4 MHz
{
TCNT0=0x7F;
while (!(TIFR&0x02));
// Wait for timer0 overflow flag to be set
TIFR = 0x02; // Clear overflow flag
}
void display7seg(void)
{


hun_mi=(pulses)/100;
ten_mi=((pulses)%100)/10;
one_mi=((pulses)%100)%10;

hun_mph=(mph_result)/100;
ten_mph=((mph_result)%100)/10;
one_mph=((mph_result)%100)%10;

	PORTB=segment_table[hun_mi];
	PORTD=0x7B;
	delay();
	PORTB=segment_table[ten_mi];
	PORTD=0x7D;
	delay();
	PORTB=segment_table[one_mi];
	PORTD=0x7E;
	delay();
	
	PORTB=segment_table[hun_mph];
	PORTD=0x6F;
	delay();
	PORTB=segment_table[ten_mph];
	PORTD=0x5F;
	delay();
	PORTB=segment_table[one_mph];
	PORTD=0x3F;
	delay();
}

INTERRUPT(SIG_INTERRUPT1)
{
if (++pulses==999)
	{
		pulses=0;
	}
mph++;
}



INTERRUPT(SIG_OVERFLOW1)
{
mph_result=mph*.08863;
mph=0;
TCNT1H=0xC9;
TCNT1L=0x61;
}

The code above is for my electric scooter. The motor is attached to a slotted wheel and that wheel spins thru a photointerrupter. The circuit above is made to count those pulses to calc distance traveled (not yet finish) and mph. When I connect the mcu interrupt pin to the photointerrupter and spins the wheel with my hand, it counts very well. When I turn on the motor, my display seems to go crazy and crashes. This happen even when the MCU is not connected to the photointerrupter. I think it has to do with the EMF from the motor. Anyway, my circuit seems to count even when it is not grounded to the scooter. Lots of noise??? Can somebody give me some advice?

Added after 3 minutes:

basically i'm having a lot of false triggering and my 7segment displays go crazy.
 

This occur because of spark ignition circuit, try put the circuit far of spark plugs and if possible put your circuit in a good conductor box, with good ground. If cable of display is separated of your board use shield cable.... maybe if you add a pulldown resistor with small value in input can help you too ...

leomecma
 

It is an electric scooter not gas.

I figured it was noise so I added a cap between my + and - of power supply and another at the MCU interrupt pin and it made my circuit much more stable.

I do have another problem. The scooter has a security feature where if it took a hard hit, back wheel gets wet or the back wheel is off the ground, the scooter shuts off. When I tried to tap into the photointerrupt, for some reason the scooter shuts off when it gets to certain speed. I figured the MCU interrupt pin must be load down the photointerrupter and pulling it down to ground or something.

Update: to my suprise the scooter shuts off even if i touch a plain wire not connected to anything else to the photointerrupter output. Can somebody explain what is happening? I don't think i'm shorting anything.
 

what are some ways I can keep em wave produced by motors out of my circuit?
 

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top