BAM code for C18, 128 steps at circa 200Hz
/******************************************************************************
* Function: void high_isr(void)
* PreCondition: None
* Input:
* Output:
* Side Effects:
* Overview:
*****************************************************************************/
#pragma interrupt high_isr nosave=section("MATH_DATA"),section(".tmpdata")
void high_isr(void) {
// static byte Timer64RGB; messo sopra x ACCESSBANK
// static byte i,phase; // idem x velocità!
//static byte divider;
// if(INTCONbits.TMR0IF) { // Timer 0 .. c'è solo questo, VELOCIZZO!
//75uS 26/11/10
// WriteTimer0(TMR0BASE); // reinizializzo TMR0
// in questo modo evito overhead nell'interrupt... causa chiamata di funzione!
// TMR0L=0;
// TMR0H=0;
// if(Timer64RGB==0)
// TMR0L=248;
// else
// TMR0L=TMR0BASE-(1 << Timer64RGB); //200Hz
// TMR0L=TMR0BASE-(2 << Timer64RGB); //100Hz mi sembra ok e va meglio visto overhead in irq
// meglio spezzando...
// i=pow2value64*2; //2<< Timer64RGB;
// i+=128;
TMR0L=(byte)255-pow2value64;
// 2/2/2011: il timeslice + lungo è 3mS, considerando il mirror BAM-MAB dovremmo avere quindi 160Hz nel peggior caso..
//TMR0H=50;
//divider++;
//if(divider)
//return;
//if(!(divider & (1<<Timer64RGB)))
//return;
// i_temp=r_timeslice[Timer64RGB];
FSR0L=(byte)r_timeslice+Timer64RGB; //PERICOLOSO! ma va
FSR0H=0;
// i_temp=INDF0;
if(INDF0 & 1)
m_RPWMO1Bit = 1;
else
m_RPWMO1Bit = 0;
// m_RPWMO1Bit = Timer64RGB < RGBValue[0][0] ? 1 : 0; e' + veloce come sopra...
if(INDF0 & 2)
m_RPWMO2Bit = 1;
else
m_RPWMO2Bit = 0;
if(INDF0 & 4)
m_RPWMO3Bit = 1;
else
m_RPWMO3Bit = 0;
if(INDF0 & 8)
m_RPWMO4Bit = 1;
else
m_RPWMO4Bit = 0;
if(INDF0 & 16)
m_RPWMO5Bit = 1;
else
m_RPWMO5Bit = 0;
if(INDF0 & 32)
m_RPWMO6Bit = 1;
else
m_RPWMO6Bit = 0;
if(INDF0 & 64)
m_RPWMO7Bit = 1;
else
m_RPWMO7Bit = 0;
if(INDF0 & (char)128)
m_RPWMO8Bit = 1;
else
m_RPWMO8Bit = 0;
// i_temp=g_timeslice[Timer64RGB];
FSR0L=(byte)g_timeslice+Timer64RGB; //PERICOLOSO! ma va
// FSR0H=0;
// i_temp=INDF0;
if(INDF0 & 1)
m_GPWMO1Bit = 1;
else
m_GPWMO1Bit = 0;
if(INDF0 & 2)
m_GPWMO2Bit = 1;
else
m_GPWMO2Bit = 0;
if(INDF0 & 4)
m_GPWMO3Bit = 1;
else
m_GPWMO3Bit = 0;
if(INDF0 & 8)
m_GPWMO4Bit = 1;
else
m_GPWMO4Bit = 0;
if(INDF0 & 16)
m_GPWMO5Bit = 1;
else
m_GPWMO5Bit = 0;
if(INDF0 & 32)
m_GPWMO6Bit = 1;
else
m_GPWMO6Bit = 0;
if(INDF0 & 64)
m_GPWMO7Bit = 1;
else
m_GPWMO7Bit = 0;
if(INDF0 & (char)128)
m_GPWMO8Bit = 1;
else
m_GPWMO8Bit = 0;
// i_temp=b_timeslice[Timer64RGB];
FSR0L=(byte)b_timeslice+Timer64RGB; //PERICOLOSO! ma va
// FSR0H=0;
// i_temp=INDF0;
if(INDF0 & 1)
m_BPWMO1Bit = 1;
else
m_BPWMO1Bit = 0;
if(INDF0 & 2)
m_BPWMO2Bit = 1;
else
m_BPWMO2Bit = 0;
if(INDF0 & 4)
m_BPWMO3Bit = 1;
else
m_BPWMO3Bit = 0;
if(INDF0 & 8)
m_BPWMO4Bit = 1;
else
m_BPWMO4Bit = 0;
if(INDF0 & 16)
m_BPWMO5Bit = 1;
else
m_BPWMO5Bit = 0;
if(INDF0 & 32)
m_BPWMO6Bit = 1;
else
m_BPWMO6Bit = 0;
if(INDF0 & 64)
m_BPWMO7Bit = 1;
else
m_BPWMO7Bit = 0;
if(INDF0 & (char)128)
m_BPWMO8Bit = 1;
else
m_BPWMO8Bit = 0;
if(phase & 1) {
pow2value64>>=1;
if(Timer64RGB == 0) {
pow2value64=1;
if(phase & 2) {
phase=0;
}
else {
phase |= 2;
}
}
else
Timer64RGB--;
}
else {
pow2value64<<=1;
if(Timer64RGB == 7) {
if(phase & 2) {
pow2value64=128;
phase=1;
}
else {
phase |= 2;
}
}
else
Timer64RGB++;
}
INTCONbits.TMR0IF=0; // clear bit IRQ
// DOPO che lo uso anche come semaforo, v. converti timeslices
// m_Led2Bit ^= 1; //check timer
// } //if timer...
}
//this function creates the "timeslices" for the BAM
// encode an array of 8 LED brightness bytes into the pattern
// to be shown on the port for each of the 8 timeslices.
void led_encode_timeslices(void) {
overlay byte portbits;
overlay byte bitvalue,bitpos,bitposB,ledpos;
/*
RGBValue[0][0] =1;
RGBValue[1][0] =2;
RGBValue[2][0] =4;
RGBValue[3][0] =8;
RGBValue[4][0] =32;
RGBValue[5][0] =64;
RGBValue[6][0] =128;
RGBValue[7][0] =240;
*/
while(Timer64RGB) // asp per non disturbare
ClrWdt();
// opp. copiare questi valori in 24 variabili specchio, e in interrupt, all'istante 8, copiarle in quelle vere..
//http://www.microchip.com/forums/tm.aspx?high=&m=538239&mpage=1#554351, anche per il problema del "salto" tra 127 e 128
for(bitpos=0,bitposB=1; bitposB; bitpos++,bitposB<<=1) {
portbits = 0;
for(ledpos=0,bitvalue=1; ledpos<8; ledpos++,bitvalue<<=1) {
if(RGBValue[ledpos][0] & bitposB)
portbits |= bitvalue;
}
r_timeslice[bitpos] = portbits;
}
for(bitpos=0,bitposB=1; bitposB; bitpos++,bitposB<<=1) {
portbits = 0;
bitvalue = 1;
for(ledpos=0,bitvalue=1; ledpos<8; ledpos++,bitvalue<<=1) {
if(RGBValue[ledpos][1] & bitposB)
portbits |= bitvalue;
}
g_timeslice[bitpos] = portbits;
}
for(bitpos=0,bitposB=1; bitposB; bitpos++,bitposB<<=1) {
portbits = 0;
bitvalue = 1;
for(ledpos=0,bitvalue=1; ledpos<8; ledpos++,bitvalue<<=1) {
if(RGBValue[ledpos][2] & bitposB)
portbits |= bitvalue;
}
b_timeslice[bitpos] = portbits;
}
}