2.3.1 TCA0 Setup
TCA0 is a 16-bit timer/counter with three compare channels and six PWM outputs. In order to create a realistic application heartbeat, two PWM signals are needed, generated using two compare channels.
To create a heartbeat of approximately 60 bpm, the timer setup needs to be as follows:
- Divide system clock by 1024
- Set period register to 5000
- Enable compare channel 0 and set the compare value to 1500
- Enable compare channel 1 and set the compare value to 1000
- Enable compare waveform output for both channels
- Set waveform generation mode to; Dual-slope PWM, overflow on TOP and BOTTOM
When the application needs to change the heart rate, the CPU will change the value in the period buffer register.