Menu

Digital light effect

jackjames
2025-05-07
2025-05-22
  • jackjames

    jackjames - 2025-05-07

    A few years ago psychedelic lights were all the rage.
    These lights would light up in time with the music, following the progression of the high, medium and low frequencies.
    The circuit at the time used more or less complicated RC or RLC filters.
    Now the signals can be analyzed using digital filters that, through mathematical calculations, divide the changed audio signal into the desired frequency bands.
    I had written the program I am sharing in MikroBasic and, now that GCBasic supports floating point calculations, I have converted it for this compiler.
    The software divides the audio band into four different frequency bands and drives four outputs.
    I used a pic with a 32MHz clock to have a better performance with the musical progression.
    Inside the source there are explanations on the operation and instructions for the connections of the micro.

    ' 1. The audio signal is sampled via the ADC (channel AN0).
    ' 2. The signal is processed by four IIR digital filters to separate the bands:
    ' - ExtraBass: Low-pass filter with a cutoff frequency of 100 Hz.
    ' - Bass: Band-pass filter with frequencies between 101 Hz and 400 Hz.
    ' - Middle: Band-pass filter with frequencies between 401 Hz and 2 kHz.
    ' - High: High-pass filter with a cutoff frequency of 2 kHz.
    ' 3. The filtered signals are compared with the potentiometer values.
    ' 4. If the signal of a band exceeds the corresponding threshold, the output is activated.

     
    ❤️
    1
    👍
    1

    Last edit: jackjames 2025-05-07
  • Chris Roper

    Chris Roper - 2025-05-07

    That takes me back........

    I recall that for my younger Sister's 16th birthday, way back in 1976, I rigged up a set of disco lights for her party, all synchronized to the music. It was primitive and it mainly followed the beat and the peak volume of the music, rather than any frequency analysis, but it worked and everyone loved it.

    Apart from my Mother that is because the next morning she wanted to take her car shopping only to discover that it was missing its Head lamps, tail lights, ignition coil and Indicator relays.

    I think you have just reminded me of why I decided to follow a career in electronics ;)

     
  • mmotte

    mmotte - 2025-05-07

    I have been wondering how to use pics to do digital filters and
    How to use the new GCB floating point. This does both! Thanks.!

    I too had dual three channel color organs hook ed to the stereo back in the early 70's. They were transistor RC filters, scr's, 120vac bulbs, diamond shaped fluorescent light diffusers. They worked good but life happened and they were too big for the living room.

    73
    Mike

     
  • Anobium

    Anobium - 2025-05-08

    Fantastic Use of GCBASIC’s Floating Point Capabilities! 🎶🚀

    This is absolutely brilliant! It is truly great to see the Singles capability being put to such impressive use. A few years ago, this kind of real-time frequency analysis would have been a nightmare with analogue filters, but now, thanks to floating point support in GCBASIC, projects like this are not only possible but incredibly efficient. The fact that you have successfully converted your MikroBasic program and achieved such a robust solution is a testament to both your skill and the power of GCBASIC’s evolving capabilities.

    The complexity of this programme is remarkable—handling ADC sampling, applying four IIR digital filters, and dynamically driving outputs based on frequency thresholds is no small feat. The precision of the filtering and the responsiveness of the system show just how well thought-out this implementation is. Using a 32MHz PIC to ensure smooth performance is a great choice, and it is exciting to see how well GCBASIC handles such demanding calculations.

    A huge shoutout to everyone involved in last year’s Singles project—this is exactly the kind of advanced application we envisioned when pushing for floating point support. Seeing it in action like this is incredibly rewarding. Hats off to you for bringing this to life, and to all who contributed to making Singles a reality! 👏🔥 I would love to hear more about how the system performs under different audio conditions—this is truly next-level work!

    Evan

     
  • Anobium

    Anobium - 2025-05-08

    @Jackjames

    Can I get your permission to add to the GitHub demos? Please.

     
    • jackjames

      jackjames - 2025-05-08

      Certainly

       
  • Anobium

    Anobium - 2025-05-09

    See KO-FI for the full post KO-FI and the URL to the demo folder.

     
    ❤️
    1
  • Roger Jönsson

    Roger Jönsson - 2025-05-11

    May I ask, how much margin is there before the 32MHz PIC goes into the wall, not able to keep up handling a majority of the samples + filters (at the 8KHz sample frequency)? Is there a margin?

     
  • Roger Jönsson

    Roger Jönsson - 2025-05-11

    May I ask, how much margin is there before the 32MHz PIC goes into the wall, not able to keep up handling a majority of the samples + filters (at the 8KHz sample frequency)? Is there a margin?

     
  • Roger Jönsson

    Roger Jönsson - 2025-05-11

    Sorry for the double message. I don't know why the copy got sent.
    I looked at the code and I see that a wait 125us is used. Does this mean that the actual processing is so fast that you still end up with a sample frequency close to 1/125us=8KHz?

     

    Last edit: Roger Jönsson 2025-05-12
    • jackjames

      jackjames - 2025-05-14

      Actually no, it was for testing and it stayed there like that. It needs to be lowered but I don't have the program with me now, I had set it with the oscilloscope during debugging.

       
      👍
      1
  • Roger Jönsson

    Roger Jönsson - 2025-05-17

    Sounds like much of the time it is slowed down with wait to get to the sample frequency, then.
    If single is that effective so that it can do multiple IIR filters in real time (hopefully at a higher sampling rate), then it can be really useful!
    It's great to have a project like this as a starting point!

     
    • jackjames

      jackjames - 2025-05-18

      I had written the original program in MikroBasic and I tried it on the pic16F1847 with a clock of 32mhz and on a pic18F47K40 with a clock of 64MHz. In both cases the response was quite fast and the effect was pleasant.
      I did not have the opportunity to try this version in GCBasic because I gave the circuit I had assembled to a friend for his birthday.
      It all depends on the speed that the GCBasic compiler uses to do the floating point calculations.
      If you try it, use a PIC with a high enough clock and let us know how it goes.

       
  • Picsi

    Picsi - 2025-05-22

    Great work, I'm impressed!
    I wouldn't have thought that something like this is possible with an 8-bit PIC. Considering that others need a DSP or a GHz CPU for this... ;)

     

    Last edit: Picsi 2025-05-22

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.