Understood Bijumon.
I prefer to use Arduino Nano to test the code.
The reason I have sent you the links to the IDE Ard code is that the author uses only 100 lut values, not 200, as you do.
As well the work of Timer1 in mode8 is very interesting and I thought you will have a look at it.
All the best.
Arduino interrupt Frequency
-
- Posts: 47
- http://meble-kuchenne.info.pl
- Joined: Wed Jul 12, 2023 7:09 am
- Has thanked: 7 times
- Been thanked: 12 times
Re: Arduino interrupt Frequency
hi viktor,
code from above said link i had converted to Flowcode as same, 100 lut values and 10Khz interrupt.
code from above said link i had converted to Flowcode as same, 100 lut values and 10Khz interrupt.
- Attachments
-
- Arduino Nano SPWM 10 KHz.fcfx
- (13.85 KiB) Downloaded 72 times
Re: Arduino interrupt Frequency
Hi Bijumon.
Good job.
The converted by you IDE code works (to a degree).
The problem exists with the LUT table.
I added to the main loop the output to flash the onboard LED (B5).
It does not flash.
For some reason the main loop is frozen.
However the converted by you code works and Timer1 works OK in mode8.
I can be wrong, but I think, the next can be done:
- lut and main loop problem should be solved.
- improve the dead time code.
- create the mechanism of changing the value of Timer1 ISR1.
I think, when ICR1 = 800 the sinewave value is close to zero or zero.
The code line: OCR1A = FCV_LOOKUP * 0.7 + FCV_DTA should be changed as well.
PS
Have you considered the Egs002 module to be used?
Good job.
The converted by you IDE code works (to a degree).
The problem exists with the LUT table.
I added to the main loop the output to flash the onboard LED (B5).
It does not flash.
For some reason the main loop is frozen.
However the converted by you code works and Timer1 works OK in mode8.
I can be wrong, but I think, the next can be done:
- lut and main loop problem should be solved.
- improve the dead time code.
- create the mechanism of changing the value of Timer1 ISR1.
I think, when ICR1 = 800 the sinewave value is close to zero or zero.
The code line: OCR1A = FCV_LOOKUP * 0.7 + FCV_DTA should be changed as well.
PS
Have you considered the Egs002 module to be used?
- Attachments
-
- Scope_18Dec24_1.jpg (75.23 KiB) Viewed 1655 times
Re: Arduino interrupt Frequency
Hi Viktor,
i haven't seen any issue in main loop, i had added LED on D13 and its blinking, may your hardware issue.
LUT just copied from the article as same, didn't change.
That fixed voltage correction value (0.7) and dead time you can change as you whish. i follow the article.
there are inverted signal as well with dead time that's what the filtered signal showing inverted sine as well.
i haven't seen any issue in main loop, i had added LED on D13 and its blinking, may your hardware issue.
LUT just copied from the article as same, didn't change.
That fixed voltage correction value (0.7) and dead time you can change as you whish. i follow the article.
there are inverted signal as well with dead time that's what the filtered signal showing inverted sine as well.
- Attachments
-
- Arduino Nano SPWM 10 KHz.fcfx
- (14.79 KiB) Downloaded 71 times
Re: Arduino interrupt Frequency
Hi Bijumon
About the fixed voltage correction value = 0.7.
The author of the article used this value (I think) as an example.
It is not a feedback value for AC voltage.
-----
Correct me if I am wrong.
Example: If OCR1A = 0, Vout = max.
Set as norm: If Vout = 240v, set OCR1A=5,
Do something if Vout = 260v (OCR1A=0?),
Do something if Vout = 220v (OCR1A=10?),
I think there are a different ways to control the AC voltage.
Any ideas?
About the fixed voltage correction value = 0.7.
The author of the article used this value (I think) as an example.
It is not a feedback value for AC voltage.
-----
Correct me if I am wrong.
Example: If OCR1A = 0, Vout = max.
Set as norm: If Vout = 240v, set OCR1A=5,
Do something if Vout = 260v (OCR1A=0?),
Do something if Vout = 220v (OCR1A=10?),
I think there are a different ways to control the AC voltage.
Any ideas?
Re: Arduino interrupt Frequency
Hi Viktor,
About the fixed voltage correction value = 0.7 is an Example it can be change as you wish, 0.7 will give 70% of each LUT value.
Eg: 0.5 will give 50% of each LUT value , 0.9 will give 90% of each LUT value.
it can be use to vary the output voltage or stabilize the output voltage use feed back from output.
you have to use a variable instead of fixed value.
Correct me if I am wrong?
in this case Lut value 0 will give always 0% duty cycle and 800 will give 100% duty cycle without voltage correction value.
adding different voltage correction vale will allow to control output amplitude.
i had draw the the circuit in proteus as same as in article ( i don't have full hardware to test it in real world) if you have hardware you can test it.
proteus simulation is working well as attached.
About the fixed voltage correction value = 0.7 is an Example it can be change as you wish, 0.7 will give 70% of each LUT value.
Eg: 0.5 will give 50% of each LUT value , 0.9 will give 90% of each LUT value.
it can be use to vary the output voltage or stabilize the output voltage use feed back from output.
you have to use a variable instead of fixed value.
Correct me if I am wrong?
in this case Lut value 0 will give always 0% duty cycle and 800 will give 100% duty cycle without voltage correction value.
adding different voltage correction vale will allow to control output amplitude.
i had draw the the circuit in proteus as same as in article ( i don't have full hardware to test it in real world) if you have hardware you can test it.
proteus simulation is working well as attached.
- Attachments
-
- Screenshot 2024-12-20 201957.jpg (148.2 KiB) Viewed 1506 times
-
- Screenshot 2024-12-20 201345.jpg (195.07 KiB) Viewed 1506 times
Re: Arduino interrupt Frequency
Hi Bijumon
Timer1 OCR1A register changes the state of pin B1.
From datasheet:
The 16-bit comparator continuously compares TCNT1 with the output compare register (OCR1x).
When ICR1 value = 0, the OCRIA register value is set to LUT value.
The question.
What is the default state of pin B1?
Is it zero?
I attached the diagram from the datasheet.
Looks like:
If ICR1 counts up, if OCRIA register value = ICR1 value, the pin B1 state changes from 1 to 0.
If ICR1 counts down, if OCRIA register value = ICR1 value, the pin B1 state changes from 0 to 1.
In this case you right, the sinewave graph values follow the OCR1A values.
Timer1 OCR1A register changes the state of pin B1.
From datasheet:
The 16-bit comparator continuously compares TCNT1 with the output compare register (OCR1x).
When ICR1 value = 0, the OCRIA register value is set to LUT value.
The question.
What is the default state of pin B1?
Is it zero?
I attached the diagram from the datasheet.
Looks like:
If ICR1 counts up, if OCRIA register value = ICR1 value, the pin B1 state changes from 1 to 0.
If ICR1 counts down, if OCRIA register value = ICR1 value, the pin B1 state changes from 0 to 1.
In this case you right, the sinewave graph values follow the OCR1A values.
- Attachments
-
- DataSheet_graph_1.jpg (53.59 KiB) Viewed 1482 times