Hi,
I've successfully assembled HET file and compiled my project files without any error.
However, pin HET0 and HET1 are not toggling as they should be, not as coded in HET.
The flow of the code:
Basically, in main( ), there is a forever loop to blink LEDS using port GIOA[7:0], and generate PWM output on pin HET0 and HET1. The LEDS are blinking just fine (the on-and-off duration can be controlled through SYSCLK setting, ICLK setting and delay loop), but both the HET0 and HET1 pins have no activity.
The following are my main.c and HET_pwm files.
Any ideas what setting that I've missed in my main() or in HET_pwm.het? What have I done wrong?
Any help is appreciated. Thank you!
-----------------------------------------------------------------------------------------------------------------------------------------------------
Note: Clock setup -> SYSCLK = Foscin = 14.7456Mhz, peripherals clock, ICLK = SYSCLK, and HET clock = SYSCLK
Software Tool: IAR Embedded Workbench
main.c
#include <stdio.h>
#include <string.h>
#include <intrinsic.h>
#include "std_het.h"
#include "tms470.h"
#include "HET_pwm.h"
#ifdef R1VF689
#include "iotms470r1vf689.h"
#else
#include "iotms470r1vf348.h"
#endif
__no_init volatile HETPROGRAM0_UN e_HETPROGRAM0_UN @ 0x00800000;
//------------------------------------------------------------------------------
// Help function to load the HET program into the HET RAM using 32-bit access.
//------------------------------------------------------------------------------
void MemCopy32(unsigned long *dst, unsigned long *src, int bytes)
{
for (int i = 0; i < (bytes + 3) / 4; i++)
*dst++ = *src++;
}
int main()
{
// Init SYSCLK, Foscin = 14.7456Mhz
GCR = 0x00000007; // set SYSCLK = (Foscin * 8)/8
// Enable peripherals and set clock to SYSCLK
PCR = 0x00; // set ICLK = SYSCLK
PCR |= 0x1; // enable peripherals
// Set pin CLKOUT
CLKCNTL_bit.CLKSR = 0x3;// set pin CLKOUT = SYSCLK
__enable_interrupt(); // Enable interrupts.
// Init GIOA as output
GIODIRA = 0xFF;
// Set the output low
GIODOUTA = 0x00;
// Copy HET instructions to HET RAM
MemCopy32((void *) &e_HETPROGRAM0_UN, (void *) HET_INIT0_PST, sizeof(HET_INIT0_PST));
// Setup HET
HETGCR_bit.CLK_MASTER = 0x1; // HET Master Mode
HETGCR_bit.IGNORE_SUSPEND = 0x1; // Ignore SW BP
// Time slots available = (Hr*Lr)-1 = (2 * 32 )-1 = 63
// fHR = SYSCLK/Hr, fLr=SYSCLK/(Hr*Lr)
HETPFR = 0x00000501;
HETDIR = 0xFFFFFFFF; // set all HETx as output
HETDOUT = 0xFFFFFFFF; // clear HET output
HETGCR_bit.ON = 0x1; //HETGCR |= 0x1; // Enable HET
HETXOR_bit.HR_XOR_SHARE_0_1=0x0; //HET0 and HET 1 are NOT shared
//*************************
// Loop forever.
while(1)
{
volatile unsigned int i;
GIODOUTA ^= 0xFF; ; // Toggle GIOA4 high and low
i = 50000; // Delay
do (i--);
while (i != 0);
}
//*************************
}
--------------------------------------------------------------------------------------------------------
HET_pwm.het
; Init SYSCLK, Foscin = 14.7456Mhz
; Enable peripherals and set clock to SYSCLK, ICLK = SYSCLK
; HET clock = SYSCLK
; Use TMS470R1x HET Reference Guide page 33 as example
A_PIN .equ 0 ; HET0 is used as output pin
B_PIN .equ 1 ; HET1 is used as output pin
CN: CNT { next=EA, reg=A, max=22 }
EA: ECMP { next=EB, cond_addr=MA, hr_lr=HIGH, en_pin_action=ON, pin=A_PIN,action=PULSELO, reg=A, data=17, hr_data=19 }
MA: MOV32 { next=EB, remote=EA, type=IMTOREG&REM, reg=NONE, data=17, hr_data=19 }
EB: ECMP { next=CN, cond_addr=MB, hr_lr=HIGH, en_pin_action=ON, pin=B_PIN,action=PULSELO, reg=A, data=5, hr_data=13 }
MB: MOV32 { next=CN, remote=EB, type=IMTOREG&REM, reg=NONE, data=5, hr_data=13 }
-----------------------------------Generate *.c and *.h files-------------------------------------
HET_pwm.c
#include "std_het.h"
HET_MEMORY const HET_INIT0_PST[5] =
{
/* A_PIN_0 */
{
0x00001600,
0x00000016,
0x00000000,
0x00000000
},
/* EA_0 */
{
0x00003000,
0x00102008,
0x00000233,
0x00000000
},
/* MA_0 */
{
0x00003401,
0x0000000E,
0x00000233,
0x00000000
},
/* EB_0 */
{
0x00000000,
0x00104088,
0x000000AD,
0x00000000
},
/* MB_0 */
{
0x00000403,
0x0000000E,
0x000000AD,
0x00000000
}
};
-------------------------
HET_pwm.h
#define HET_CN_0 (e_HETPROGRAM0_UN.Program0_ST.CN_0)
#define HET_EA_0 (e_HETPROGRAM0_UN.Program0_ST.EA_0)
#define HET_MA_0 (e_HETPROGRAM0_UN.Program0_ST.MA_0)
#define HET_EB_0 (e_HETPROGRAM0_UN.Program0_ST.EB_0)
#define HET_MB_0 (e_HETPROGRAM0_UN.Program0_ST.MB_0)
typedef union
{
HET_MEMORY Memory0_PST[5];
struct
{
CNT_INSTRUCTION CN_0;
ECMP_INSTRUCTION EA_0;
MOV32_INSTRUCTION MA_0;
ECMP_INSTRUCTION EB_0;
MOV32_INSTRUCTION MB_0;
} Program0_ST;
} HETPROGRAM0_UN;
extern volatile HETPROGRAM0_UN e_HETPROGRAM0_UN;
extern const HET_MEMORY HET_INIT0_PST[5];
Regards,
Soo