Simple single-color 8x8x8 LED Cube with AVRs
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

eq.c 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * eq.c
  3. *
  4. * Copyright 2011 Thomas Buck <xythobuz@me.com>
  5. * Copyright 2011 Max Nuding <max.nuding@gmail.com>
  6. * Copyright 2011 Felix Bäder <baeder.felix@gmail.com>
  7. *
  8. * This file is part of LED-Cube.
  9. *
  10. * LED-Cube is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * LED-Cube is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with LED-Cube. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. #include <avr/io.h>
  24. #include <stdint.h>
  25. #include <util/delay.h>
  26. #include "eq.h"
  27. #include "adc.h"
  28. #define Trs 72
  29. #define Ts 19
  30. #define To 36
  31. uint8_t result[7] = {128, 128, 128, 128, 128, 128, 128};
  32. #define RESETPORT PORTC
  33. #define STROBEPORT PORTC
  34. #define RESET PC3
  35. #define STROBE PC2
  36. #define RESETON RESETPORT |= (1 << RESET)
  37. #define RESETOFF RESETPORT &= ~(1 << RESET)
  38. #define STROBEON STROBEPORT |= (1 << STROBE)
  39. #define STROBEOFF STROBEPORT &= ~(1 << STROBE)
  40. void equalizerInit(void) {
  41. RESETON;
  42. STROBEOFF;
  43. }
  44. uint8_t *equalizerGet(void) {
  45. uint8_t i, offset = getOffset();
  46. RESETOFF;
  47. _delay_us(Trs);
  48. for (i = 0; i < 7; i++) {
  49. STROBEON;
  50. _delay_us(Ts);
  51. STROBEOFF;
  52. _delay_us(To); // Wait for result
  53. // Get result, takes ca. 29ms
  54. adcStartConversion(0);
  55. result[i] = offset + adcGetByte();
  56. }
  57. RESETON;
  58. asm volatile ("nop");
  59. asm volatile ("nop"); // Ensure minimal reset pulse width
  60. // 2 NOPs at 16MHz are enough...
  61. return result;
  62. }
  63. uint8_t getOffset(void) {
  64. adcStartConversion(0x01);
  65. return (adcGetByte() / 2);
  66. }