Page 3 of 8

Re: AVR to Arduino - VPW

Posted: Fri Mar 28, 2014 1:04 pm
by Tazzi
Not a big fan of AVR studio right this second. Only because its not a simple "paste n go" situation. Looks like I have to read up on the ATmega baud registers and compare that to the ATmega8 so that I can edit and port the code to the ATmega328. Things such as:
UBRRH = DEFAULT_BAUD>>8; // set baud rate
UBRRL = DEFAULT_BAUD;
UCSRB =((1<<RXCIE)|(1<<RXEN)|(1<<TXEN)); // enable Rx & Tx, enable Rx interrupt
UCSRC =((1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0)); // config USART; 8N1

Need to be updated to the appropriate atmega328 version.
Unless anyone can think of something Im missing, this seems to be whats needed.


*Edit
Looks like theres a few examples using the ATmega328 and baud registers.. this makes life a whoooooole lot easier

Re: AVR to Arduino - VPW

Posted: Fri Mar 28, 2014 1:33 pm
by Tazzi
These definitions should set us on course :thumbup:

Code: Select all

//defines needed for Atmega328: 
#define    UCSRA    UCSR0A 
#define    UCSRB    UCSR0B 
#define    UCSRC    UCSR0C 
#define    UBRRH    UBRR0H 
#define    UBRRL    UBRR0L 
#define    UDRE    UDRE0 
#define    UDR    UDR0 
#define    RXC    RXC0 
#define    RXEN    RXEN0 
#define    TXEN    TXEN0 
#define    UCSZ1    UCSZ01 
#define    UCSZ0    UCSZ00 
#define output_high(port,pin) port |= (1<<pin) 
#define output_low(port,pin) port &= ~(1<<pin) 
#define set_output(portdir,pin) portdir |= (1<<pin) 

#ifndef F_CPU 
   #define F_CPU 16000000UL      
#endif 

Re: AVR to Arduino - VPW

Posted: Fri Mar 28, 2014 1:48 pm
by Tazzi
8-)

I guess all thats left is to flash file using avrdude and see how we go. The pins set to analog 0 and 3 (I think). Am going to pop round jaycar now to pick up the list of requirements at the obd end:

Code: Select all

78L05 (voltage regulator) 
R1 220ohms
D1 (LED Green)
C2 0.1u capacitor(i think)
C1 100u capacitor
R2 220ohms
D2 (LED yellow)
T1 BC548A
R3 15K
R4 2.2K
R5 47K
R6 47K
R7 10K
T2 BC548A
D3 1N4148
T3 BC548A
D4 ZPD8V2
R8 47omhs
R9 510ohms
T4 BC548A
R10 1K

Re: AVR to Arduino - VPW

Posted: Fri Mar 28, 2014 6:22 pm
by ejukated
awesome work, be really keen to see how this turns out.

Re: AVR to Arduino - VPW

Posted: Fri Mar 28, 2014 7:31 pm
by Tazzi
Hopefully it does.. The coding changes have been made (which I imagine is the hardest bit) so all thats left is trial and error.

Ran out of time to pick up the gear. But I dont see why I couldnt try flashing the code to the arduino.. Wont be able to test the VPW communication, but will be able to check if its loaded properly as it should send the device name and info over serial port. *fingers crossed*

Re: AVR to Arduino - VPW

Posted: Sat Mar 29, 2014 11:30 pm
by Tazzi
Well I think it flashed successfully :)
Just gotta write some code up quickly to read whatever is sent from the arduino.

Re: AVR to Arduino - VPW

Posted: Sun Mar 30, 2014 1:34 pm
by antus
This is a good quick reference to see if whatever speed your looking for is going to be achievable at your clock speed, and how close the speed will be. Within a couple of % is acceptible, but you can see some rates like 11.0592 Mhz or 18.432 Mhz lend themselves to serial data transmission at normal speeds better than others. I used it extensively when I was trying to build my vpw cable on AVR.

http://www.wormfood.net/avrbaudcalc.php

Re: AVR to Arduino - VPW

Posted: Sun Mar 30, 2014 10:37 pm
by Tazzi
Cheers Ant, funny enough I had that bookmarked already from research of baud rates and clockspeeds.

Only thing Im looking to understand better is adapting the prescaler to suit the 16Mhz chip.

Re: AVR to Arduino - VPW

Posted: Thu Apr 03, 2014 12:06 pm
by Tazzi
Was going over the schematic, added a few labels to see if there was any parts I can toss for the moment for simple test designs. It probably is a good idea to keep it as is since it would be nice to see when data is passing through, and when the device is powered up.

But, highlighted in the green square.. Im a little lost whats happening there? I thought this would be connected to 5v, since well.. its not really a constant 12v from the car, this can fluctuate from 10v to 14ish volts, any idea if this will be an issue?

Also, I not too experienced with Eagle or pcb designing software, really appreciate if someone could draft up the diagram below for an arduino shield of some sort. Just dont need the atmega8 chip or max232 chip. Board only needs to connect to the rx/tx pin, power and gnd.
Commented.png
Commented.png (55.29 KiB) Viewed 7240 times

Re: AVR to Arduino - VPW

Posted: Thu Apr 03, 2014 3:46 pm
by VL400
Its a buffer/driver that clamps the battery voltage using the zener (8.2V) and current limiting resistor. The forward volt drop of the diode D3 drops it another 0.7V or so to keep it within the VPW spec of (I think) a nominal 7V for a high.