Setting OCR0A for Phase Correct Non-Inverted PWM

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I run a simulation and try to set OCR0A in a function and change it in a ISR the value is never copied to OCR0A, yet when I set OCR0A in the main it works just fine. Is there something I need to declare in order to make OCR0A accessible within the scope of a function or to make it global? I was thinking of using a pointer for OCR0A so that I can set it in the function, but I wasn't sure why a register would be accessible from a function. I'm using AVR Studio 4.18 SP1, ATMega88PA @20MHz. Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Is there something I need to declare in order to make OCR0A accessible within the scope of a function or to make it global?

No, as a register it is already global and volatile.
Quote:
When I run a simulation and try to set OCR0A in a function and change it in a ISR the value is never copied to OCR0A

Are you sure about this? In PWM mode, OCR0A is double buffered. The actual value of OCR0A will not change until TOP is reached.

Also, keep in mind that this is a simulator. There is no guarantee that the simulation is correct.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

There is no guarantee that the simulation is correct.

Too true - but at least it's a mega88PA so make sure you are using Sim2, not Sim1 - you have a bit more hope that it might work a bit like the real thing.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'll have to take another look, but I thought it was quite strange myself. Perhaps I'll for go the simulator for now and test directly on the micro-controller. Thanks for the info guys.