![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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. 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);
}; |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
__________________ All Electronic components run on smoke. Let the smoke out and it no longer works. ~Tim Baker (Electronics Instructor at John A. Logan College) | |
| |
| | (permalink) |
| I would answer your post but i dont understand ' C ' | |
| |
| | (permalink) |
| Likewise, I don't understand C either, plus the code section assumes an understanding of how Atmel processors work. For a start though, why are you trying to use hardware timers?. Use a simple software loop, there's far less demand on knowing what the hardware is doing. Something like this Zero counter Wait until pin is high Loop: Increment Count If pin high then goto Loop You will probably need Count to be a multi-byte counter, or introduce a delay in the counting process. | |
| |
| | (permalink) |
| Aha! Thanks Nigel, I hadn't thought of doing it that way. ~Mike
__________________ All Electronic components run on smoke. Let the smoke out and it no longer works. ~Tim Baker (Electronics Instructor at John A. Logan College) | |
| |
| | (permalink) |
| OK, I tried it that way and still no good. Code: count = 0;
timeUP = count;
while (input == 0)
{
//delay_us(1);
++count;
}
timeDOWN = count;
__________________ All Electronic components run on smoke. Let the smoke out and it no longer works. ~Tim Baker (Electronics Instructor at John A. Logan College) | |
| |
| | (permalink) |
| what would comments have to do with it?. unless it is interpreted C? anyway i bought a scope used for $ 125 I'm sure you can find one , you just gotta look.. | |
| |
| | (permalink) |
| Well, I meant that I had tried it with and without the delay.
__________________ All Electronic components run on smoke. Let the smoke out and it no longer works. ~Tim Baker (Electronics Instructor at John A. Logan College) | |
| |
| | (permalink) |
| which software do you use? i use the Keil C, when press 'Debug'\'Start/Stop Debug Session', then into the debug window, on the left of the window, i can see the time.
__________________ let me try! | |
| |