Page 1 of 1

Advice!

Posted: Sat Sep 21, 2024 4:56 pm
by jgu1
Hi all!

I am making a project where I use PWM. I want to adjust the timing with two button. I call these two button by help of pin interrupt to toggle up and down. I in/de crement by one (in the calculation DelayAjd = DelayAjd - 1 and DelayAjd = DelayAjd + 1 But every time I press one of the button the counters step up and down with two? If I change cslculation with 2 it change with 4 ?

Works in simulation. My loop in the interrupt I use for "delay" timer to avoid noice. I know it is not good to use delay component in macro called by interrupt.

Plaese, what am i doing wrong? :roll:

Br jorgen

Re: Advice!

Posted: Sat Sep 21, 2024 5:04 pm
by mnfisher
In Up and Down - you can get an infinite loop.

For example if DelayAdj is 0 when Up is called - then it will loop to connection point A forever.


Can you use a button component?

Martin

Re: Advice!

Posted: Sat Sep 21, 2024 5:12 pm
by jgu1
Hi Martin :D

Honest, I don’t understand,

I dare to ask, Will you please to edit in my program, Then I would be happy :D

Re: Advice!

Posted: Sat Sep 21, 2024 5:54 pm
by mnfisher
A first idea.

Here I read both buttons and then adjust DelayAjd - no change if both buttons pressed.
I just print the value to LCD - so 'works' in simulation. Then wait for buttons to be released (or have a delay for value to increase / decrease whilst button held)

It would be nicer - at least in simulation - to use an interrupt. In simulation button presses can be 'missed' (probably whilst waiting for 'low') - but I don't think this will be an issue on hardware which is rather quicker?

I commented in 'Up' where the infinite loop can occur...

Martin

Re: Advice!

Posted: Sat Sep 21, 2024 6:41 pm
by jgu1
Thank you Martin, I see now what you mean, and it work. Now I can continue :D

Jorgen

Re: Advice!

Posted: Sat Sep 21, 2024 9:12 pm
by mnfisher
Good to hear you are going again.

Please let us see the project when it's running 👍

Re: Advice!

Posted: Sun Sep 22, 2024 5:37 am
by jgu1
You Will hear Martin, take a little while. ;)