Need help with C code for a project.

Discussion in 'Embedded Systems and Microcontrollers' started by illusive, Oct 28, 2015.

  1. illusive

    Thread Starter Member

    Jul 9, 2015
    46
    0
    Hi all!
    I've just started to learn C for avr microcontrollers, but i urgently need to write a code for a project of mine to finish it (it is not school related).
    Basically what i need is to convert a square wave signal to a constant one. I have an IC that controls 7 bands of leds, so every band is on 1/7th of the time, so i want to put a microcontroller between that IC and the output transistors in order to "smooth" the signal, because of that low duty cycle signal the brightness of the leds is too low.
    I'm planning to use ATtiny2313 because it has enough pins for the job. So i need to write a code for the ATtiny so when a square wave signal is detected at pin number 2 a constant output signal is presented at pin number 19 for example.

    Here is a rough schematic of what i have in mind:
    P51028-141821.jpg

    If you can give me example for 1 pin on how the code will work i will do the rest for the 7 pins. Or if there is a tutorial or a similar project somewhere i think i will figure it out. I just wasn't able to find what i need on the net.

    Thanks!
     
  2. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,677
    2,728
    I'm not going to write code for you, but here is what you need to do:

    Create a set of 7 flag bits: These bits represent whether an output should be on or off.
    Create 7 software timers, one for each bit. The expiration time of each timer should be longer than the period of the incoming square waves.
    Poll each pin. If a '1' is detected, reset the corresponding timer and set the corresponding flag.
    If a timer expires, clear the corresponding flag;
    For each set flag, activate the corresponding output pin. For each clear flag, clear the corresponding output pin.

    If the CPU supports it, you can use the output pin register bits as your flags.

    This is nothing more than a software "pulse stretcher", and could also be performed with 555 timers if you wish to eliminate the MCU.
     
Loading...