dslocum
Newbie level 5
I'm using MikroC Pro for PIC24. Reasonably comfortable in C, but this has been difficult problem for many hours.
My hardware uses an electronic attenuator chip that works just fine. I can program it to 'attenuate' for 0 (full volume) to 127 (minimum volume / mute). That works great. Simple stripped down code below, raises and lowers the volume thru the full range of the chip (works). I left off obvious declarations, etc for clarity.
Instead of attenuation, I want to have the volume increase from minimum at 0, to maximum at 127. I should be able to simply do the following to subtract 'i' from 127, right? It doesn't work.
I've tried unsigned, signed, shorts, chars, ints, variables of 127 in place of literals. No joy here today.
Watching variables while single stepping in the debugger seems OK. What am I not seeing?
My hardware uses an electronic attenuator chip that works just fine. I can program it to 'attenuate' for 0 (full volume) to 127 (minimum volume / mute). That works great. Simple stripped down code below, raises and lowers the volume thru the full range of the chip (works). I left off obvious declarations, etc for clarity.
Code:
void Vol_Output(unsigned short channel, unsigned short valueVOL) {
unsigned short temp;
// Send address Byte
Vol_Write_Byte(channel);
// Send volume value Byte
Vol_Write_Byte(valueVOL);
}
void main(void) {
unsigned short i;
// init stuff here...
while(1) {
for(i=0; i<127; i++) { //
Vol_Output(0, i);
Delay_ms(10);
}
for(i=127; i>0; i--) {
Vol_Output(0, i);
Delay_ms(10);
}
}
}
Instead of attenuation, I want to have the volume increase from minimum at 0, to maximum at 127. I should be able to simply do the following to subtract 'i' from 127, right? It doesn't work.
I've tried unsigned, signed, shorts, chars, ints, variables of 127 in place of literals. No joy here today.
Watching variables while single stepping in the debugger seems OK. What am I not seeing?
Code:
void Vol_Output(unsigned short channel, unsigned short valueVOL) {
unsigned short temp;
// Send address Byte
Vol_Write_Byte(channel);
// added this to 'invert' the input volume
temp = 127 - valueVOL;
// Send volume value Byte
Vol_Write_Byte(temp);
}
void main(void) {
unsigned short i;
// init stuff here...
while(1) {
for(i=0; i<127; i++) { //
Vol_Output(0, i);
Delay_ms(10);
}
for(i=127; i>0; i--) {
Vol_Output(0, i);
Delay_ms(10);
}
}
}