MrMikey83
New Member
This code is supposed to sense the input from a radio receiver. I wish I had an O'scope so I could see the receiver output and know for certain what kind of wavefor it is, but I dont feel like spending $1000 on one right now.
The receiver outputs a 1ms to 2ms signal. The ATmega32 needs to be able to read this and store the result.
I tried Timer0 instead of Timer1 and finally was able to get the timer running, but when I use it in my code, I dont get anything.
PWMin is where I have the receiver connected. timeUP, timeDOWN and pulse are variables. The printf lines are for me to see what is hapenning when I run it. The Terminal output looks like this...
|13|0|0|
|128|0|0|
|231|0|0|
|19|0|0|
|132|0|0|
|251|0|0|
...
The first number is the timer. The second is my "pulse" output. The third is to monitor the overflow. As you can see, the "pulse" code didn't work, but also, the overflow isn't counting up either. I have an overflow interupt which increments the variable ov_counter.
I have altered the code and I get a slightly better result...
...and heres the output...
|82|0|80|80|0|
|175|0|173|173|0|
|35|0|33|33|0|
|128|0|126|126|0|
|244|0|242|242|0|
...
Key:
|TCNT0|timeUP|timeDOWN|pulse|ov_counter|
As you can see, it too is not doing the job I wish it to do.
It doesn't seem to be storing the time for the timeUP.
The overflow counter also doesn't seem to work. Isn't it supposed to trigger the interrupt (not shown above) when the counter reaches 255 and rolls over?
Thanks
~Mike
The receiver outputs a 1ms to 2ms signal. The ATmega32 needs to be able to read this and store the result.
I tried Timer0 instead of Timer1 and finally was able to get the timer running, but when I use it in my code, I dont get anything.
PWMin is where I have the receiver connected. timeUP, timeDOWN and pulse are variables. The printf lines are for me to see what is hapenning when I run it. The Terminal output looks like this...
|13|0|0|
|128|0|0|
|231|0|0|
|19|0|0|
|132|0|0|
|251|0|0|
...
The first number is the timer. The second is my "pulse" output. The third is to monitor the overflow. As you can see, the "pulse" code didn't work, but also, the overflow isn't counting up either. I have an overflow interupt which increments the variable ov_counter.
Code:
while (1)
{
if(PWMin == 1)
{
timeUP = TCNT0;
}
else
{
timeDOWN = TCNT0;
}
pulse = (timeDOWN - timeUP) / 500;
printf("|%d|", TCNT0);
printf("%d|", pulse);
printf("%d|", ov_counter);
putchar(13);
delay_ms(300);
};
}
I have altered the code and I get a slightly better result...
Code:
while (1)
{
if(PWMin == 1)
{
timeUP = TCNT0;
}
if(PWMin == 0)
{
timeDOWN = TCNT0;
}
pulse = (timeDOWN - timeUP);
printf("|%d|", TCNT0);
printf("%d|", timeUP);
printf("%d|", timeDOWN);
printf("%d|", pulse);
printf("%d|", ov_counter);
putchar(13);
delay_ms(300);
};
...and heres the output...
|82|0|80|80|0|
|175|0|173|173|0|
|35|0|33|33|0|
|128|0|126|126|0|
|244|0|242|242|0|
...
Key:
|TCNT0|timeUP|timeDOWN|pulse|ov_counter|
As you can see, it too is not doing the job I wish it to do.
It doesn't seem to be storing the time for the timeUP.
The overflow counter also doesn't seem to work. Isn't it supposed to trigger the interrupt (not shown above) when the counter reaches 255 and rolls over?
Thanks
~Mike