Post by jg on Nov 8, 2018 13:59:25 GMT
Hi all,
I want to make a LED blink using the TOM. I have it working but changing the clock in the tomConfig struct doesn't seem to have an effect. What am I doing wrong?
I want to make a LED blink using the TOM. I have it working but changing the clock in the tomConfig struct doesn't seem to have an effect. What am I doing wrong?
#include "vt100.h"
#include "IfxPort_PinMap.h"
#include <Gtm/Tom/Pwm/IfxGtm_Tom_Pwm.h>
Ifx_GTM *gtm = &MODULE_GTM;
boolean tom_status = false;
float32 frequency;
void setup() {
/*************************************
* SERIAL CONFIGURATION
*************************************/
SerialASC.begin(9600);
SerialASC.print(VT100_CURSOR_OFF);
SerialASC.print(VT100_CLR_SCREEN);
/*************************************
* PWM CONFIGURATION
*************************************/
// Enable GTM Module
IfxGtm_enable(gtm);
frequency = IfxGtm_Cmu_getModuleFrequency(gtm); // Returns 100MHz
// Select the CMU_CLK_5 as input for FXU
gtm->CMU.FXCLK.CTRL.B.FXCLK_SEL = 6;
// Set the clock divider to 1000
gtm->CMU.CLK0_5[5].CTRL.B.CLK_CNT = 1000;
// Enable CMU_CLK_5 and FXU clock
IfxGtm_Cmu_enableClocks(gtm, IFXGTM_CMU_CLKEN_FXCLK | IFXGTM_CMU_CLKEN_CLK5);
// Initialise TOM
IfxGtm_Tom_Pwm_Config tomConfig; // Configuration structure
IfxGtm_Tom_Pwm_Driver tomHandle; // Handle
// Initialise struct
IfxGtm_Tom_Pwm_initConfig(&tomConfig, gtm);
tomConfig.clock = IfxGtm_Tom_Ch_ClkSrc_cmuFxclk0; // Has no effect...?
tomConfig.tom = IfxGtm_Tom_0;
tomConfig.tomChannel = IfxGtm_Tom_Ch_2;
tomConfig.period = 2*32767;
tomConfig.dutyCycle = 0.5*tomConfig.period; // 50% duty cycle
tomConfig.interrupt.ccu0Enabled = FALSE;
tomConfig.pin.outputPin = &IfxGtm_TOM0_2_TOUT104_P10_2_OUT; // ShieldBuddy LED
// Start TOM -> LED will blink
tom_status = IfxGtm_Tom_Pwm_init(&tomHandle, &tomConfig);
}
void loop() {
delay(200);
//SerialASC.print("ADC Val: ");
if(tom_status)
SerialASC.print("Running ");
else
SerialASC.print("Error ");
SerialASC.print(frequency);
SerialASC.print("\r\n");
}
void setup1(){
}
void loop1(){
}
void setup2(){
}
void loop2(){
}