I'm trying to access the variable inside the ISR and i want to initiate the PWM signal on D4 pin when the interrupt occurred. also duty cycle of the PWM is control by analog potentiometer as shown in the below code. i have try this code but it wouldn't work (no PWM output).
i have tried code one by one as 1st i have checked that Val1 is update when interrupt occurred and it updated as expected
Code: Select all
void loop() {
if (val1 == 1){
Serial.println(val1);
}
}
void EXTI0_IRQHandler (){
val1 = true;
}
Code: Select all
void loop() {
if (val1 == 1){
val = map(analogRead(A0), 0, 4096, 0, 100);
Serial.println(val);
}
}
void EXTI0_IRQHandler (){
val1 = true;
}
Code: Select all
void loop() {
if (val1 == 1){
pulse->setPWM(channel, pin, 5, 40);
}
}
void EXTI0_IRQHandler (){
val1 = true;
}
Code: Select all
int val =0;
#define InterruptPin 3
#define pin 4
volatile bool val1 = false ;
TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(pin), PinMap_PWM);
uint32_t channel = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(pin), PinMap_PWM));
HardwareTimer *pulse ;
void setup() {
pinMode(InterruptPin, INPUT_PULLDOWN);
pulse = new HardwareTimer(Instance);
attachInterrupt(InterruptPin, EXTI0_IRQHandler, RISING);
analogReadResolution(12);
}
void loop() {
if (val1 == 1){
val = map(analogRead(A0), 0, 4096, 0, 100);
pulse->setPWM(channel, pin, 5, val);
//Serial.println(val);
}
}
void EXTI0_IRQHandler (){
val1 = true;
} // end of ISR