Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 63 → Rev 64

/IR-TX-BL/branches/PWM-CTRL_V0.02/Doku/fuses.JPG
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/IR-TX-BL/branches/PWM-CTRL_V0.02/Doku/fuses.JPG
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/IR-TX-BL/branches/PWM-CTRL_V0.02/PWM-CTRL.pnproj
0,0 → 1,0
<Project name="IR-Tx"><File path="main.c"></File><File path="main.h"></File><File path="uart.h"></File><File path="uart.c"></File><File path="twislave.c"></File><File path="twislave.h"></File></Project>
/IR-TX-BL/branches/PWM-CTRL_V0.02/PWM-CTRL.pnws
0,0 → 1,0
<Workspace><File path="c:\mikrokopter\projects\ir-tx-bl\branches\led-ctrl_v0.01\main.c"></File><Project path="c:\mikrokopter\projects\ir-tx-bl\branches\led-ctrl_v0.01\led-ctrl.pnproj"></Project></Workspace>
/IR-TX-BL/branches/PWM-CTRL_V0.02/PWM-CTRL_V0_02.eep
0,0 → 1,2
:060000000000FFFFFFFFFE
:00000001FF
/IR-TX-BL/branches/PWM-CTRL_V0.02/PWM-CTRL_V0_02.hex
0,0 → 1,194
:1000000012C02CC02BC02AC029C03AC027C026C0AD
:1000100026C0AAC023C022C021C020C01FC01EC04D
:100020001DC033C31BC011241FBECFE5D4E0DEBF0B
:10003000CDBF11E0A0E6B0E0ECEFFAE002C0059021
:100040000D92AA36B107D9F711E0AAE6B1E001C0D6
:100050001D92AA38B107E1F779D14FC5D1CF1F92D0
:100060000F920FB60F9211248F9380916B018F5FC7
:1000700080936B018F910F900FBE0F901F9018957A
:100080001F920F920FB60F9211242F933F934F930D
:100090008F939F930EB406FE0CC08EB58F7B8EBDE2
:1000A00010926B0186B597B5909376018093750198
:1000B00051C08EB580648EBD26B537B580916B0179
:1000C0008091750190917601281B390B3093740152
:1000D00020937301C9018955924087509740D0F50C
:1000E0002553384030F084E398E090937401809376
:1000F000730180917301909174018458934030F49E
:1001000084E893E0909374018093730120916000E0
:1001100030916100C901880F991F820F931F2091B0
:10012000730130917401820F931F96958795969570
:1001300087959093740180937301909361008093ED
:10014000600080916A01823328F480916A018F5F98
:1001500080936A019F918F914F913F912F910F90C2
:100160000FBE0F901F9018951F920F920FB60F920F
:1001700011242F933F938F939F9338B322B3809191
:1001800062018F5F809362018F3FE1F43E602863DC
:1001900080917C018093710180917801809370013E
:1001A00080917E0180936F018091790180936E012F
:1001B00080917D0180936D018091770180936C0126
:1001C000109262019091620180917101891709F486
:1001D000377F80917001891709F43B7F80916F010F
:1001E000891709F43D7F80916E01891709F4277FF3
:1001F00080916D01891709F42F7E80916C01891718
:1002000009F42F7D38BB22BB809172018F5F8093F0
:100210007201813259F41092720180917A019091A9
:100220007B01019690937B0180937A019F918F913E
:100230003F912F910F900FBE0F901F901895AC011A
:1002400020917A0130917B01232F3327E0917A01AD
:10025000F0917B0180917A0190917B01622F892F2F
:1002600099272817390739F080917A0190917B01FD
:10027000892F9927682F4F5F5F4F862F90E0982F27
:1002800088272E2F30E0822B932B840F951F089503
:10029000AC0120917A0130917B01232F3327E0912B
:1002A0007A01F0917B0180917A0190917B01622F1C
:1002B000892F99272817390739F080917A01909171
:1002C0007B01892F9927682F862F90E0982F882708
:1002D0002E2F30E0822B932B481B590B452F55278F
:1002E0004695842F807490E0089581E083BF89B79C
:1002F000816089BF08951FBC82EC8EBD89B784627E
:1003000089BF08952091600030916100232F332729
:100310006091600070916100809160009091610037
:10032000422F892F99272817390739F080916000CB
:1003300090916100892F9927482F842F90E0982F62
:100340008827262F30E0822B932B08952F923F92FF
:100350004F925F926F927F928F929F92AF92BF92D5
:10036000CF92DF92EF92FF920F931F93CF93DF9381
:10037000CDB7DEB722970FB6F894DEBF0FBECDBF64
:100380008EE087BB18BA88E084BB15BA88EB81BBC6
:1003900012BA10927C011092780110927E01109294
:1003A000790110927D01109277011FBC82EC8EBD05
:1003B00089B7846289BF81E083BF89B7816089BFC3
:1003C000789444E050E0DA015FD3A0E0B0E022E0AE
:1003D00030E0EA5AF545B9F080EB94E00C0159D3CE
:1003E00088E097E0D9010C0154D38AEA95E5DA0157
:1003F0000C014FD320EB422E24E0522E98E0292E00
:1004000097E0392E05C040D32F01D9013DD31F01FC
:1004100088E893E114DF9A83898388E893E10FDF0A
:100420005C0188EE93E00BDF6C0110E0662477241A
:1004300088248A94982C01C018E080916A01853143
:1004400080F0AB985FDF7C0184EF91E0F8DE5C0127
:100450006E147F0408F43701E814F90420F447010E
:1004600002C0AB9A7201C50113DF882331F088E81E
:1004700093E1E5DE5C0110926A01163008F039C0A4
:10048000F1E4EF16F6E0FF0618F010FD08C006C014
:1004900088E7E81685E0F80610F410FD1F5FC60136
:1004A000F7DE882399F080917C01809580937C0110
:1004B0008091780180958093780180917E0180956C
:1004C00080937E018AEF90E0BADE6C01163089F4E9
:1004D000979A88EB9BE0B3DE9A838983A0E0B0E033
:1004E0000401D7D2A2E0B0E00301D3D2240113016A
:1004F00002C01730C1F4C601CBDE882399F0809189
:100500007C01809580937C01809178018095809317
:10051000780180917E01809580937E0189E190E051
:100520008EDE6C0117E089819A81B2DE882311F09A
:10053000979803C0183009F080CFEEEFFFEFEE0E72
:10054000FF1EE418F5080027F7FC0095102F910115
:10055000241935092450304040E050E060E070EC50
:1005600084ED91E054D2C801B70132D220E23EE4DA
:1005700040E050E04CD2B90137FF03C060E070E0CA
:1005800005C02250364014F061E076E06F3F7105FF
:1005900009F030F460937C011092780110927E0192
:1005A000CB01805091408F3F910509F038F48FEFD7
:1005B00080937C011092780160937E01CB01805082
:1005C00092408F3F910509F048F4862F80958093E3
:1005D0007C01109278018FEF80937E01CB018050D7
:1005E00093408F3F910509F038F410927C0160939D
:1005F00078018FEF80937E01CB01805094408F3F34
:10060000910509F048F410927C018FEF80937801F6
:10061000862F809580937E01CB01805095408F3F3F
:10062000910509F038F460937C018FEF8093780195
:1006300010927E01605076400CF4FECE8FEF8093D6
:100640007C018093780110927E01F6CE1F93182FC3
:100650008A3011F48DE0FADF5D9BFECF1CB980E09B
:1006600090E01F910895599A88E18AB986E880BD83
:1006700089E189B960E070E086E293E03ED00895B8
:1006800082E682B985EC86BF08951F920F920FB65D
:100690000F9211248F939F9381B190E0887F907087
:1006A0008038910599F08138910534F40097C9F0AC
:1006B00080369105C9F40FC0883B910559F0883FF9
:1006C000910561F0883A910579F404C083B1809373
:1006D0007F0101C013B886B7806807C086B78069FC
:1006E00086BF86B7806986BF85EC86BF9F918F9154
:1006F0000F900FBE0F901F901895EF92FF920F93DF
:100700001F93CF93DF938C017B01892B11F4672B0F
:10071000C9F16EE070E081E090E03BD0FC01009711
:1007200089F1DC0180E88383E114F10471F0F38640
:10073000E28681E883838091800190918101892BF9
:1007400021F4F0938101E093800101151105E1F09E
:1007500011870087838182608383809182019091D9
:100760008301892B89F4F0938301E09382018091C6
:10077000840190918501892B39F4F0938501E093F0
:10078000840102C0A0E0B0E0CD01E6E0CDB7DEB765
:10079000A5C10F931F93CF93DF93689F8001699F3B
:1007A000100D789F100D1124C8010DD0EC01009799
:1007B00021F0A80160E070E004D1CE01DF91CF917B
:1007C0001F910F910895CF93DF93AC01029710F41E
:1007D00042E050E0A0918801B0918901FD01C0E0A4
:1007E000D0E020E030E020C080819181841795071F
:1007F00069F482819381209719F09B838A8304C0D6
:1008000090938901809388019F0132C0481759074E
:1008100038F42115310519F08217930708F49C016B
:10082000EF010280F381E02D3097F1F621153105BB
:1008300099F1C901841B950B049708F4A901E0E024
:10084000F0E028C08D919C91119782179307F9F4DD
:100850004817590781F4ED018A819B81309719F07F
:100860009383828304C090938901809388019D01C2
:100870002E5F3F4F4CC0841B950BFD01E80FF91F05
:100880004193519302978D939C939F0140C0FD012A
:10089000A281B3811097B1F6809186019091870172
:1008A000892B41F4809165019091660190938701B5
:1008B00080938601209167013091680121153105EF
:1008C00049F48DB7282F30E0809163019091640145
:1008D000281B390BA0918601B09187012A1B3B0B85
:1008E0002417350790F0CA0102962817390768F0D7
:1008F0009D012E5F3F4FC901840F951F9093870183
:10090000809386014D935C9302C020E030E0C901E2
:10091000DF91CF910895CF93DF93009709F44EC0F4
:10092000EC0122971B821A82A0918801B091890163
:10093000109711F140E050E001C0DC01AC17BD0799
:1009400000F1BB83AA83FE0121913191E20FF31FD5
:10095000EA17FB0771F48D919C911197280F391FAD
:100960002E5F3F4F39832883FD01828193819B83D2
:100970008A834115510559F4D0938901C0938801A8
:100980001DC0FD0182819381AD010097B1F6FA018E
:10099000D383C28321913191E20FF31FEC17FD073E
:1009A00069F488819981280F391F2E5F3F4FFA0122
:1009B000318320838A819B8193838283DF91CF91CE
:1009C0000895DC0101C06D9341505040E0F7089557
:1009D000629FD001739FF001829FE00DF11D649F23
:1009E000E00DF11D929FF00D839FF00D749FF00DAF
:1009F000659FF00D9927729FB00DE11DF91F639F50
:100A0000B00DE11DF91FBD01CF011124089597FB21
:100A1000092E05260ED057FD04D014D00AD0001C94
:100A200038F450954095309521953F4F4F4F5F4F8B
:100A30000895F6F790958095709561957F4F8F4F4B
:100A40009F4F0895A1E21A2EAA1BBB1BFD010DC0EA
:100A5000AA1FBB1FEE1FFF1FA217B307E407F5076E
:100A600020F0A21BB30BE40BF50B661F771F881F4A
:100A7000991F1A9469F760957095809590959B01E0
:100A8000AC01BD01CF01089509D0E02D07D0F02DB4
:100A900008950CD0012C0AD011240895E199FECFBD
:100AA000BFBBAEBBE09A11960DB20895E199FECF9F
:100AB000BFBBAEBB0DBA11960FB6F894E29AE19A9D
:100AC0000FBE08952A88398848885F846E847D84A3
:100AD0008C849B84AA84B984C884DF80EE80FD80E6
:100AE0000C811B81AA81B981CE0FD11D0FB6F8945C
:0C0AF000DEBF0FBECDBFED010895FFCFAB
:100AFC00F005000102030405060708090A0B0C0D9A
:100B0C000E0F000102030405060708090A0B0C0D61
:100B1C000E0F000102030405060708090A0B0C0D51
:100B2C000E0F000102030405060708090A0B0C0D41
:100B3C000E0F000102030405060708090A0B0C0D31
:100B4C000E0F000102030405060708090A0B0C0D21
:100B5C000E0F000102030405060708090A0B0C0D11
:100B6C000E0F000102030405060708090A0B0C0D01
:100B7C000E0F000102030405060708090A0B0C0DF1
:100B8C000E0F000102030405060708090A0B0C0DE1
:100B9C000E0F000102030405060708090A0B0C0DD1
:100BAC000E0F000102030405060708090A0B0C0DC1
:100BBC000E0F000102030405060708090A0B0C0DB1
:100BCC000E0F000102030405060708090A0B0C0DA1
:100BDC000E0F000102030405060708090A0B0C0D91
:100BEC000E0F000102030405060708090A0B0C0D81
:0A0BFC000E0FFE20008A0100000029
:00000001FF
/IR-TX-BL/branches/PWM-CTRL_V0.02/main.c
0,0 → 1,434
//############################################################################
// - PWM CTRL
// - Main
// - ATMEGA8 mit 8MHz
// - Nur für den privaten Gebrauch
// - Keine Garantie auf Fehlerfreiheit
// - Kommerzielle Nutzung nur mit meiner Zustimmung
// - walter Meyer @ www.freakware.de
// - 11.12.2007
// - Make sure Fuses are programmed for internal 8 MHz RC Oscilator
//############################################################################*/
 
#include "main.h"
#include "uart.h"
#include "twislave.h"
 
volatile unsigned int PPM_SIGNAL = 1520;
volatile unsigned char PPM_NEW = 0;
volatile unsigned char TMR1OvF = 0;
volatile unsigned int TMR1MS;
volatile unsigned char CH0;
volatile unsigned char CH1;
volatile unsigned char CH2;
volatile unsigned char CH3;
volatile unsigned char CH4;
volatile unsigned char CH5;
 
uint16_t EEMEM EEPMIN=0x0000;
uint16_t EEMEM EEPMAX=0xffff;
uint16_t EEMEM EEPSIG=0xffff;
 
 
//led kennlinie, (noch nicht implementiert, nur vorbereitet)
unsigned char kl[256]={
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
};
 
 
 
/*##############################################################################*/
SIGNAL(SIG_OVERFLOW1)
{
TMR1OvF++;
}
 
 
SIGNAL(SIG_INPUT_CAPTURE1)
{
static unsigned int pos_ICR;
static unsigned int ppm;
if ((TCCR1B & (1<<ICES1)) != 0) //rising edge
{
TCCR1B &= ~(1<<ICES1); //set falling egde
TMR1OvF = 0;
pos_ICR = ICR1;
}
else //falling edge
{
TCCR1B |= (1<<ICES1); //set rising egde
ppm = (ICR1 - pos_ICR + (int) TMR1OvF * 65536);
if ((ppm > 600) && (ppm < 2400))
{
if (ppm > 2100) ppm = 2100;
if (ppm < 900) ppm = 900;
ppm = (PPM_SIGNAL * 3 + ppm) / 4;
PPM_SIGNAL = ppm;
if (PPM_NEW < 50) PPM_NEW++;
}
}
 
}
 
/*##############################################################################*/
SIGNAL(SIG_OVERFLOW0)
{
// this function is called every 32us,
// it is very important that it's execution time is as short as possible
// currently it's about 20us
 
static unsigned char counter = 254;
static unsigned char ms1 = 0;
static unsigned char ch0_tmp = 0;
static unsigned char ch1_tmp = 0;
static unsigned char ch2_tmp = 0;
static unsigned char ch3_tmp = 0;
static unsigned char ch4_tmp = 0;
static unsigned char ch5_tmp = 0;
unsigned char PORTB_BAK;
unsigned char PORTD_BAK;
 
PORTB_BAK = PORTB;
PORTD_BAK = PORTD;
 
if (counter++ == 254)
{
PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); //new cycle, output on
PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); //
ch0_tmp = CH0;
ch1_tmp = CH1;
ch2_tmp = CH2;
ch3_tmp = CH3;
ch4_tmp = CH4;
ch5_tmp = CH5;
counter = 0;
}
 
if (ch0_tmp == counter) PORTB_BAK LEDOFF CH0_B; //channel value reached, output off
if (ch1_tmp == counter) PORTB_BAK LEDOFF CH1_B; //
if (ch2_tmp == counter) PORTB_BAK LEDOFF CH2_B; //
if (ch3_tmp == counter) PORTD_BAK LEDOFF CH3_D; //
if (ch4_tmp == counter) PORTD_BAK LEDOFF CH4_D; //
if (ch5_tmp == counter) PORTD_BAK LEDOFF CH5_D; //
PORTB = PORTB_BAK;
PORTD = PORTD_BAK;
if (ms1++ == 32)
{
ms1=0;
TMR1MS++;
}
 
 
 
}
 
 
/*##############################################################################*/
unsigned int SetDelay (unsigned int t)
{
unsigned char hi_byte;
unsigned char lo_byte;
 
hi_byte = (TMR1MS >> 8);
lo_byte = (TMR1MS & 0xff);
if (hi_byte != (TMR1MS >> 8)) hi_byte = (TMR1MS >> 8);
 
return(((hi_byte << 8) | lo_byte) + t + 1);
}
 
 
/*##############################################################################*/
char CheckDelay(unsigned int t)
{
unsigned char hi_byte;
unsigned char lo_byte;
 
hi_byte = (TMR1MS >> 8);
lo_byte = (TMR1MS & 0xff);
if (hi_byte != (TMR1MS >> 8)) hi_byte = (TMR1MS >> 8);
 
return(((t - ((hi_byte << 8) | lo_byte)) & 0x8000) >> 9);
}
 
 
 
/*##############################################################################*/
void StartPWM(void)
{
//Timer 0 Config
TCCR0 = (0<<CS02)|(0<<CS01)|(1<<CS00); // (@8MHz) = 1/8us Clk = 256/8 = 32us overflow
TIMSK setbit (1<<TOIE0); // enable Int
 
}
 
 
/*##############################################################################*/
void StartPPM(void)
{
//Timer1 Config
TCCR1A = (0<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)|
(0<<FOC1A) |(0<<FOC1B) |(0<<WGM10) |(0<<WGM11);
TCCR1B = (1<<ICNC1)|(1<<ICES1)|(0<<WGM13)|
(0<<WGM12)|(0<<CS12)|(1<<CS11)|(0<<CS10); //ICP_POS_FLANKE
 
// interrupts
TIMSK |= (1<<TICIE1)|(1<<TOIE1); //ICP_INT_ENABLE and TIMER1_INT_ENABLE
 
}
 
 
/*##############################################################################*/
unsigned int GetPPM(void)
{
//this routines seems to be nesseccary, as reading a 16 bit value
//on a 8 bit machine is not atomic, so if an interrupt apears between reading
//low and high byte of the 16 bit value a wrong result is possible
unsigned char temp_hi;
unsigned char temp_lo;
 
temp_hi = (PPM_SIGNAL >> 8);
temp_lo = (PPM_SIGNAL & 0xff);
if (temp_hi != (PPM_SIGNAL >> 8)) temp_hi = (PPM_SIGNAL >> 8);
return( (temp_hi << 8) | temp_lo);
 
}
 
 
/*##############################################################################*/
// MAIN
/*##############################################################################*/
int main (void)
{
 
#define STEP 256
#define MUL 1
#define REDUCE 2
#define EEPSIGNATURE 0x55aa
 
#define inimin 1200
#define inimax 1800
 
unsigned int ppm;
signed int color;
unsigned int setupdly;
unsigned int ppmtodly;
unsigned int flashdly;
unsigned char setup;
unsigned int lmax;
unsigned int lmin;
unsigned int max;
unsigned int min;
signed long temp1;
signed long temp2;
 
DDRB = (CH0_B|CH1_B|CH2_B);
PORTB = 0x00;
 
DDRC = (ledred);
PORTC = 0x00;
 
DDRD = (ledgreen|CH3_D|CH4_D|CH5_D);
PORTD = 0x00;
 
CH0 = 0;
CH1 = 0;
CH2 = 0;
CH3 = 0;
CH4 = 0;
CH5 = 0;
 
lmax = 0x0000;
lmin = 0xffff;
 
// StartUART();
StartPPM();
//StartI2C();
StartPWM();
sei();
 
min = inimin; //default min
max = inimax; //default max
 
if (eeprom_read_word(&EEPSIG) != EEPSIGNATURE) //check eep if signature is there
{
eeprom_write_word(&EEPMIN, min); //no, write initial min
eeprom_write_word(&EEPMAX, max); //and max values
eeprom_write_word(&EEPSIG, EEPSIGNATURE); //along with eep signature
}
else
{
 
min = eeprom_read_word(&EEPMIN); //signature ok
max = eeprom_read_word(&EEPMAX); //read min and max
}
 
 
setup = 0; //reset setup toggle counter
setupdly = SetDelay(5000);
ppmtodly = SetDelay(5000);
flashdly = SetDelay(1000);
while (1)
{
 
if (PPM_NEW > 20) //ppm Signal ok
{
PORTC clrbit ledred;
ppm = GetPPM();
ppmtodly = SetDelay(500); //reset timeout
if (lmax < ppm) lmax=ppm; //update impulse max
if (lmin > ppm) lmin=ppm; //and min boundarys
}
else
{
PORTC setbit ledred; //ppm signal not ok
ppm = min; //set ppm to minimum
}
 
if (CheckDelay(ppmtodly)) //timeout
{
ppmtodly = SetDelay(5000);
PPM_NEW = 0; //set ppm signal not ok
}
 
 
if (setup < 6)
{
if ((ppm > 1600) && ((setup&1)==0)) setup++; //
if ((ppm < 1400) && ((setup&1)==1)) setup++; //
 
if (CheckDelay(flashdly))
{
CH0 = CH0 ^ 0xff;
CH1 = CH1 ^ 0xff;
CH2 = CH2 ^ 0xff;
flashdly = SetDelay(250);
}
}
 
if (setup == 6) //if stick is toggled 6 times
{ //within setup timeout
PORTD setbit ledgreen; //store ppm min and max
setupdly = SetDelay(3000); //for 2000ms
eeprom_write_word(&EEPMIN, lmin); //in eeprom
eeprom_write_word(&EEPMAX, lmax);
min = lmin;
max = lmax;
setup = 7; //enter PWM toggle mode
 
}
 
 
if (setup == 7)
{
if (CheckDelay(flashdly)) //each 25ms toggle PWM's
{
CH0 = CH0 ^ 0xff;
CH1 = CH1 ^ 0xff;
CH2 = CH2 ^ 0xff;
flashdly = SetDelay(25);
}
}
 
if (CheckDelay(setupdly)) //setup timeout reached
{
setup = 8; //lockdown setup
PORTD clrbit ledgreen;
}
 
if (setup == 8)
{
 
temp1 = ((long)STEP * 6 * 20000) / ((max-REDUCE) - (min+REDUCE));
temp2 = (((int)ppm - ((int)min+REDUCE)) * temp1);
color = temp2 / 20000;
if (color < 0) color = 0;
if (color > ((STEP*6)+1)) color = ((STEP*6)+1);
 
//printf("p %u ",ppm);
//printf("pm %u ",(min+REDUCE));
//printf("t1 %li ",temp1);
//printf("t2 %li ",temp2);
//printf("c %i\n ",color);
// Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb >
if ((color >= (STEP * 0)) && (color < (STEP * 1)))
{
CH0 = MUL * ((color - (STEP * 0))); //fade in red > red (red only)
CH1 = 0;
CH2 = 0;
}
if ((color >= (STEP * 1)) && (color < (STEP * 2)))
{
CH0 = ((STEP-1) * MUL);
CH1 = 0;
CH2 = MUL * ((color - (STEP * 1))); //fade in blue > purple (red + blue)
}
if ((color >= (STEP * 2)) && (color < (STEP * 3)))
{
CH0 = MUL * ((STEP - 1) - (color - (STEP * 2))); //fade out red > blue (blue only)
CH1 = 0;
CH2 = ((STEP-1) * MUL);
}
if ((color >= (STEP * 3)) && (color < (STEP * 4)))
{
CH0 = 0;
CH1 = MUL * ((color - (STEP * 3))); //fade in green > cyan (blue + green)
CH2 = ((STEP-1) * MUL);
}
if ((color >= (STEP * 4)) && (color < (STEP * 5)))
{
CH0 = 0;
CH1 = ((STEP-1) * MUL);
CH2 = MUL * ((STEP - 1) - (color - (STEP * 4))); //fade out blue > green (green only)
}
if ((color >= (STEP * 5)) && (color < (STEP * 6)))
{
CH0 = MUL * ((color - (STEP * 5))); //fade in red > yellow (green + red)
CH1 = ((STEP-1) * MUL);
CH2 = 0;
}
if (color >= (STEP * 6))
{
CH0 = ((STEP-1) * MUL); //fade in red > yellow (green + red)
CH1 = ((STEP-1) * MUL);
CH2 = 0;
}
}
 
 
}
 
}
 
/IR-TX-BL/branches/PWM-CTRL_V0.02/main.h
0,0 → 1,40
#ifndef _MAIN_H
#define _MAIN_H
 
 
#define SYSCLK 8000000L
 
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
 
 
#define setbit |=
#define clrbit &=~
#define invbit ^=
//#define correction -60
 
#define LEDON setbit
#define LEDOFF clrbit
 
#define ledred (1<<3) //on Port C
#define ledgreen (1<<7) //on Port D
 
#define CH0_B (1<<3)
#define CH1_B (1<<2)
#define CH2_B (1<<1)
#define CH3_D (1<<3)
#define CH4_D (1<<4)
#define CH5_D (1<<5)
 
 
#endif //_MAIN_H
 
 
 
 
 
/IR-TX-BL/branches/PWM-CTRL_V0.02/makefile
0,0 → 1,387
#--------------------------------------------------------------------
# MCU name
MCU = atmega8
#-------------------------------------------------------------------
HAUPT_VERSION = 0
NEBEN_VERSION = 02
#-------------------------------------------------------------------
 
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
 
# Target file name (without extension).
TARGET = PWM-CTRL_V$(HAUPT_VERSION)_$(NEBEN_VERSION)
 
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
 
##########################################################################################################
# List C source files here. (C dependencies are automatically generated.)
SRC = main.c uart.c twislave.c
##########################################################################################################
 
# If there is more than one source file, append them above, or modify and
# uncomment the following:
#SRC += foo.c bar.c
 
# You can also wrap lines by appending a backslash to the end of the line:
#SRC += baz.c \
#xyzzy.c
 
 
 
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
 
 
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
EXTRAINCDIRS =
 
 
# Optional compiler flags.
# -g: generate debugging information (for GDB, or for COFF conversion)
# -O*: optimization level
# -f...: tuning, see gcc manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create assembler listing
CFLAGS = -g -O$(OPT) \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
-Wall -Wstrict-prototypes \
-Wa,-adhlns=$(<:.c=.lst) \
$(patsubst %,-I%,$(EXTRAINCDIRS))
 
 
# Set a "language standard" compiler flag.
# Unremark just one line below to set the language standard to use.
# gnu99 = C99 + GNU extensions. See GCC manual for more information.
#CFLAGS += -std=c89
#CFLAGS += -std=gnu89
#CFLAGS += -std=c99
CFLAGS += -std=gnu99
 
CFLAGS += -DVERSION_HAUPTVERSION=$(HAUPT_VERSION) -DVERSION_NEBENVERSION=$(NEBEN_VERSION)
 
ifeq ($(AVR_CTRL_PLATINE), 1)
CFLAGS += -DAVR_CTRL_PLATINE=$(AVR_CTRL_PLATINE)
endif
 
 
 
# Optional assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
 
 
 
# Optional linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
 
 
 
# Additional libraries
 
# Minimalistic printf version
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
 
# Floating point printf version (requires -lm below)
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
 
# -lm = math library
LDFLAGS += -lm
 
 
 
 
# Programming support using avrdude. Settings and variables.
 
# Programming hardware: alf avr910 avrisp bascom bsd
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
#
# Type: avrdude -c ?
# to get a full listing.
#
 
AVRDUDE_PROGRAMMER = ponyser
#AVRDUDE_PROGRAMMER = stk200
 
#AVRDUDE_PORT = com1 # programmer connected to serial device
AVRDUDE_PORT = com1
 
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
 
AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
 
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE += -y
 
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_FLAGS += -V -E noreset
 
 
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_FLAGS += -v -v
 
 
 
 
# ---------------------------------------------------------------------------
 
# Define directories, if needed.
DIRAVR = c:/winavr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
 
 
# Define programs and commands.
SHELL = sh
 
CC = avr-gcc
 
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
 
 
# Programming support using avrdude.
AVRDUDE = avrdude
 
 
REMOVE = rm -f
COPY = cp
 
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
 
 
 
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
 
 
 
 
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
 
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
 
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
 
 
 
# Default target.
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
$(TARGET).lss $(TARGET).sym sizeafter finished end
 
 
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
 
finished:
@echo $(MSG_ERRORS_NONE)
 
end:
@echo $(MSG_END)
@echo
 
 
# Display size of file.
sizebefore:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
 
sizeafter:
@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
 
 
 
# Display compiler version information.
gccversion :
@$(CC) --version
 
 
 
 
# Convert ELF to COFF for use in debugging / simulating in
# AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
 
 
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
 
 
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
 
 
 
 
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
 
 
 
 
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
 
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
 
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S $< > $@
 
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
avr-nm -n $< > $@
 
 
 
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
 
 
# Compile: create object files from C source files.
%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
 
 
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
 
 
# Assemble: create object files from assembler source files.
%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
 
 
 
 
 
 
# Target: clean project.
clean: begin clean_list finished end
 
clean_list :
@echo
@echo $(MSG_CLEANING)
# $(REMOVE) $(TARGET).hex
# $(REMOVE) $(TARGET).eep
# $(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
 
 
# Automatically generate C source code dependencies.
# (Code originally taken from the GNU make user manual and modified
# (See README.txt Credits).)
#
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
# (see the SHELL variable defined above).
# This may not work with other shells or other seds.
#
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
[ -s $@ ] || rm -f $@
 
 
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
 
 
 
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
clean clean_list program
 
 
 
/IR-TX-BL/branches/PWM-CTRL_V0.02/twislave.c
0,0 → 1,62
//############################################################################
// - PWM CTRL
// - ATMEGA8 mit 8MHz
// - Nur für den privaten Gebrauch
// - Keine Garantie auf Fehlerfreiheit
// - Kommerzielle Nutzung nur mit meiner Zustimmung
// - walter Meyer @ www.freakware.de
//############################################################################*/
#include <avr/io.h>
#include <util/twi.h>
#include "main.h"
#include "twislave.h"
 
unsigned char I2C_IN;
 
 
//############################################################################
//I2C (TWI) Interface Init
void StartI2C(void)
//############################################################################
{
TWAR = 0x62; //I2C client address
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE) | (1<<TWEA);
}
 
//############################################################################
//ISR, die bei einem Ereignis auf dem Bus ausgelöst wird. Im Register TWSR befindet
//sich dann ein Statuscode, anhand dessen die Situation festgestellt werden kann.
SIGNAL (TWI_vect)
//############################################################################
{
switch (TWSR & 0xF8)
{
case SR_SLA_ACK:
TWCR |= (1<<TWINT);
return;
 
case SR_PREV_ACK: //receive
I2C_IN = TWDR;
TWCR |= (1<<TWINT);
return;
 
case SW_SLA_ACK: //send 0x00
TWDR = 0x00;
TWCR |= (1<<TWINT);
return;
 
case SW_DATA_ACK: //send 0x00
TWDR = 0x00;
TWCR |= (1<<TWINT);
return;
 
case TWI_BUS_ERR_2: //bus error / reset bus
TWCR |=(1<<TWSTO) | (1<<TWINT);
 
case TWI_BUS_ERR_1: //bus error / reset bus
TWCR |=(1<<TWSTO) | (1<<TWINT);
}
TWCR =(1<<TWEA) | (1<<TWINT) | (1<<TWEN) | (1<<TWIE); // TWI Reset
}
 
 
/IR-TX-BL/branches/PWM-CTRL_V0.02/twislave.h
0,0 → 1,31
#ifndef _TWI_SLAVE_H_
#define _TWI_SLAVE_H_
 
extern unsigned char I2C_IN;
 
extern void StartI2C(void);
 
#define TWI_BUS_ERR_1 0x00
#define TWI_BUS_ERR_2 0xF8
 
// Status Slave RX Mode
#define SR_SLA_ACK 0x60
#define SR_LOST_ACK 0x68
#define SR_GEN_CALL_ACK 0x70
#define GEN_LOST_ACK 0x78
#define SR_PREV_ACK 0x80
#define SR_PREV_NACK 0x88
#define GEN_PREV_ACK 0x90
#define GEN_PREV_NACK 0x98
#define STOP_CONDITION 0xA0
#define REPEATED_START 0xA0
 
// Status Slave TX mode
#define SW_SLA_ACK 0xA8
#define SW_LOST_ACK 0xB0
#define SW_DATA_ACK 0xB8
#define SW_DATA_NACK 0xC0
#define SW_LAST_ACK 0xC8
 
#endif
 
/IR-TX-BL/branches/PWM-CTRL_V0.02/uart.c
0,0 → 1,38
//############################################################################
// - PWM CTRL
// - ATMEGA8 mit 8MHz
// - Nur für den privaten Gebrauch
// - Keine Garantie auf Fehlerfreiheit
// - Kommerzielle Nutzung nur mit meiner Zustimmung
// - walter Meyer @ www.freakware.de
//############################################################################*/
 
#include "main.h"
#include "uart.h"
 
void StartUART(void)
{
// UART Double Speed (U2X)
UCSRA |= (1<<U2X);
/* Enable receiver and transmitter, no RX Int, no TX Int */
UCSRB = (1<<RXEN)|(1<<TXEN); // (1<<RXCIE)|(1<<TXCIE)
/* Set frame format: 8data, 1stop bit */
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
 
//Teiler wird gesetzt
UBRRL= (SYSCLK / (BAUD_RATE * 8L) -1 );
 
//öffnet einen Kanal für printf (STDOUT)
fdevopen (uart_putchar, NULL);
 
}
 
int uart_putchar (char c)
{
if (c == '\n') uart_putchar('\r');
loop_until_bit_is_set(UCSRA, UDRE);
UDR = c;
return (0);
}
/IR-TX-BL/branches/PWM-CTRL_V0.02/uart.h
0,0 → 1,11
#ifndef _UART_H
#define _UART_H
 
extern void StartUART (void);
extern int uart_putchar (char c);
 
 
#define BAUD_RATE 38400 //Baud Rate für die Serielle Schnittstelle
 
 
#endif //_UART_H