I am running the following code found in one of the application notes to generate a sine wave PWM with the N2HET.
L00: CNT{next=L01, reqnum=0, request=GENREQ, reg=A, irq=OFF, max=PWM_PERIOD};
L01: ECMP{next=L03, hr_lr=HIGH, en_pin_action=ON, cond_addr=L02, pin=PWM_PIN_NUM, action=PULSELO, reg=A, irq=OFF, data=INIT_COMPARE, hr_data=INIT_HR_DELAY};
L02: MOV32 { remote=L01,type=IMTOREG&REM,reg=NONE,data=INIT_COMPARE,hr_data=INIT_HR_DELAY};
L03: BR{next=L00, cond_addr=L00, event=NOCOND}
However, the behavior I see is not what I understand from the TRM. I reckon the CNT instruction counts up to max_count and then resets the data field, while modifying the A register. The ECMP instruction compares the A register with its data field and PULSES the pin 0. So essentially the PWM period is determined by the max_count in the CNT instruction and the duty cycle (in terms of counts) is determined by the data field in the ECMP instruction.
But when I give the values of say, PERIOD = 100, and PULSE_WIDTH = 50 to max_count and data in the CNT and ECMP instructions respectively, I get a very slim spike on the pin. granted I can vary its width but not to the full extent of the PERIOD.
To get the behavior that I want, I have to do something more along these lines.
PERIOD = 100
PULSE_WIDTH = 50 * 50
Or something like that.
Am I not understanding the documentation correctly and this is the intended behavior? Or am I doing something wrong in the configuration?
Host side code as follows:
#include <math.h>
#include <stdint.h>
#include <stdbool.h>
#include "sys_common.h"
#include "het.h"
#include "htu.h"
#include "Sine_wave.h"
#define SINE_FREQ_DIVIDER 16
#define LRPFC 7
#define NHET1_PWM_PIN PIN_HET_0
#define CNT_MAX_PERIOD SINE_FREQ_DIVIDER
#define SAMPLE_SIZE 128
#define PI 3.14159f
float sine_table [SAMPLE_SIZE] = {};
uint32_t sine_digital_table [SAMPLE_SIZE] = {};
void htuInit(void)
{
htuRAM1->DCP[0].ITCOUNT = 0x00010000 + SAMPLE_SIZE;
htuRAM1->DCP[0].IHADDRCT = (htuRAM1->DCP[0].IHADDRCT & 0x0) | //Clear Register
0x1 << 23 | //DIR
0x0 << 22 | //SIZE
0x0 << 21 | //ADDMH
0x0 << 20 | //ADDFM
0x1 << 18 | //TMBA
0x0 << 16 | //TMBB
0x28; //IHADDR
htuRAM1->DCP[0].IFADDRA = (unsigned int)sine_digital_table;
htuREG1->CPENA = 0x00000001;
htuREG1->GC = 0x00010000;
}
void configNHET1()
{
hetREG1->PFR = LRPFC << 8;
hetREG1->REQENS = 1;
hetREG1->DIR = (1 << NHET1_PWM_PIN);
hetRAM1->Instruction[pHET_L00_0].Control = (uint32_t)(SAMPLE_SIZE) |
(hetRAM1->Instruction[pHET_L00_0].Control & 0xFE000000);
hetRAM1->Instruction[pHET_L01_0].Control =
(hetRAM1->Instruction[pHET_L01_0].Control & 0xFFFFE0FF) |
(NHET1_PWM_PIN << 8);
}
void main(void)
{
//C-style variable declaration
uint16_t iter_sine;
//Initialization Code
for ( iter_sine = 0; iter_sine < SAMPLE_SIZE; iter_sine++ ) {
sine_table[iter_sine] = sinf(2.0f * PI * ((float)iter_sine) / ((float)SAMPLE_SIZE)) * 0.5f + 0.5f;
sine_digital_table[iter_sine] = sine_table[iter_sine] * ((float)(SAMPLE_SIZE * SAMPLE_SIZE));
}
htuInit();
hetInit();
configNHET1();
while(1);
}
