diFireplace: New Year habrakamin

    A fireplace is such a thing that personifies the extraordinary warmth, comfort of your home, sweets, gifts, winter evenings, and indeed a pleasant thing. Today we will build a real habracamine - in a computer case, on nanotechnological LEDs and "warm tube" technologies - pic12f683, Hi-Tech PICC in the Hi-Tide IDE.

    Not so long ago I got hold of a new home computer and caring Chinese put 12-centimeter fans glowing red in front and behind in the case. They made a lot of noise, zero benefits, so I quickly dismantled them. Here are just an empty place and an eternally overwhelming feeling in one place on the subject of homemade goods that haunted me and eventually resulted in the idea of ​​a fireplace in the front of the computer. The fireplace should have flared up depending on the number and duration of system calls to the hard drive and gradually went out in the absence of them.

    Means of implementation

    Microcontroller pic12f683 . While we are asserted that the controllers for 100+ rubles are cheaper and one hundred times steeper than the controllers for 30 rubles, we will sit on old, proven and popular solutions. Something more ambitious than an eight-foot controller, we do not need. I settled on this “because I had them”, but the implementation of the fireplace itself should fit into pic12f629 or pic12f675 . Any peripherals, except for two timers and an input / output port, are not needed.
    LEDs . There are two of them, to ensure the necessary brightness in the window of the case, and to ensure the reality of the combustion effect. I took the 1-candela ones in power of yellow color, they consume 20 mA each (obligatory remark that it is impossible to conduct more than 100 mA through the MK).
    Programming MK . Anyone who is familiar with Microchip products a little more than hearsay, probably knows that some time ago Microchip absorbed for money the company Hi-Tech, which was developing compilers for these same controllers. And not so long ago, Microchip presented to the public its new products - the XC series compilers. In fact, these are the same combined old PICC, With NN in the form of a chaotic mishmash of the rules of old dialects. Nobody reads the long paragraphs anyway, because to you - sweetie . So far, there are more unpleasant and contradictory feelings from them than feelings of standardization and the only true vector for creating your applications.
    Staying on the old and still pretty nice Hi-Tech PICC 9.60 STD. Instructions on how to get this rarity are on the archive page of the absorbed company.
    The IDE . Separately, I highlight the use of a little more than enough pleasant IDE from the same Hi-Tech - Hi-Tide. This add-on for Eclipse features a handy wizard to determine the configuration and settings of the controller. Hi-Tide is installed with the compiler (checkbox at one of the installation steps) or, for those who do not start version 3.15, you can try 3.13 .

    Some agreement on the implementation of plans

    Here are some sketches of ideas about the functioning of the created fireplace:
    1. Both LEDs should independently create a flame effect. Their joint work gives light closer to the real flame.
    2. We will divide the implementation of the flame effect into three components — software PWM for setting the instantaneous brightness of the glow from 0 to 255, frames — stages of changing random brightness of the glow and the border of these brightness depending on the total brightness of the glow. I found out experimentally that it’s good when the lower limit can vary from 0 to 50 and the upper one - from 30 to 255.
    3. The total brightness of the glow varies from 0 to 255 and depends on the number or duration of access to the disk. If the frames will “hang” on the zero timer, then the change in the overall brightness is on the independent first and interrupt on the change of state at the input.
    4. To use software PWM, you have to use a high clock frequency, I took the maximum possible 20 MHz.
    5. The state of calls to the hard drive will be taken directly from the positive contact of the LED on the case. There can be only two states on the LED - either pressed to the ground, or to +5 volts. This state of affairs will help get rid of suspenders and other subcircuits to ensure discreteness of input states.


    The device diagram is used as follows:

    I do not see the need for explanation - the number of parts is minimal, their selection is described above.

    We also omit how from this:

    It turns out this: The

    form factor of the board was mainly determined by the size of the window and the possibilities for attaching it to the computer case.

    The power and signal input of the hard drive on the board of the device is made in a single standard pin connector, on its back there is an ordinary molex for soldering in textolite, but with +5 V (red) and ground (black) wires connected and the other two contacts are damped by heat shrinkage . The input signal is permanently soldered to the positive leg of the LED:


    I prefer to make the settings first in the Hi-Tide wizard, and then rewrite them in a new way to fill out the assignments of values ​​not specified in them to the configuration bytes.
    FUSE-s turn off the watchdog-timer, instruct to use an external high-frequency resonator and an external pin to restart the program.

    Peripheral settings are as follows:
    	// По переполнению таймера 1 будет вызываться прерывание
    	PIE1 = 0b00000001;
    	// Включаем прерывания нулевого таймера и возможность получения прерываний периферии
    	INTCON = 0b01101000;
    	// К 0 и 1 контактам подключены светодиоды, прочие - на вход
    	TRISIO = 0b00111100;
    	// Таймер 0 используется с минимальным делителем частоты
    	OPTION = 0b00000000;
    	// Также как и таймер 1
    	T1CON = 0b00000001;
    	// Выключение компараторов
    	CMCON1 = 0x07;
    	CMCON0 = 0x07;
    	CCP1CON = 0x00;
    	// Выключение АЦП и концигурация всех выводов ка дискретные
    	ADCON0 = 0x00;
    	ANSEL = 0x00;
    	// Включение прерываний по изменению состояния на пине 2
    	IOC = 0b00000100;

    In the 683 controller, as in some others, there is a problem with the inability to separately set or accept values ​​on specific pins of the I / O port and you have to use the entire value of the GPIO port. To simplify the output, I use the following functions for setting high, low levels and resulting output:
    volatile uint8 fIoBuffer;
    voidsetIoPinHigh(uint8 aPinNumber){
    	fIoBuffer |= (1 << aPinNumber);
    voidsetIoPinLow(uint8 aPinNumber){
    	fIoBuffer &= ~ (1 << aPinNumber);
    	GPIO = GPIO & 0b11111100 | fIoBuffer;

    The randomizer is necessary only within the framework of generating one byte, because I used the functions of the pseudo-random sequence generator cut out and modified from standard modules:
    volatile uint32 fRandomSeed;
    	fRandomSeed = TMR0 ^ TMR1H ^ TMR1L;
    uint8 randomByte(void){
    	fRandomSeed = fRandomSeed * 1103515245L + 12345;
    	return fRandomSeed >> 16;

    On an overflow event of the first timer, two routines must be executed. The first is software PWM for outputting instantaneous brightness of LEDs. The logic is simple: the counter is always incremented; if it overflows, it falls to zero. Instantaneous brightness (fPwmLedValue1 or fPwmLedValue2) takes a value from 0 to 255, and if the counter is less than this value, then the LED is on, if more, then no. The higher the frequency of adding the counter, the less noticeable is the flickering of the LED, it merges in our eyes into a change in its brightness.
    if(fPwmLedValue1 > fPwmLedCounter1)
    if(fPwmLedValue2 > fPwmLedCounter2)

    The second action is frames. Experimentally, I selected a frame length of 0.3 seconds, which, according to the calculator , corresponds to 2930 zero timer overflow events. Each frame calculates the new instantaneous brightness of each of the LEDs (depends on the set boundaries fPwmHi and fPwmLo) and, if possible, determined by the Boolean fCanIncrement, reduces the overall brightness of the fireplace:
    uint8 randPwmValue(void){
    	return fPwmLo + randomByte() % (fPwmHi - fPwmLo);
    if(fFrameCounter >= FRAME_DELAY)
    	fPwmLedValue1 = randPwmValue();
    	fPwmLedValue2 = randPwmValue();
    	fFrameCounter = 0;

    When the input state changes to high, the total brightness of the fire must be incremented, the timer for the duration of access to the hard disk must be restarted, the boundaries of the instantaneous brightnesses will be recalculated, and the flag for enabling the increment of the overall brightness to be set. Recalculation of borders occurs according to the linear law:
    	fPwmLo = (uint8)(0.1953125 * (float)fBrightness);
    	fPwmHi = (uint8)(0.8828125 * (float)fBrightness + 30);
    	if(fBrightness < 255)
    if(GPIO & 0b00000100)
    	fCanIncrement = 1;
    	TMR1H = 0;
    	TMR1L = 0;
    	fCanIncrement = 0;


    A simple program and a simple scheme can achieve good results. Even if the video shot on the microwave is not able to show the actual results of the work, then the real work of the device makes you meditate while sitting at the "fire". Here is the video at night, in the afternoon, in a slightly different way :

    Sources and schemes are on github .

    Also popular now: