Using FOC on ATmega16/32

1 post / 0 new
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to use FOC0 to generate a single pulse.
The progam to achieve this is interrupt-driven.
The idea is to use T0ovf to start the pulse and to end it when an output-compare occurs. I intended to use the FOC0 bit to force a compare and set the output according to the state of the COM00,01 bits. For some strange reason, I have not been able to set the OC0-output to "1" with the following code:

in r16,TCCR0
ori r16,$30 ;COM00,01=11 > set output to 1 on compare match
out TCCR0,r16 ;write COM-bits
ori r16,$80 ;FOC0=1
out TCCR0,r16 ;this should force OC0 to become "1" ??

The code above is part of the T0ovf interrupt routine. Timer0 is running in normal mode with external clocking at about 40kHz. The initial condition is OC0=0, the corresponding IO-bit has been set as output.
When using toggle-mode (COM00,01= 1,0) the output level is altered on a compare-match so there should not be any programming errors other but I have been unsuccessfull with writing to FOC0. The output level simply does not change. The problem occurs with the simulator and on the STK500.
It looks as if the timer MUST pass through zero to accept a change in the mode of operation although I have not been able to find this requirement in the datasheets.

Any ideas?