2025-01-28 03:51 AM
Hello All,
I am doing project that Controls Watchdog Adc to trigger interrupt for higher Threshold value and lower Threshold, When Threshold Reaches Maximum and Minimum ISR happens, in ISR function it blink onboard led.
Using Onboard POT for watchdog adc Tuning High Threshold and Low threshold
Onboard LED Blink for ISR -Threshold high and low Interrupt
For this I am using SPC560d Dev board . We have Example Application Library for ADC it has all the function to work properly, but i want to do on my own by Register based using Xpc560d.h header fine, for that i cleared main.c file in Example ADC Application Library. Now I struct at Clock configuration for Watchdog Adc,
Below code when debugging, program hangs on Clock configuration like api config
I have selected Sysclk-->FIRC in RLA clock tree
Sysclk= 48mhz
Run mode : DRUN
RUN0 mode
pheripheral clock 24mhz
PINOUT:
PB[10]=ADC_1 Extended channel 6
PC[2]=GPIO output LED
PC[3]= GPIO output LED
//function for clock initilization
void Gpio_init(void) {
SIU.PCR[34].R = 0x0203; // Configure pin 34 as GPIO output
SIU.PCR[35].R = 0x0203; // Configure pin 35 as GPIO output
SIU.PCR[24].R = 0x2000; // Configure pin 24 for alternate function (ADC)
SIU.PSMI[2].R=0x04; //Pad select for adc_1
}
void ADC_1_IRQHandler(void) {
// Clear ADC interrupt flags
ADC_1.ISR.R = 0x0000001F;
// Check for watchdog events
if (ADC_1.WTISR.B.WDG0H || ADC_1.WTISR.B.WDG0L) {
adc_raw_value = ADC_1.CDR[4].B.CDATA; // Read ADC raw value for Channel 0
ResultInMv = (5000 * adc_raw_value) / 4096; // Convert ADC value to mV
if (adc_raw_value > THRESHOLD_HIGH) {
SIU.GPDO[34].R ^= 1; // Toggle GPIO if value exceeds high threshold
} else if (adc_raw_value < THRESHOLD_LOW) {
SIU.GPDO[35].R ^= 1; // Toggle GPIO if value is below low threshold
}
// Clear watchdog interrupt flags
ADC_1.WTISR.R = 0x01; // Clear low threshold flag
ADC_1.WTISR.R = 0x10; // Clear high threshold flag
}
}
//Main function
int main(void) {
asm volatile("wrteei 1" : : : "memory"); // Enable global interrupts
Clock_init(); // Initialize clocks
Gpio_init(); // Initialize GPIO
ADC_1_Init(); // Initialize ADC
ADC_1_IRQHandler();
while (1) {
}
return 0;
}
please let me know any correction needed for my project