Changing sensor G62 on Golf MKIII GT
Aug0
I have a Golf 3 GT from 1995 and this car has already an OBD connection to plug into the onboard computer an retrieve error and other kind of informations. I bought a very cheap cable OBD cable from ebay to do this kind of debugging.
There was one error that was making me think from a long time ago. The error was something like “Sensor G62 Open or Short to ground on B+” so I decided to use the multimeter to check if the sensor was really messed up. Conclusion, it was!
In the next day I went to a VAG parts shop and bought a new G62 sensor and put hands at work to make the change.
Be very carefull if you decided to do the following steps!
DO THIS ONLY AFTER COLD OR VERY LITTLE USAGE OF THE CAR FROM COLD!! You can get seriously burned!
First step was to take out the engine cooling liquid deposit in order to reduce the pression of the liquid. Because when you take out the sensor, the liquid will come out. After taking out the deposit is time to take out the sensor from its place and switch it with the new one.
Next, you need to put everything back in place again. You also need to set the cooling liquid level to its place again as some liquid will always be losted.
And voila! There are no errors on the onboard computer. I realized that this sensor was being missed a lot. Since I bought the car that I had problems with cranking after running the car and this becomes warm. The sensor provides runtime information of the engine actual temperature and that information is used to control intake air amount and other sort of stuff very usefull for optimum combustion of the fuel.

Results? Perfect crank and running in all conditions (so far)!!
Symfony cheat sheets
Jul0
If you are into web development and if you ever used Symfony, maybe you know that sometimes is hard to memorize all the functionalities provided by a framework.
I was wondering how could I do a ordered a bunch of records after a criteria select and I asked that to web developer coleguee at work. He passed me a link to Symfony Cheat Sheet and I found that very usefull.
In order to never forget and share with other persons I decided to post it here!
HSV color changing led driven by AVR tiny45
Jun0
In my last post I focused on delivering an integer only based algorithm to make a HSV to RGB conversion. I wanted to to drive a mood lamp with an AVR tiny13 which as only a 1K byte program memory. I ended gaving up on this idea because, I was not having good results.
I decided to get a new chip, with more program memory. The chosen one was the tiny45 with 4K bytes of program memory.
I got back in time and started again with the floating point version of the algorithm. And voila! It is working. It has a few glitches which increase with a small interval between color changing.
At this point, the code is very simple and it is like this (assumes a 2Mhz clock on the tiny45):
-
-
#include <avr/io.h>
-
#include <avr/interrupt.h>
-
#include <avr/pgmspace.h>
-
#include <avr/eeprom.h>
-
#include <avr/wdt.h>
-
#include <util/delay.h>
-
#include <math.h>
-
-
#define R_PIN PB0
-
#define G_PIN PB1
-
#define B_PIN PB2
-
-
static float h=0,s=0.8,v=0.5,r=0,g=0,b=0;
-
static int ri,gi,bi;
-
-
void HSVtoRGB( float *r, float *g, float *b, float h, float s, float v )
-
{
-
int i;
-
float f, p, q, t;
-
-
if( s == 0 ) {
-
*r = *g = *b = v; // achromatic (grey)
-
return;
-
}
-
-
h /= 60; // sector 0 to 5
-
i = floor( h );
-
f = h – i; // factorial part of h
-
p = v * ( 1 – s );
-
q = v * ( 1 – s * f );
-
t = v * ( 1 – s * ( 1 – f ) );
-
-
switch( i )
-
{
-
case 0:
-
*r = v;
-
*g = t;
-
*b = p;
-
break;
-
case 1:
-
*r = q;
-
*g = v;
-
*b = p;
-
break;
-
case 2:
-
*r = p;
-
*g = v;
-
*b = t;
-
break;
-
case 3:
-
*r = p;
-
*g = q;
-
*b = v;
-
break;
-
case 4:
-
*r = t;
-
*g = p;
-
*b = v;
-
break;
-
default:
-
*r = v;
-
*g = p;
-
*b = q;
-
break;
-
}
-
}
-
-
ISR(TIM0_COMPA_vect)
-
{
-
static unsigned char count = 0;
-
-
if (count == 0)
-
PORTB = _BV(R_PIN) | _BV(G_PIN) | _BV(B_PIN);
-
-
if (count==ri)
-
PORTB^=_BV(R_PIN);
-
-
if (count==gi)
-
PORTB^=_BV(G_PIN);
-
-
if (count==bi)
-
PORTB^=_BV(B_PIN);
-
-
count++;
-
}
-
-
int main()
-
{
-
// Enable PORTB as output
-
DDRB=0xff;
-
-
// Enable global interrupts
-
sei();
-
-
// Setting timer in CTC mode
-
TCCR0A = _BV(WGM01);
-
-
// Setting no prescaler
-
TCCR0B = _BV(CS00);
-
-
// Enabling compa
-
TIMSK = _BV(OCIE0A);
-
-
// Setting compare to make a frequency of 60*256 Hz
-
OCR0A = 0×82;
-
-
while(1)
-
{
-
if (h==360)
-
h=0;
-
-
h++;
-
-
HSVtoRGB(&r,&g,&b,h,s,v);
-
-
ri = r*255.;
-
gi = g*255.;
-
bi = b*255.;
-
-
_delay_ms(100);
-
}
-
-
return 0;
-
}
-
-
HSV to RGB color conversion in C, using integers only!
Jun0
My current goal is to build a mood lamp using a 3W RGB led and an AVR microcontroller. To control color fading I have taken a suggestion from promag who told me to explore the HSV color model because it deals with the colors in a much more natural and easy way.
I googled a little and found a conversion function from HSV to RGB written in C, the problem was that the algorithm was using floats and I can’t use them right now, as i’m using a ATtiny13 with only 1K of flash memory for the program. When the math lib is linked and floats are used the final program size increases a lot! So I had to convert the algorithm to use integers only. The other option was to change to a micro controller with more program memory.
The result of the conversion was the the following:
-
-
void HSVtoRGB( int *r, int *g,int *b, int h, int s, int v )
-
{
-
int f;
-
long p, q, t;
-
-
if( s == 0 )
-
{
-
*r = *g = *b = v;
-
return;
-
}
-
-
f = ((h%60)*255)/60;
-
h /= 60;
-
-
p = (v * (256 – s))/256;
-
q = (v * ( 256 – (s * f)/256 ))/256;
-
t = (v * ( 256 – (s * ( 256 – f ))/256))/256;
-
-
switch( h ) {
-
case 0:
-
*r = v;
-
*g = t;
-
*b = p;
-
break;
-
case 1:
-
*r = q;
-
*g = v;
-
*b = p;
-
break;
-
case 2:
-
*r = p;
-
*g = v;
-
*b = t;
-
break;
-
case 3:
-
*r = p;
-
*g = q;
-
*b = v;
-
break;
-
case 4:
-
*r = t;
-
*g = p;
-
*b = v;
-
break;
-
default:
-
*r = v;
-
*g = p;
-
*b = q;
-
break;
-
}
-
}
-
But while it works on a computer, when I use this code in a AVR, the color transitions are not smooth and there are a few glitches. I haven’t found the solution for that yet. Maybe that will be the content of my next post.
How to setup PWM on a AVR (Part II)
Jun0
In my last post I have described a little bit of what PWM is and which are the abstract steps are necessary to be executed. Now let’s go to the code. This code assumes a Tiny 13 AVR with an internal oscilator of 9.6 MHz divided by 8 (fuses configuration).
-
int main()
-
{
-
// Enable PORTB as output
-
DDRB=0xff;
-
-
// Enable global interrupts
-
sei();
-
-
// Enabling Timer 0 Fast PWM mode
-
TCCR0A = _BV(WGM01) | _BV(WGM00) | _BV(COM0A1);
-
-
// Setting Prescaler to none
-
TCCR0B = _BV(CS00);
-
-
// Setting the duty cycle to 50%
-
OCR0A = 0x7f;
-
-
while(1);
-
}
And that’s it. This code enables a PWM with a 50% duty cycle and controls a led connected to PB0 pin. If you need to give to led full intensity, then OCR1A must be set to 0xff, if you want the less intensity possible you need to set OCR1A to 0×00.
How to setup PWM on a AVR (Part I)
Jun0
I have been trying to make the setup of a PWM with an AVR. My wish is to build my own mood lamp. I divided my problem into smaller problems which the most basic is the generation of a PWM signal to control the brightness of the led.
PWM stands for Pulse Width Modulation and it consists in generating a square wave with a variable duty cycle. Imagine a perfect square wave, that half of the cycle is up and another half is down. That wave as a duty cycle of 50%.
If you power a lamp with this signal and give the up value 5 volts, at 50 Hz, it means that it will receive a 2.5 voltage 50 times per second, because 2.5 its the mean value along the time.
If you change the duty cycle you can obtain a full on, or a full of. This is simple explanation and lot can be found about PWM googling a little bit.
To make an AVR generate a PWM signal you just need to do the following:
- Setup a timer to a PWM mode.
- Enable global interrupts
- Enable port as output
My next post will be about more pratical and it will focus on how to implement led intensity change on a Tiny13 AVR using PWM.



