Pages

Monday, June 24, 2013

An AVR Atmega library for HD44780 based lcd connected through i2c

This library implements a driver for HD44780 lcd connected through PCF8574 port expander.
Data is transmitted using only 2 wire over i2c with the PCF8574.


Lcd driver is based upon Peter Fleury's lcd driver.
Setup parameters can be found in file lcdpcf8574.h and pcf8574.h
This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 1MHz.




Issues fix:

  • If you have problem making this library works with Arduino Uno and QAPASS LCD with Funduino I2C interface, please read the comment above "Matt Alizadeh June 1, 2018 at 2:56 PM"  by Matt Alizadeh


Changelog
  • 02: added CGRAM, custom char functions by Péter Papp
  • 01: first release

Code

Notes
  • read risk disclaimer
  • excuse my bad english

Monday, June 17, 2013

Irradiance/Illuminance Meter using TLR235R sensor with AVR Atmega

The TSL235 is a light-to-frequency converter.
This library reads TSL235 output frequency and convert it to irradiance, and then to illuminance.


Irradiance is the power of electromagnetic radiation per unit area (radiative flux) incident on a surface. It's expressed in watt per square metre, the symbol is Ee.

In photometry, illuminance is the total luminous flux incident on a surface, per unit area. It is a measure of how much the incident light illuminates the surface, wavelength-weighted by the luminosity function to correlate with human brightness perception. It's expressed in lux, the symbol is Ev.

Irradiance and illuminance are related by the luminosity function. The luminosity function describes the average spectral sensitivity of human visual perception of brightness. This function it is standardized, usually the CIE 1924 function it is used for conversion.

The standard luminosity function is normalized to a peak value of unity at 555 nm, so the value of the constant in front of the integral is usually rounded off to 683 lm/W.
Vlambda is the luminosity function.

To measure TSL235 output we count the number of risign edge on the clock external input pin of Atmega.
Using this frequency count method, we can measure up to F_CPU / 2. Given a 8Mhz micro frequency, we can measure up to 4Mhz.

References of the below summary goes to Irradiance Meter by Jonathan Thomson.

TSL235 returns a frequency dependant on spectral irrandiance or the light source.
Every photon that crash on the photodiode area is beeing absorbed and converted to current depending on his wavelength. Current is then trasformed to frequency by a Current-to-Frequancy converter.
The photodiode has a spectral responsivity that vary upon wavelength. The responsivity over a specify wavelength is specify by datasheet. TSL235 photodiode react from 300 to 1100nm.
We can say that


given fO as the output frequency, Re(lambda) as responsivity over wavelength, Ee(lambda) source light spectral irradiance over wavelength

If we fix a normalized spectral irradiance of a know source as X(lambda), the frequency output from sensor is:


Because fX is computed starting by the normalized spectral irradiance X(lambda), and our light source has the same shape of spectral irradiance, we can relate fX and fO by a constant k.


So, the spectral irradiance of the measured source is [uW/(cm^2)/nm]


and the irradiance of the source [uW/(cm^2)]


The measured illuminance [lm/m^2] of the source is related to irradiance by the formula:


Note that we have to transoform Ee from uW/(cm^2)/nm to W/(m^2)/nm, this is the reson for the 10.000 (1/cm^2 to 1/m^2) and 1.000.000 parameter (uW to W).

Now, beacuse we are want to use micro to do all the computation, if we fix the lumisonisity function, the sensor responsivity, and the source spectral function we can evaluate a fixed constant that we can use in lower resource environment, like micro, to calculate the illuminance.


so


and


Some matlab helpers are provided with code to:

  • grab responsivity function from a the datasheet graph (using ginput)
  • export luminosity function on a desired wavelength interval
  • export a normalized spectral irradiance for the light source
  • test the function above

Setup parameters are stored in file tsl235.h


Code

Notes
  • read risk disclaimer
  • excuse my bad english

Monday, June 3, 2013

AVR Atmega audio input RMA using FFT Radix-4

audiogetradix4 is a simple library you can use to interface with a ac audio input.
It reads data from an ADC pin and returns the RMS value of the input using DFT Radix-4 algorithm.


The discrete Fourier transform (DFT) converts a finite list of equally-spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids, ordered by their frequencies, that has those same sample values.

I'm not a DSP expert, so if some expert find error in the method i use, explained below, please let me know.

A Radix-4 decimation-in-time (DIT) FFT is a Cooley–Tukey algorithm for computing the discrete Fourier transform (DFT).

My radix4 implementation is a port of RADIX-4 FFT library by Anatoly Kuzmenko.

To obtain RMS value of the AC current of the audio signal processed, from which you can get the SPL db value, we use the Parseval's theorem for FFT so for fft size of N.

Let's conside x[i] as the signal, and let's take N samples, we could take only real part of the signal using our ADC, so we can consider Parseval therorem for DFT.


consider X[k] as the "modified" frequency spectrum, valid from 0 to N/2, and the the first (0) and the last (N/2) element have to be divided by the root square of 2.
We define:

given ReX as the real part, and ImX as the imaginary part of the signal in frequency domain.

So Parseval therorem for DFT became:

 Now we know that RMS in time domain is:

Applying the parseval theorem we can compute RMS in frequency domain as:

Because we are computing a discrete signal, we can treat the equation above for DTFT.
So X[k] is not a "modified" frequency spectrum.

So Parseval therorem for DTFT became:

And we can compute RMS in frequency domain as:

Once again as audiogetavarage library here is also implemented a dynamic bias, for the electronic board used during experiment, refer to that project.
This time the TLC272 opamp is used in pre, this ic is a little more sensitive then the TLC27L2 used previously, so a filter caps is added in this pre circuit revision (rev 03).


As a tips, i would like to recomend you The Scientist and Engineer's Guide to Digital Signal Processing to study in deep DSP, some of the math above is from this book.

Setup parameters are stored in file audioget.h

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz


Code

Notes
  • read risk disclaimer
  • excuse my bad english