Xplain, Timer, delay and sine - questions!

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

// Writing in AVR Studio 5 (gcc), using Xplain -Xmega128A1.

Hello. I have 3 questions:

1) I'll make an amplitude that has a value between 1 and zero, by using this formula:

Amplitude = sin ((X - 3000) / (4000/180))

X is a random variable drawn from a normal distribution table.

How can a write the code? can I use the sine in C?

2) I have made "‹"‹a normal distribution table that goes from 0 to 4000

How can I use a timer to pick out the X?

X shall be a random number from the table, using a timer.

and finally ....

3) convert this sentence from _delay_ms to _delay_us.

rand1 = 4 + (uint16_t) ((double) rand () / ((double) RAND_MAX + 1) * 3);

_delay_ms (rand1);

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1) yes, the line you wrote is valid in C (if the parameter is in radians)

2) You want the table in PROGMEM you then use:

value = pgm_read_word(&dist_table[rand() % 4000]);

3)

_delay_us( rand1 * 1000);