Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Development / Re: Time Library added to Playground on: January 21, 2010, 09:35:12 am
I think you should make overloaded functions in the library. It's more logical.

For example when I say I'm gonna do something in 5 minutes, I don't say I'm gonna do something in 0 hours and 5 minutes smiley-wink

Btw I have uploaded the sourcecode of the timesync application:

http://www.megaupload.com/?d=YIEMNV9W
2  Forum 2005-2010 (read only) / Development / Re: Time Library added to Playground on: January 20, 2010, 01:27:46 pm
I have created a Visual Basic application based on the code from Moriszen.

Here is the link: http://www.megaupload.com/?d=1A76PJ5F
3  Forum 2005-2010 (read only) / Development / Re: New library for Scheduling Time Based Tasks on: January 27, 2010, 02:09:18 pm
Think dayoffset is wrong, lets take Sunday for example. Today is Sunday.

This is your code:

unsigned long dayOffset =  ( 7 + DOW - dayOfWeek(now())) % 7;

dowSunday returns 1, dayOfWeek(now()) returns 0.

(7 + 1 - 0) % 7 = 8 % 7 = 1. So the alarm is always a day off. Correct me if I'm wrong.

I think the right code is:

unsigned long dayOffset =  ( 7 + (DOW - 1) - dayOfWeek(now())) % 7;

ps I also added some functions to your library, usable for easy printing alarms or timers:

TimeAlarms.h
Code:
 void clear();                                                 // disable and clear all alarms from memory
  time_t readAlarm(AlarmID_t ID);                   // return the value for given alarm
  time_t readTimer(AlarmID_t ID);                   //      return the value for given timer

TimeAlarms.cpp
Code:
// return the value for alarms only
time_t TimeAlarmsClass::readAlarm(AlarmID_t ID)
{
  if(ID < dtNBR_ALARMS && Alarm[ID].Mode.isAllocated && Alarm[ID].Mode.isAlarm)
    return Alarm[ID].value ;
  else       
    return 0l;  
}

// return the value for timers only
time_t TimeAlarmsClass::readTimer(AlarmID_t ID)
{
  if(ID < dtNBR_ALARMS && Alarm[ID].Mode.isAllocated && Alarm[ID].Mode.isAlarm == false && Alarm[ID].Mode.isOneShot)
    return Alarm[ID].value ;
  else       
    return 0l;  
}

void TimeAlarmsClass::clear()  // clear and disable all alarms and make them avialable for allocation  
{
  for(uint8_t id = 0; id < dtNBR_ALARMS; id++){
     Alarm[id].Mode.isEnabled = false;  
     Alarm[id].Mode.isAllocated = false;
  }
}
4  Forum 2005-2010 (read only) / Development / Re: New library for Scheduling Time Based Tasks on: January 26, 2010, 06:54:26 pm
Thanks! Gonna try tommorow. Will report back to you!
5  Forum 2005-2010 (read only) / Development / Re: New library for Scheduling Time Based Tasks on: January 26, 2010, 12:25:27 pm
Quote
Peeter, the logic is in the library but it hasn't been tested and the user interface isn't there. If you would like to try it, add this to the top of the ...

Mem, this doesnt work, if i add an alarm for Sunday the alarm triggers today. If i add an alarm for monday the alarm triggers tomorrow. Can you explain why? smiley-wink

I'm guessing its days from now and not weekdays.
6  Forum 2005-2010 (read only) / Development / Re: New library for Scheduling Time Based Tasks on: January 22, 2010, 03:20:02 pm
Can you please update your library, to schedule alarms to specific times at specific days of the week. If you can find the time ofcourse.

It would be really cool to schedule diferrent alarms at different days of the week smiley-wink

Thx
7  Forum 2005-2010 (read only) / Development / Re: Frequency Measurement FFT, DFT on: January 24, 2010, 06:34:29 pm
Nooo ofcourse not, I used an Arduino! smiley-razz As you can read on that page the AVR used is an ATmega8 so the software is compatible with an arduino. Used avrstudio to write the code and uploaded the .hex to the arduino. smiley-wink

Quick and Dirty Code

Code:
// AVR FFT
// based on code from ELM-chan & Michael Spiceland
// Designed for atmega328 @ 16MHz
// LCD Pins for Arduino Data(DB0-Pin2|DB1-Pin3|DB2-Pin4|DB3-Pin5) Funtions(RS-Pin6|RW-Pin7|E-Pin8)
// Samplerate = 9.6kHz Max Freq ~5kHz
// (c) Peeter123
// F_CPU is defined already in project definition
// #define F_CPU 16000000

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <avr/sleep.h>
#include <stdio.h>
#include <inttypes.h>
#include <ctype.h>
#include <util/delay.h>
#include <math.h>
#include "fft.h"
#include "lcd.h"


// choose 9600 if you have issues, but you shouldn't
#define BAUD 38400
#define MYUBRR F_CPU/16/BAUD-1

/* defines */
#define NUM_SAMPLES  FFT_N
#define FFT_SIZE FFT_N / 2

int16_t capture[FFT_N];                  /* Wave capturing buffer */
complex_t bfly_buff[FFT_N];            /* FFT buffer */
uint16_t spectrum[FFT_N/2];            /* Spectrum output buffer */

// UART functions
static int uart_putchar(char c, FILE *stream);
uint8_t uart_getchar(void);
static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);

// make blinkin' e-z on port C
void BlinkMS(int time);
int set_PORTB_bit(int position, int value);
void lcd_spectrum_data(unsigned char fft_hight, unsigned char position);

// to print FFT data to UART
void print_FFT(uint16_t *buffer, uint8_t points);
void print_wave(int16_t *buffer, uint8_t points);


static const PROGMEM unsigned char BarGraphChar[] = //Bargraph custom chars
{
      0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
      0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1f,
      0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1f, 0x1f,
      0x0, 0x0, 0x0, 0x0, 0x0, 0x1f, 0x1f, 0x1f,
      0x0, 0x0, 0x0, 0x0, 0x1f, 0x1f, 0x1f, 0x1f,
      0x0, 0x0, 0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
      0x0, 0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f,
      0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f
};

unsigned char LcdDataBuffer1[20]; //LCD Line data buffers
unsigned char LcdDataBuffer2[20];
unsigned char LcdDataBuffer3[20];
unsigned char LcdDataBuffer4[20];


/************************************************************************
 * ISR TIMER0 Overflow
 *
 * This routine is run evertime the timer counter overflows.  Since the
 * timer counter is 8 bits, it can count to 255 before overflowing and
 * going back to 0.  The frequency this is executed in is determined by
 * the clock speed / clk_divide (TCCR0) / 256.
 ***********************************************************************/
ISR(TIMER0_OVF_vect){
      static unsigned char count = 0;
      static unsigned char count_clock = 0;
      static uint16_t offset = 0;
      uint8_t adc_val;

      //printf("%s \n ","inside interrupt");

      // we only want to run every clk/4 times  8mhz
      count_clock++;
      if ((count_clock % 4)){ // 2 = 16mhz, 4 = 8mhz, 8 = 4mhz
            return;}

      ADCSRA |= (1 << ADSC); // start ADC conversion
      while (ADCSRA&(1<<ADSC)); // wait for the result to be available
      adc_val = ADCH;

      capture[offset] = ((int16_t)(adc_val)-127)*4; // convert to signed linear and multiplied by 4
      offset++;

      if (offset == NUM_SAMPLES) // buffer is full
      {
      count = 0;
            //FFT
            fft_input(capture, bfly_buff);
            fft_execute(bfly_buff);
            fft_output(bfly_buff, spectrum);
            print_FFT(spectrum, NUM_SAMPLES/2);
            offset = 0;
           //LCD
            lcd_clrscr();
        for(unsigned char p=0;p<60;p = p + 3){
                  lcd_spectrum_data(spectrum[p+1],count);      
                  count++;
            }
            for(unsigned char l1=0;l1<20;l1++){
                  lcd_putc(LcdDataBuffer1[l1]);
            }
            lcd_gotoxy(0,1);      
            for(unsigned char l2=0;l2<20;l2++){
                  lcd_putc(LcdDataBuffer2[l2]);
            }
            lcd_gotoxy(0,2);
            for(unsigned char l3=0;l3<20;l3++){
                  lcd_putc(LcdDataBuffer3[l3]);
            }
            lcd_gotoxy(0,3);      
            for(unsigned char l4=0;l4<20;l4++){
                  lcd_putc(LcdDataBuffer4[l4]);
            }
      }
}


int main(void){

      // STARTUP SEQUENCE

      /* initialize port data directions */
      PORTB = 0xFF;

      /* initialize timers */
      TCCR0B |=  _BV(CS00);       // clk prescale (Fcpu/1)
      TIMSK0 |= _BV(TOIE0);       // enable timer/counter0 overflow interrupt
      TCNT0 = 0;                  // Reset timer 0
    //TCCR1B |= (1 << WGM12); // Configure timer 1 for CTC mode
    //TCCR1A |= (1 << COM1A0);// Enable timer 1 Compare Output channel A in toggle mode
    //OCR1A   = 31;                   // Set CTC compare value to 500kHz at 16MHz AVR clock, with a prescaler of 1
    //TCCR1B |= (1 << CS00);       // Start timer at Fcpu/1
      
      /* initialize the ADC */
      ADMUX |= _BV(REFS0)| _BV(ADLAR);  // we only want 8-bit on ADC 0 VCC reference
      ADCSRA |= _BV(ADEN);  // for now we don't do this in the ISR | _BV(ADIE);
      ADCSRA |= _BV(ADPS2)| _BV(ADPS0);//_BV(ADPS2);//| _BV(ADPS1)| _BV(ADPS0); // clk is / 32

      /* initialize the UART */
      DDRD = 0b11111110;         //PORTD (RX on PD0)
      // load baud rate registers
      UBRR0H = (MYUBRR) >> 8;
    UBRR0L = MYUBRR;
    // enable transmitter + receiver
    UCSR0B = (1<<RXEN0)|(1<<TXEN0);
    // asynchronous, no parity, 1 stop bit, 8 bit character size
    UCSR0C = (0<<UMSEL01)|(0<<UMSEL00)|(0<<UPM01)|(0<<UPM00)|(0<<USBS0)|(0<<UCSZ02)|(1<<UCSZ01)|(1<<UCSZ00);
      stdout = &mystdout;
      
      /* initialize the LCD Display*/
      lcd_init(LCD_DISP_ON);
      
      //Load two userdefined characters from program memory into LCD controller CG RAM
       lcd_command(_BV(LCD_CGRAM));  /* set CG RAM start address 0 */
       for(unsigned char i=0; i<64; i++)
       {
           lcd_data(pgm_read_byte_near(&BarGraphChar[i]));
       }
      
      // let ya know startup's finished
      BlinkMS(500);
      sei(); //enable global interrupts

      /* AVR's like to have a loop */
      while(1) {
      }
}

void lcd_spectrum_data(unsigned char fft_hight, unsigned char position){
      if(fft_hight < 32){
            LcdDataBuffer1[position] = 0;
            LcdDataBuffer2[position] = 0;
            LcdDataBuffer3[position] = 0;
            LcdDataBuffer4[position] = 1 + fft_hight / 4;
      }else if(fft_hight < 64){
            LcdDataBuffer1[position] = 0;
            LcdDataBuffer2[position] = 0;
            LcdDataBuffer3[position] = fft_hight / 4;
            LcdDataBuffer4[position] = 0xFF;
      }else if(fft_hight < 96){
            LcdDataBuffer1[position] = fft_hight / 4;
            LcdDataBuffer2[position] = 0xFF;
            LcdDataBuffer3[position] = 0xFF;
            LcdDataBuffer4[position] = 0xFF;
      }else if(fft_hight < 128){
            LcdDataBuffer1[position] = fft_hight / 4;
            LcdDataBuffer2[position] = 0xFF;
            LcdDataBuffer3[position] = 0xFF;
            LcdDataBuffer4[position] = 0xFF;
      }else{
            LcdDataBuffer1[position] = 0xFF;
            LcdDataBuffer2[position] = 0xFF;
            LcdDataBuffer3[position] = 0xFF;
            LcdDataBuffer4[position] = 0xFF;
      }
}

static int uart_putchar(char c, FILE *stream)
{
    if (c == '\n') uart_putchar('\r', stream);

    loop_until_bit_is_set(UCSR0A, UDRE0);
    UDR0 = c;

    return 0;
}
/*
uint8_t uart_getchar(void)
{
    while( !(UCSR0A & (1<<RXC0)) );
    return(UDR0);
}*/

// Blink an LED on PB5 Pin 13 Arduino
void BlinkMS(int time)
{
      set_PORTB_bit(5, 1);
      _delay_ms(time);
      set_PORTB_bit(5, 0);
      _delay_ms(time);
}

int set_PORTB_bit(int position, int value)
{
        // Sets or clears the bit in position 'position'
        // either high or low (1 or 0) to match 'value'.
        // Leaves all other bits in PORTB unchanged.

      if (value == 0){
            PORTB &= ~(1 << position);      // Set bit # 'position' low
      }
      else{
            PORTB |= (1 << position);       // Set bit # 'position' high
      }
return 1;
}

#define GAIN 1


// prints comma separated values of sample[0]...sample[N/2] to UART
void print_FFT(uint16_t *buffer, uint8_t points)
{
      uint8_t i = 0;
      uint16_t value;
      
      for(i = 0; i < points; i++)
      {
            value = (unsigned char)(buffer[i]) * GAIN;

            // I print the value of the FFT sample
            printf("%d,",buffer[i]);
      }
      // end
      printf("\n");
}
8  Forum 2005-2010 (read only) / Development / Re: Frequency Measurement FFT, DFT on: January 22, 2010, 12:45:58 pm
Look at this link:

http://elm-chan.org/works/akilcd/report_e.html

I have succesfully implemented this on an arduino smiley-wink
9  Forum 2005-2010 (read only) / Exhibition / Re: LED Matrix Spectrogram on: February 05, 2010, 05:49:23 pm
Can you still upload the source code, want to use it on an 16*24 matrix smiley-wink
10  Forum 2005-2010 (read only) / Bar Sport / Re: hello everyone! on: January 20, 2010, 01:27:14 pm
Hi there! smiley-wink
Pages: [1]