Skip to main content

Messages

This section allows you to view all Messages made by this member. Note that you can only see Messages made in areas you currently have access to.

Messages - senso

31
General discussion / Re: Getting started in the ARM world
This is driving me crazy!!
Without the so said 3.3 version after more than 1h following this tutorial:
https://sites.google.com/site/stm32disc ... evelopment

I got a bunch of errors because it was made for that lib and not for the old libs.
There is so many people out there using ARM's and I cant get to put one compiler up, I think that I will install CoCox, looks like ready to use, lets hope for the best, but I will only try that tomorrow or next week, I'm dead lol.

Well, I see that almost all the DP projects have PIC's, I will PIC's in my university, PIC's have nice IDE's that work, a simple PicKit3 program any Pic out there and there are Pic's up to 32 bits, if I feel the need for speed/power, and I can get free samples, I think I will ditch the Arm world if CoCoox doesn't work right..

EDIT:

YAY!!!
CooCox compiles dummy while(1) loop and also its built in blinky demo!!
Finally it works!
33
Project logs / Re: AVR VU meter and spectrum analyser
I forgot to say, but I'm using AvrStudio and the WinAvr C compiler, no Arduino IDE and no arduino bloated libs, it compiles to just under 4K of flash and less tha 512 bytes of ram used right now.

I designed the op-amp filer in the LTSpice but I dont know (yet) how to really use it to do some simulations ;)

Thanks for the compliment, yes the lcd as two bar modes so to say, after having the bar functions up and running they are really handy to have, for example in distance sensors for simple robots so have some visual indication of what the sensor is seeing without needing some tailor made test made program in the pc.
34
Project logs / AVR VU meter and spectrum analyser
Good night to everyone, I'm here to show my on-going project, its a little VU meter and spectrum analyzer that I made using an op-amp, an Arduino(I know that not everyone likes them, and I don't really like the Arduino in its essence to many bloat code, but it was a cheap way of getting a dev-board so to say, because I didn't have paypal account to buy a real ISP programmer, but I already have the parts coming to make an USBasp), and a 16x2 char lcd.
By now its still pretty incomplete, it still doesn't have buttons so I can change between the two modes, and a little menu to at least adjust lcd contrast and brightness via pwm, in fact that adjustment code and hardware are not even built/tested.

To control the lcd I use Pete Fleury lcd lib, and the FFT part is handled by the great Elm-chan FFT engine, the lcd is updated at about 14Hz via timer interruption and the rest is always running in the background so to say.

I'm using this also as a motive to learn how to use Eagle and how to lay down a pcb, that I will order in SeeedStudio, and in fact I have a little doubt, can anyone teach me how to define the board size so Seeed will cut the board to size and not to the 5x5cm square, the design it self is not yet concluded, I will add the buttons for the menu and at least i2c headers so I can have them for future extensions like a little led controller using some tlc5940 and a little uC to go between the i2c and the tlc.

This is my code, the comments are in Portuguese though:
Code: [Select]
/*
*****************************************************************************
**  LCD VU meter and FFT spectrum analyser                          *
**  Using Peter Fleury lcd lib and el-chan fft engine for avr            *
**  Made for Atmega328p/Arduino Duemilanove                          *
**  Tiago Angelo  12/01/2011                                    *
**  V0.6                                                  *
**                                                        *
*****************************************************************************

****************************************************************************
**
**  Pinos do lcd - 16x2
**  1  2  3  4  5  6  7  8  9  10    11  12  13  14    15  16
**  Gnd  Vcc  Ctr  RS  RW  En  D0  D1  D2  D3    D4    D5  D6  D7    An    Cat
**PB        4  5                  0    1    2    3
**PD              7
**
**  Ctr - Contrast
**  An - Anode(+)
**  Cat - Cathode(-)
****************************************************************************
*/

#include <avr/io.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#define F_CPU 16000000UL
#include <util/delay.h>
#include <math.h>
#include <inttypes.h>
#include <avr/pgmspace.h>

#include "lcd.h"
#include "ffft.h"

/*
** Defines usados no programa
*/
#define NUM_SAMPLES 64      //Samples usadas para calcular o FFT
#define FFT_SIZE (64/2)      //Numero de valores devolvidos pelo FFT

#define FULL 0xFF  //Caracter "cheio", consultar datasheet para perceber
#define BLANK 0xFE  //Caracter em branco

/*
***********************************************************************
** Constantes globais usadas no programa
***********************************************************************
*/

static const PROGMEM unsigned char vuChars[] = {  //Dados na flash que não são precisos na Ram para nada
  0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,  // 1 linha
  0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,  // 2 linhas
  0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C,  // 3 linhas
  0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E,  // 4 linhas
  0x00, 0x00, 0x1F, 0x10, 0x10, 0x10, 0x00, 0x00,  //simbolo L
  0x00, 0x00, 0x1F, 0x05, 0x0D, 0x12, 0x00, 0x00,  //Simbolo R
  };
static const PROGMEM unsigned char fftChars[] = {  //Dados na flash que não são precisos na Ram para nada
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F,  //1 coluna
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F,  //2 coluna
  0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F,  //3 coluna
  0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F,  //4 coluna
  0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,  //5 coluna
  0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,  //6 coluna
  0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,  //7 coluna
  0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F,  //7 coluna
  };

uint8_t i,k;                  //Variaveis de iterações
uint8_t sector2 = 0;            //Numero de colunas para o vu meter, linha 2
uint8_t sectorRest2 = 0;        //Numero de colunas para o vu meter, linha 2
uint8_t sector1 = 0;            //Numero de colunas para o vu meter, linha 1
uint8_t sectorRest1 = 0;        //Numero de colunas para o vu meter, linha 1
uint8_t count = 0;
volatile uint8_t j=0;            //variavel de iterações (só para a ISR)
volatile uint8_t lcd_linha1[16];  //Dados da linha 1 do lcd
volatile uint8_t lcd_linha2[16];  //Dados da linha 2 do lcd
uint16_t newReading1 = 0;        //Variavel para guardar o valor lido pelo ADC
uint16_t newReading2 = 0;        //Variavel para guardar o valor lido pelo ADC
uint16_t lastReading1 = 0;
uint16_t lastReading2 = 0;
uint16_t adcVal= 0;              //Usado para guardar o valor lido pelo adc no modo fft
uint32_t mapped1 = 0;            //Variavel para guardar o valor de adc_var_1*map
uint32_t mapped2 = 0;            //Variavel para guardar o valor de adc_var_2*map

//Estas 3 são especificas para o FFT
int16_t capture[FFT_N];        //Buffer de captura
complex_t bfly_buff[FFT_N];      //Buffer do FFT
uint16_t spectrum[(FFT_N/2)];  //Buffer de saida do FFT


/*
***********************************************************************
** Declarações dos protótipos das funções
***********************************************************************
*/

int adc_read(char channel);      //Função usada para ler um canal arbitrário do ADC
void adc_init(void);        //Função para inicializar o ADC
void vu_mode(void);
void vu_mode_init(void);      //Inicialização do modo VU meter
void fft_mode_init(void);
void fft_mode(void);
void timer1_init(void);        //Inicialização do Timer1
void lcd_test(void);

/*
***********************************************************************
** Inicio do main
***********************************************************************
*/

int main(void){

  adc_init();
  lcd_init(LCD_DISP_ON);        //Inicializa o LCD, sem cursor visivel
  lcd_clrscr();              //Limpa o lcd e coloca o cursor em (0,0)
  fft_mode_init();            //Inicialização do modo fft
  //vu_mode_init();            //Inicialização do modo vu meter
  timer1_init();              //Inicialização/configuração do timer para gerar as interrupções
  sei();                    //Inicia as interrupções

  while(1){                  //Loop infinito
     
      //vu_mode();            //Modo vu meter
      fft_mode();              //Modo fft
      //lcd_test();            //Modo de teste do lcd
      }

  return 1;
}

/*
***********************************************************************
** ISR
** Corre todo o vu_mode e faz o refresh do display.
** Todo o trabalho é feito por interrupção, deixando o CPU livre
** entre interrupções.
** Actualiza as duas linhas na totalidade.
***********************************************************************
*/

ISR(TIMER1_COMPA_vect){

  lcd_gotoxy(0,0);
  for(j=0; j<16; j++){
      lcd_putc(lcd_linha1[j]); }

  lcd_gotoxy(0,1);
  for(j=0; j<16; j++){
      lcd_putc(lcd_linha2[j]); }
  }

/*
***********************************************************************
**                    Funções usadas
***********************************************************************
*/

/*
***********************************************************************
** Inicializa o ADC no modo 10bits a 125Khz
***********************************************************************
*/

void adc_init(void){

  ADCSRA |= ((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0));  //16Mhz/128 = 125Khz
  ADMUX |= (1<<REFS0);                    //Referencia de 5v, com condensador no pino Aref
  ADCSRA |= (1<<ADEN);                    //Adc ligada
  ADCSRA |= (1<<ADSC);                    //Fazer uma primeira conversão para iniciar o circuito e porque é a mais lenta
}

/*
***********************************************************************
** Passa-se o canal a ler e devolve um valor de 10bits do ADC
***********************************************************************
*/

int adc_read(char channel){

  ADMUX &= 0xF0;                  //Limpa o canal anterior
  ADMUX |= channel;              //Define o novo canal a ler do ADC
  ADCSRA |= (1<<ADSC);            //Inicia uma nova conversão
  while(ADCSRA & (1<<ADSC));        //Espera que a conversão seja feita
  return ADCW;                  //Retorna o valor do ADC, em modo 10 bits
}

/*
***********************************************************************
** Le o canal 0 e 1 do adc, faz uma detecção de pico e depois mapeia
** o valor 0..1023 do adc para 0..75 barras no display 16x2
***********************************************************************
*/

void vu_mode(void){
 
  newReading1 = adc_read(0);
  newReading2 = adc_read(1);
 
  if(newReading1 > lastReading1){
      lastReading1 = newReading1; }
  else{
      lastReading1 = (lastReading1*3 + newReading1)/4; }  //Decaimento "suave"

  mapped1 = ((lastReading1 * 75)/1024);                  //Pega nos 0..1023 e devolve 0..75
  sector1 = mapped1/5;                              //Segmentos FULL na linha 0
  sectorRest1 = mapped1 % 5;                            //Segmento final da linha 0

  if(newReading2 > lastReading2){
      lastReading2 = newReading2; }
  else{
      lastReading2 = (lastReading2*3 + newReading2)/4; }  //Decaimento "suave"

  mapped2 = ((lastReading2 * 75)/1024);                  //Pega nos 0..1023 e devolve 0..75
  sector2 = mapped2/5;                              //Segmentos FULL na linha 1
  sectorRest2 = mapped2 % 5;                            //Segmento final da linha 1
 

  //Linha 0
  for(i=0; i<(sector1); i++){
      lcd_linha1[i+1] = FULL; }
  if(sectorRest1>=1){
      lcd_linha1[i+1] = ((sectorRest1-1)); }
  for(i=(sector1 + 1);i<15; i++){
      lcd_linha1[i+1] = BLANK; }

  //Linha 1
  for(i=0; i<(sector2); i++){
      lcd_linha2[i+1] = FULL; }
  if(sectorRest2>=1){
      lcd_linha2[i+1] = ((sectorRest2-1)); }
  for(i=(sector2 + 1);i<15; i++){
      lcd_linha2[i+1] = BLANK; }

}

/*
***********************************************************************
** Le o canal 0 do adc, ao subtrair 512 á sample de 1023 bits cria um
** sinal positivo ou negativo centrado em 0, é preciso para o fft
** usando o FFT feito pelo elm-chan calcula um FFT de 64 pontos
** e preenche as duas linhas do lcd com barras
***********************************************************************
*/

void fft_mode(void){
  count = 0;
  adc_read(0);
  cli();
  while(count != NUM_SAMPLES){
      ADCSRA |= (1<<ADSC);
      while((ADCSRA & (1<<ADSC))){};
      adcVal = ADCW;
      capture[count] = ((int16_t)(adcVal)-512);
      count++;
      }
  sei();

  fft_input(capture,bfly_buff);
  fft_execute(bfly_buff);
  fft_output(bfly_buff,spectrum);
 
  k=0;
  for(i=1; i<17; i++){
      sector1 = spectrum[i]/16;

  if(sector1>7){
      lcd_linha2[k]=FULL;
      lcd_linha1[k]=(sector1-8);
      }
  else{
      lcd_linha2[k]=sector1;
      lcd_linha1[k]=BLANK;
      }

      k++;

  }
}

/*
***********************************************************************
** Função de teste usada para afinar o gerador de barras verticais
***********************************************************************
*/

void lcd_test(void){

  for(i=0; i<16; i++){
 
  sector1=i;

  if(sector1>7){
      lcd_linha2[i]=FULL;
      lcd_linha1[i]=(sector1-8);
      }
  else{
      lcd_linha2[i]=sector1;
      lcd_linha1[i]=BLANK;
      }

  }


}

/*
***********************************************************************
** Carrega da flash os caracteres especiais para fazer as barras e as
** letras L e R na CGRAM do display
***********************************************************************
*/

void vu_mode_init(void){

  lcd_command(_BV(LCD_CGRAM));                  //Coloca CG RAM no endereço 0
  for(i=0; i<48; i++){
      lcd_data(pgm_read_byte_near(&vuChars[i])); }  //Lê os dados da flash e carrega na Ram do LCD

  lcd_gotoxy(0,0);  //Linha 0 coluna 0
  lcd_putc(4);      //Escreve L na esquerda
  lcd_gotoxy(0,1);  //Linha 1 coluna 0
  lcd_putc(5);      //Escreve R na direita
  lcd_linha1[0]=4;
  lcd_linha2[0]=5;
}

/*
***********************************************************************
** Carrega da flash os caracteres especiais para fazer as barras e as
** na CGRAM do display
***********************************************************************
*/

void fft_mode_init(void){
 
  lcd_command(_BV(LCD_CGRAM));                  //Coloca CG RAM no endereço 0
  for(i=0; i<64; i++){
      lcd_data(pgm_read_byte_near(&fftChars[i]));  }  //Lê os dados da flash e carrega na Ram do LCD

  lcd_clrscr();
}

/*
***********************************************************************
** Inicializa o timer1(16 bits) no modo CTC com prescaller de 1024
***********************************************************************
*/

void timer1_init(void){

  TCCR1B |= (1 << WGM12);        // Configure timer 1 for CTC mode
  OCR1A = 1100;              //Para gerar interrupções a 14Hz para o refresh do display, valor obtido experimentalmente
  TIMSK1 |= (1 << OCIE1A);      // Enable CTC interrupt
  TCCR1B |= ((1<<CS12)|(1<<CS10));//Inicia timer 1 com clock div de 1024
}

And this are some photos:





And the input buffer/signal conditioner, if I'm not wrong its a full bridge precision rectifier, some people have said its half-bridge, but I think its full bridge:



And two videos showing it working, sadly my cam for some reason doesn't catch the real movement of the bars, they are slowed down between 3 and 6 times than reality.

http://www.youtube.com/watch?v=91fefTmt2hI

http://www.youtube.com/watch?v=Zpz8XP4go3U

And now where it is really bad, the Eagle schematic and pcb, the pcb as top and bottom ground plane:







What do you think about it?
Any suggestions or critics are welcome.
EDIT: Looks like the images are cutted and there is no scroll bar, you can see then doing right click and View Image.
35
General discussion / Re: Forum migration
I know that you are already working on this, but I have the same opinion as znanev, even in my small 15" laptop I have a lot of unsued space at each side of the screen, maybe a little bit wider, I dont say to use all the width but a bit more wouldn't hurt.
But I understand you, I have setup some foruns and it can be a real pain until we understand what does what, and more important where are the options that we want to tweak, some times they are just buried in the deeps.

Keep up the good work Ian ;)

EDIT:

I know that this is isnt really related to forum, but more to the WordPress blog, but today I tried to reply to one post, and I was logged in as the machinegeek, I could no post, but it was saying that I was logged in with is account, and after that in the Name field I have Ian, must be a strange bug out there in the blog.
37
General discussion / Re: Forum migration
Congratulations for the new forum Ian!
I have been using the forum and I didn't detect anything unusual, everything is working just perfectly!
38
General discussion / Re: Getting started in the ARM world
Finally got some time to do a fresh install of the CodeSourcery Lite, Eclipse and the suggested Eclipse plugin from the GnuArm project, it all seems to be fine a working, now, I'm with a little trouble, all the examples that I have from STM are just include after include after include of files and I cant even understand why so many included headers and respective sources all scattered around 7 or 8 folders.

Do any one know of a simple project for Eclipse that I can import and do a dummy compile, another thing, how can I define to what micro-controller I want to compile, from what I saw in the Attolic TrueStudio I just select the desired target micro-controller in a list and the IDE does all the house keeping, but using CodeSourcery and Eclipse I don't have those little things, can someone help me?

Many thanks to all the great information that everyone as just posted here!!

EDIT:
I think my problem is using Windows..
Although the old tool-chain that I tried gave some warnings that I couldnt correct, I think that I will switch back to ubuntu and send an email to the script author and see if he can help me.
39
General discussion / Re: IR photogates
For what I have read in the Microchip site I taught that those chips could handle the creation of the carrier and the modulation of the data, and also receiving the data and doing the de-modulation, I know that they dont implement any protocol, cant I just hook then to an usart and send a steady stream of 0xAA for example?
This will need testing with hardware I know, but I'm still waiting for the parts to arrive.
Thanks for your help and suggestions sirs!
40
General discussion / Re: IR photogates
The TSPOP17xx I think I can get here, for around 2,5€ each, more than 3$ for such a commom thing..
I have requested some MCP2022 samples, and I will try to get some IR emitter leds from the electronics shop and find some sort of TSOP and will test the system, I will report back to you ;)
41
General discussion / Re: IR photogates
I have found the MCP2022 and other that is almost the same, looks like it would simplify a lot the use of encoded data/modulation, using a simple pattern like 0xAA, 0x55, 0x88, would suffice I think, now I need to get some TSOP's, that in Portugal are un-obtanium and ebay seems risky :/

Yes, but I think that there could be false positives when the sun is directly shinning to the sensor, the idea of the modulation came from seeing how the commercial units made by Osram and others work, but each emitter from Osram costs more than 100€ and I think that I can do something near as good for much less money.
42
General discussion / IR photogates
Goodnight everyone, I'm thinking about (trying) to do an IR photogate, such the ones used in automated garage-doors, to use well, in my garage-door.
But I have some doubts, should I simply use an IR emiter in one side, or more, because the garage door as almost 4m wide, and a simple IR receiver in the other end, or should I use use modulated IR's?
The big question is that I dont really know how to then demodulate the signal, using one TSOP variant would work or they only work if I have some sort of RC-5 protocol/info being transmitted?
44
General discussion / Re: Outputing a variable over serial using atmega32 + max232
You can also use itoa, that stands for Integer TO Ascii, so it converts an integer value to a little ascii string that you can send to your terminal.
Something like this in your main loop code should work:
Code: [Select]
#include <stdlib.h>  //This should be together with all the other includes
char buff[5];  //This is a little output buffer for itoa and should be declared outside your main loop
itoa(brightness, buff, 10);
USART_Transmit(buff);
The 10 is in what base you want to convert, you can use 2 for binary, 8 for octal, 10 for decimal and 16 for hexadecimal.
Its really simple and easy, but if you want to learn a little bit more read this:
http://www.nongnu.org/avr-libc/user-man ... tdlib.html
45
General discussion / Re: Getting started in the ARM world
Yet another twist, I think that while I don’t have a JTAG programmer, and since the LPCXpresso and the Discovery boards both need proprietary software to program then that only runs in Windows I will try to install CoCox, as it supports both boards and I can use the ST-LINK to program the Discovery and FlashMagic as someone said to program the LPCXpresso.
What is your opinion about CoCox?
I think that in fact it boils down to the same things, all of this different compilers and/or IDE's uses gcc and the same libs under the hood, or I'am wrong?

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01642486120session_write_close ( )...(null):0
20.01672617736ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01672618512Database_MySQL->query( ).../DatabaseHandler.php:119
40.05882757272Database_MySQL->error( ).../Db-mysql.class.php:273