It would be interesting to see the disassemble of your new C program. Would you mind posting it here?
if (counter1 == 0) {counter1 = 112; fbi(PORTB, 0);}
00000097 CPSE R2,R1 Compare, skip if equal
00000098 RJMP PC+0x0006 Relative jump
00000099 LDI R25,0x70 Load immediate
0000009A MOV R2,R25 Copy register
0000009B IN R25,0x05 In from I/O location
0000009C EOR R25,R24 Exclusive OR
0000009D OUT 0x05,R25 Out to I/O location
while(1)
{
/* Check if counter is over the top */
if (counter1-- == 0) {counter1 = 112; fbi(PORTB, 0);}
if (counter2-- == 0) {counter2 = 119; fbi(PORTB, 0);}
if (counter3-- == 0) {counter3 = 126; fbi(PORTB, 0);}
if (counter4-- == 0) {counter4 = 134; fbi(PORTB, 0);}
if (counter5-- == 0) {counter5 = 141; fbi(PORTB, 0);}
if (counter6-- == 0) {counter6 = 150; fbi(PORTB, 0);}
if (counter7-- == 0) {counter7 = 159; fbi(PORTB, 0);}
if (counter8-- == 0) {counter8 = 168; fbi(PORTB, 0);}
if (counter9-- == 0) {counter9 = 178; fbi(PORTB, 0);}
if (counter10-- == 0) {counter10 = 189; fbi(PORTB, 0);}
if (counter11-- == 0) {counter11 = 200; fbi(PORTB, 0);}
if (counter12-- == 0) {counter12 = 212; fbi(PORTB, 0);}
}
if(--counter1 ==0){counter1 =112; fbi(PORTB,0);}
62 cycles best case.
if (--counter3 == 0) {counter3 = 126; fbi(PORTB, 0);}
00000091 MOV R25,R4 Copy register
00000092 SUBI R25,0x01 Subtract immediate
00000093 BRNE PC+0x02 Branch if not equal
00000094 RJMP PC+0x0046 Relative jump
00000095 MOV R4,R25 Copy register
...
if (--counter3 == 0) {counter3 = 126; fbi(PORTB, 0);}
000000D6 MOV R25,R4 Copy register
000000D7 SUBI R25,0x01 Subtract immediate
000000D8 BREQ PC+0x02 Branch if equal
000000D9 RJMP PC-0x0044 Relative jump
000000DA LDI R26,0x7E Load immediate
000000DB MOV R4,R26 Copy register
000000DC IN R25,0x05 In from I/O location
000000DD EOR R25,R24 Exclusive OR
000000DE OUT 0x05,R25 Out to I/O location
if (counter3-- == 0) {counter3 = 126; fbi(PORTB, 0);}
0000008F TST R4 Test for Zero or Minus
00000090 BREQ PC+0x36 Branch if equal
00000091 DEC R4 Decrement
...
if (counter3-- == 0) {counter3 = 126; fbi(PORTB, 0);}
000000C4 CPSE R4,R1 Compare, skip if equal
000000C5 RJMP PC-0x0034 Relative jump
000000C6 LDI R26,0x7E Load immediate
000000C7 MOV R4,R26 Copy register
000000C8 IN R25,0x05 In from I/O location
000000C9 EOR R25,R24 Exclusive OR
000000CA OUT 0x05,R25 Out to I/O location
00000093 BRNE PC+0x02 Branch if not equal
00000094 RJMP PC+0x0046 Relative jump
00000090 BREQ PC+0x36 Branch if equal
00000091 MOV R25,R4 Copy register
...
00000095 MOV R4,R25 Copy register
0000008F TST R4 Test for Zero or Minus
...
00000091 DEC R4 Decrement
000000C6 LDI R26,0x7E Load immediate
000000C7 MOV R4,R26 Copy register
LDI R4,0x7E
NorthGuy, MisterT and all who helped me: THANK YOU !!!
What is the meaning of those "--" as in here --counter3 == 0?
I seem to recall something like "++"...
Non conversant in C.
It did miss some obvious things in both cases:
Code:000000C6 LDI R26,0x7E Load immediate 000000C7 MOV R4,R26 Copy register
You can replace this with
Code:LDI R4,0x7E
But this is in the "slow" part of the code, so it doesn't matter much in this case.
Those are increment and decrement operations.
x++;
is same as
x = x+1;
Now, if you do some other operations in the same "sentence", like comparison:
x++ == 0
that means "first compare and then add one to x". This is called post increment.
++x == 0
means "first add one to x, then compare". This is called pre increment.
Same thing with minus signs, but that is decrement by one, of course.
So,
--counter3 == 0
means "first subtract one from counter3 and then compare (against zero)".
pitch 36 is 207.652
pitch 37 is 220.000
pitch 38 is 233.082
pitch 39 is 246.942
pitch 40 is 261.626
pitch 41 is 277.183
pitch 42 is 293.665
pitch 43 is 311.127
pitch 44 is 329.628
pitch 45 is 349.228
pitch 46 is 369.994
pitch 47 is 391.995
a) have you found the way to output the 12 outputs simultaneously, that is, each one through one of 12 pins?
b) are you actually generating the frequencies in the list above?
c) Why 432 and not 440? Could have been 434 or 438 as well?
d) Are you going to post a detailed explanation of how the strings are plucked?
Yes, but because I am also using VUSB the cpu is quite busy, so the precision of the PWM / timer is not as great as I wanted (in the higher frequencies).
for (i = 0; i <12; i++) {
if (z&mask) {
if(i > 7) {
PORTE ^= (1 << (i - 8));
} else {
PORTB ^= (1 << i);
}
x[(p+f[i])&MASK] |= mask;
}
mask <<= 1;
}
PORTE ^= z >> 8;
PORTB ^= z; // assumes 8-bit CPU
for (i = 0; i <12; i++) {
if (z&mask) {
x[(p+f[i])&MASK] |= mask;
}
mask <<= 1;
}
The strings are not plucked, but they vibrate because of the magnetic field produce by the coils.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?