Other Parts Discussed in Thread: HALCOGEN
Been trying to get the HTU to work for a while. Right now, I've gotten the N2HET programs to work (just generating a PWM right now, in the same way as in the sine wave generation example in SPNA217). But, when I try to do the HTU transfer it's not wanting to work. Anyways, got the code below. I'm not using HalCoGen because I prefer to create my own functions and all that, and the potential final end use for this says we can't use it since it generate a lot of dead code (all of the code generated even if you don't plan to use it), but hopefully the register names should make sense enough. All it's supposed to do is start off at about a 75% duty cycle, then the HTU kicks in and changes the duty cycle to ~66%.
int main(void) { // Data to transfer using the HTU uint32_t data = (412 << 6); uint32_t *data_addr = &data; /* * Initialize the HTU */ DCP1REG->DCPx[0].ITCOUNT = (1 << 16) | (1 << 0); // Do a single element transfer and a single frame transfer DCP1REG->DCPx[0].IHADDRCT = (1 << 23) | // Main memory is read and NHET memroy is written. (1 << 18) | // Set to circular buffer mode (0x28 << 0); // Set the initial NHET address (the data field of ECMP is address 6) DCP1REG->DCPx[0].IFADDRA = (uint32_t)data_addr; // Set the initial address in main memory HTU1REG->CPENA = 1; // Enable DCP[0] control packet A HET1REG->GCR = (1 << 16); // Enable HTU1 // Enable GIOB[6] LED for debugging GIOCNTL->GCR0 = 1; GIOB->DIR |= (1 << 6); /* * Initialize the N2HETs * The HTU is attached to N2HET1 */ HET1REG->DIR |= 0xFFFF; // Enable N2HET1[0] pin for output // Set the resolution pre-scalars HET1REG->PFR |= (1 & 0x3F) | (HET1REG->PFR & 0x3F); HET1REG->PFR |= ((6 & 0x7) << 8) | (HET1REG->PFR & (0x7 << 8)); HET1REG->REQENS |= (1 << 0); // Enable requests on line 0 HET1REG->GCR |= ((1 << 24) | // Turn on the pins (1 << 17) | // Ignore suspen (1 << 16) | // Set to master mode (1 << 0)); // Enable HET // Put the program into memory // HET1RAM is the pointer to the N2HET1 RAM location. het1_instructions is the actual N2HET instructions memcpy((void *)HET1RAM, (const void *)het1_instructions, sizeof(het1_instructions)); while(1) { // Check to see if data is being transfered. If it is, turn on the LED if((HTU1REG->BUSY[0] & (1 << 24)) != 0) GIOB->DSET = (1 << 6); } return 0; }
The N2HET program is below, in case it helps. Would put it in the form of the HET IDE, but it seems the TI website wont let me download any of the HET assembler/debugger tools...
#define HET1_LENGTH 4 // Program for the N2HET1 peripheral const het_memory_t het1_instructions[] = { { // CNT // Program // 000000 000 0 000000001 0110 0 00 1 0000 0 // 0000 0000 0000 0000 0010 1100 0010 0000 0x00002C20, // Control // 000 01 0 0 0000000000000001001110000 // 0000 1000 0000 0000 0000 0010 0111 0000 0x08000270, // Data 0x00000000, // Reserved 0x00000000 }, { // MCMP // Program // 000000 000 0 000000011 0000 0 0 0 0 00000 // 0000 0000 0000 0000 0110 0000 0000 0000 0x00006000, // Control // 000 00 0 000 1 000000010 00000 0 1 0 11 00 0 // 0000 0000 0100 0000 0100 0000 0101 1000 0x00404058, // Data 0x00003400, // Reserved 0x00000000 }, { // MOV32 // Program // 000000 000 0 000000011 0100 000000001 // 0000 0000 0000 0000 0110 1000 0000 0001 0x00006801, // Control // 00000 0 000 0 00000000000000 0 0 0 01 11 0 // 0000 0000 0000 0000 0000 0000 0000 1110 0x0000000E, // Data 0x00003400, // Reserved 0x00000000 }, { // BRANCH // Program // 000000 000 0 000000000 1101 000000000 // 0000 0000 0000 0000 0001 1010 0000 0000 0x00001A00, // Control // 000 00 0 0 000 000000000 00000 00000 00 0 // 0000 0000 0000 0000 0000 0000 0000 0000 0x00000000, // Data 0x00000000, // Reserved 0x00000000 } }; // Put the instruction memory and the instruction type defaults into a union // This is more for convinience and ease of use. The instruction memory and // program struct will take up the same memory space. typedef union { het_memory_t instr_memory[HET1_LENGTH]; struct { CNT L00; MCMP L01; MOV32 L02; BR L03; } program_struct; } het1_program; // Actually instantiate the program volatile het1_program het1_program_load;
I'm probably just making a stupid small mistake, but any help you have would be appreciated. Hopefully all that makes sense. Brain is a little dead from trying to figure this out and staring at it for so long.
-Max