⬆️ ⬇️

diFireplace: New Year's Habrakamin

A fireplace is such a thing that personifies an extraordinary warmth, comfort of a home, candies, gifts, winter evenings, and generally a pleasant thing. Today we will build a real habrakamine - in a computer case, on nanotechnology LEDs and “warm tube” technologies - pic12f683, Hi-Tech PICC in IDE Hi-Tide.



Not long ago, I got hold of a new home computer and caring Chinese inserted 12 centimeter fans in front and behind in the case that glowed in red. They emitted a lot of noise, good - zero, because I quickly dismantled them. Here are just an empty place and always sverbayuschy feeling in one place on the subject of home-made did not give me rest and eventually resulted in the idea of ​​a fireplace in the front of the computer. The fireplace would have to flare up depending on the number and duration of system accesses to the hard disk and gradually go out in the absence of it.



Means of sale



Microcontroller pic12f683 . While we are being told that controllers for 100+ rubles are cheaper and more vigorous than controllers for 30 rubles, we will sit on old, proven and popular solutions. We will not need something more extensive than an eight-pin controller. I stopped at this “because I had them,” but the implementation of the fireplace itself should fit into pic12f629 or pic12f675 . Any peripherals, including two timers and an I / O port will not be needed.

LEDs . There are two of them, to provide both the necessary brightness in the case window, and to ensure the reality of the burning effect. I took 1-candelaic in power of yellow color, consume 20 mA (mandatory remark that more than 100 mA can not be performed via MC).

Programming MK . Anyone who is familiar with the products of Microchip a little more than hearsay, probably knows that some time ago Microchip absorbed Hi-Tech, which developed compilers for these controllers, for money. Not so long ago, Microchip presented its new products to the public - the XC series compilers. In essence, these are the same combined old PICC, NN in the form of a muddled jumble of rules of the old dialects. Long paragraphs still no one reads, because you - candy . So far, there are more unpleasant and contradictory feelings from them than feelings of standardization and the only true vector of creating their applications.

Staying on the old and still quite pleasant Hi-Tech PICC 9.60 STD . Instructions how to get this rarity are on the archive page of the absorbed company.

IDE . Separately, I will highlight the use of a little more than enough pleasant IDE from the same Hi-Tech - Hi-Tide. This add-on above Eclipse is characterized by a handy wizard for defining the configuration and settings of the controller. Hi-Tide is put together with the compiler (checkbox on one of the installation steps) or, for those who do not start version 3.15, you can try 3.13 .



Some agreements on the implementation of plans



Here are some sketches of ideas about the functioning of the fireplace being created:

1. Both LEDs must independently create a flame effect. Their joint work gives a light closer to the true 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 the random brightness of the glow and the boundary of these brightness depending on the overall brightness of the glow. Experimentally, I found out that good is when the lower bound can vary from 0 to 50 and the upper limit from 30 to 255.

3. The total brightness of the glow varies from 0 to 255 and depends on the number or duration of disk access. If the frames will “hang” on the zero timer, then the change in the overall brightness is on the independent first and interrupts due to the state change on the input.

4. To use the software PWM will have to use a high clock frequency, I took the maximum possible 20 MHz.

5. The status of calls to the hard disk 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. Such a state of affairs will help get rid of braces and other subcircuits ensuring the discreteness of states at the input.

')

Iron



The device layout is as follows:



I see no need for explanations - the number of parts is minimal, their choice is described above.



Omit as well from this:



It turns out this:



The form factor of the board is mainly determined by the size of the window and the possibilities for mounting it to the computer case.



The power supply and the hard disk signal input on the board are made in a single standard male connector, on the back of it is an ordinary molex for sealing into textolite, but with attached wires of +5 V (red) and ground (black) and the other two contacts plugged with heat shrinkage . The input signal is permanently soldered to the positive leg of the LED:





Firmware



I prefer to make the settings first in the Hi-Tide wizard, and then rewrite them in a new way by filling them with the assignment of values ​​not specified in them into the configuration bytes.

FUSE-s disable watchdog-timer, prescribed to use an external high-frequency resonator and the external pin to restart the program.

__CONFIG(HS & WDTDIS & PWRTDIS & MCLREN & UNPROTECT & UNPROTECT & BORDIS & IESODIS & FCMDIS); 


The peripheral settings are as follows:

 void initHardware(void) { //    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 take 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 to set the high, low levels and the resulting output:

 volatile uint8 fIoBuffer; void setIoPinHigh(uint8 aPinNumber) { fIoBuffer |= (1 << aPinNumber); } void setIoPinLow(uint8 aPinNumber) { fIoBuffer &= ~ (1 << aPinNumber); } void updateIoBuffer(void) { GPIO = GPIO & 0b11111100 | fIoBuffer; } 




The randomizer is only needed as part of generating one byte, so I used the functions of the pseudo-random sequence generator that were cut and modified from standard modules:

 volatile uint32 fRandomSeed; void srand(void) { fRandomSeed = TMR0 ^ TMR1H ^ TMR1L; } uint8 randomByte(void) { fRandomSeed = fRandomSeed * 1103515245L + 12345; return fRandomSeed >> 16; } 




Upon the overflow event of the first timer, two subroutines must be executed. The first is software PWM for outputting the instant brightness of the LEDs. The logic is simple: the counter is always incremented; if it overflows, it drops to zero. Instant 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 it is greater, then not. The higher the frequency of adding the counter, the less noticeable the blinking of the LED, it merges in our eyes into a change in its brightness.

 fPwmLedCounter1++; fPwmLedCounter2++; if(fPwmLedValue1 > fPwmLedCounter1) setIoPinHigh(PIN_LED1); else setIoPinLow(PIN_LED1); if(fPwmLedValue2 > fPwmLedCounter2) setIoPinHigh(PIN_LED2); else setIoPinLow(PIN_LED2); updateIoBuffer(); 


The second action is frames. Experimentally, I picked up a frame length of 0.3 seconds, which, according to the calculator , corresponds to 2930 zero-timer overflow events. Each frame is used to calculate the new instant brightness of each of the LEDs (depending on the set fPwmHi and fPwmLo bounds) and, if possible, determined by the Boolean fCanIncrement, reducing the overall brightness of the fireplace:

 uint8 randPwmValue(void) { return fPwmLo + randomByte() % (fPwmHi - fPwmLo); } 
 fFrameCounter++; if(fFrameCounter >= FRAME_DELAY) { fPwmLedValue1 = randPwmValue(); fPwmLedValue2 = randPwmValue(); if(!fCanIncrement) decBrightness(); fFrameCounter = 0; } 




When the input state changes to high, the overall brightness of the fire should be incremented, the timer for the hard disk should be restarted, the boundaries of the instantaneous brightness should be recalculated and the increment resolution flag of the general brightness should be set. Recalculation of boundaries occurs according to a linear law:

 void calcEdges(void) { fPwmLo = (uint8)(0.1953125 * (float)fBrightness); fPwmHi = (uint8)(0.8828125 * (float)fBrightness + 30); } void incBrightness(void) { if(fBrightness < 255) { fBrightness++; calcEdges(); } } 
 if(GPIO & 0b00000100) { fCanIncrement = 1; incBrightness(); TMR1H = 0; TMR1L = 0; } else fCanIncrement = 0; 




results



A simple program and a simple scheme make it possible to 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 operation of the device makes it necessary to meditate, sitting by the “fire”. Here is a video at night, in the afternoon a bit different





Sources and schemes - on githabe .

Source: https://habr.com/ru/post/164943/



All Articles