[SOLVED] Enable interrupts from inside a timer interrupt

Post here first, or if you can't find a relevant section!
stevestrong
Posts: 2057
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany
Contact:

Re: [SOLVED] Enable interrupts from inside a timer interrupt

Post by stevestrong » Wed Jan 17, 2018 6:44 pm

Well, I cannot see why you would anyway need BCM, that's just PWM with repeatedly variable duty cycle.
IMO, this is equivalent to a "normal" PWM with constant duty cycle, wherein you have to keep the total low/high pulse ratio within a BCM period.
What also important, I think, it is the highest allowable OFF cycle to avoid flickering, which would be ~= the total period of a BCD train.

When you talk about 200Kz, what exactly is this referring to? To the period of one pulse or the total period of a BCM train?

The F103 timer PWM is very powerful, capable to set up in very different ways. You could also do some sync with other pulses when needed.
Do you have a plot showing how exactly your signals should look like? If possible with periods on it?

dannyf
Posts: 228
Joined: Wed May 11, 2016 4:29 pm

Re: [SOLVED] Enable interrupts from inside a timer interrupt

Post by dannyf » Wed Jan 17, 2018 6:48 pm

I need to run the PWM at least 1000 times faster.
It is certainly possible to run the pwm module at 1Mhz.

But when your requirement becomes that extreme for such a simple task, you may want to re-examine your approach, both software and hardware.

Case in point. Ppm is often used as a software implementation of pwm, when the hardware isn't available. It is not intuitive to implement ppm through a pwm hardware module.

victor_pv
Posts: 1863
Joined: Mon Apr 27, 2015 12:12 pm

Re: [SOLVED] Enable interrupts from inside a timer interrupt

Post by victor_pv » Wed Jan 17, 2018 7:00 pm

There is also the option to feed a timer from another timer.
I don't remember all the details, the datasheet shows what it can do, but perhaps that can remove the need to have 2 ISRs completely and leave only 1.
I think that one of the modes is to enable the second timer to count once the first time reach a certain count, which I understand is more or less what you are trying to do with the 2 timers and the ISR.

castortiu
Posts: 59
Joined: Tue Nov 07, 2017 8:34 am
Location: Seattle, WA

Re: [SOLVED] Enable interrupts from inside a timer interrupt

Post by castortiu » Wed Jan 17, 2018 7:11 pm

I'm not sure when I talked about 200Khz?, only thing I mentioned was that I want to keep the refresh rate above 200Hz.

Still didn't get any hint how to change the PWM frequency. Do you know how?

Current approach with two timers works fine, and blue pill only take care of rendering so the current approach is good enough, however when brightness is at minimum the isr introduce a 700ns latency which isn't big deal.

However I keep looking for alternatives, if I can drive PWM at 1Mhz I may not need the secobd timer however from what I read PWM uses a timer as well, so is not that I'm saving a lot other than some code.

Anyway... anything is on the table to change,

How do I change the pwm frecuency?

Thanks!!

User avatar
Pito
Posts: 1738
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: [SOLVED] Enable interrupts from inside a timer interrupt

Post by Pito » Wed Jan 17, 2018 7:16 pm

Still didn't get any hint how to change the PWM frequency. Do you know how?
viewtopic.php?f=19&t=3037#p39304
viewtopic.php?f=19&t=3037&start=10#p39347
Pukao Hats Cleaning Services Ltd.

castortiu
Posts: 59
Joined: Tue Nov 07, 2017 8:34 am
Location: Seattle, WA

Re: [SOLVED] Enable interrupts from inside a timer interrupt

Post by castortiu » Thu Jan 18, 2018 6:34 am

Handling the OE with PWM works great, as long I keep the PWM above 400Khz it doesn't produce any artifact for lower tones since even bit 0 which is the shortest will have up to 8 pulses and I don't need to synchronize with the latching, the reality in my testing I could go down to 200Khz before I started to see some evidence that tones are changing specially when I put a gradient test screen, so I bumped PWM to 400Khz and is rock solid, definitely now with PWM I have a much accurate control of the brightness than ISR chained event.

Thanks!!!!!

By the way now I know where the pink pins info is used in the image :)
However still I don't have clear for example, PWM on PB0 is controlled by T3C4 (Timer3 Channel 4) but what means T1C3N next to it???
Attachments
pins.jpg
pins.jpg (206.42 KiB) Viewed 121 times

castortiu
Posts: 59
Joined: Tue Nov 07, 2017 8:34 am
Location: Seattle, WA

Re: [SOLVED] Enable interrupts from inside a timer interrupt

Post by castortiu » Thu Jan 18, 2018 6:54 am

I uploaded a video to youtube to show how smooth is now the steps in control of the brightness with OE and PWM, the phone I have seems to be really good a low light so in the video can't be appreciated but there is a huge difference between brightness (0) and (15).

After playing the video several times during second 3 and 4 I see some artifacts that can't be seeing with the naked eye but on the video looks like some pixel ghosting, I did not have that before, I wonder if the PWM frequency is the problem since is not synchronized with the latching, I'll see if increment the PWM to 1.28Mhz have the same issue.

Attachments
ghostpixels.png
ghostpixels.png (208.97 KiB) Viewed 119 times

castortiu
Posts: 59
Joined: Tue Nov 07, 2017 8:34 am
Location: Seattle, WA

Re: [SOLVED] Enable interrupts from inside a timer interrupt

Post by castortiu » Thu Jan 18, 2018 8:08 am

On further testing I confirmed what I was afraid, "unsynchronized" PWM on OE brings undesirable artifacts to the display, I bumped the PWM frequency from 400Mhz to 1.2Mhz and is barely noticeable however the artifacts are still there as you can see in the image below with and without PWM.

I would bet anything that is because the PWM is not synchronized with the latch so the OE is going low and enable the display while the data is still feed into the shift register.

Well... going back to the drawing board :(

My guts tells me if I synchronize the OE PWM start/stop with the latch this problem will go away, also synchronizing will make the number of pulses constants when the display is visible so I suspect that just lowering to 200Khz (about 4 pulses for bit 0) will be more than enough since now the duty cycle will be the fair and same for every bit, it would require some extra lines of code as it did with the 2 ISR timer chained events, however I think it will work.
Attachments
PWM 1Mhz.jpg
PWM 1Mhz.jpg (232.6 KiB) Viewed 98 times
No PWM.jpg
No PWM.jpg (235.34 KiB) Viewed 98 times

dannyf
Posts: 228
Joined: Wed May 11, 2016 4:29 pm

Re: [SOLVED] Enable interrupts from inside a timer interrupt

Post by dannyf » Thu Jan 18, 2018 11:34 am

There is also the option to feed a timer from another timer.
having the master to trigger to slave; or running the slave in single pulse mode....
what means T1C3N next to it???
negative.

castortiu
Posts: 59
Joined: Tue Nov 07, 2017 8:34 am
Location: Seattle, WA

Re: [SOLVED] Enable interrupts from inside a timer interrupt

Post by castortiu » Fri Jan 19, 2018 6:09 am

Synchronizing the OE with the latching works like a dream and there is no artifact problem at any brightness level and I can go as low as 300Khz for the PWM without any problem. At this point I can't be happier and don't think I'll make any more changes on the display brightness.

Steve wrote,
"Well, I cannot see why you would anyway need BCM, that's just PWM with repeatedly variable duty cycle."

From what I researched with BCM I need way fewer instructions to display a frame with 128x32 at 16 tones achieving much higher refresh rate of at least 250Hz.

Currently the main loop to display a frame is basically; cycle for the instructions I put below with barely any extra processing.
Based my work from the explanation http://www.batsocks.co.uk/readme/art_bcm_1.htm however the implementation was initially the Adafruit RGB matrix driver implementation that I heavily end up modifying..

Instructions to create a frame:
(1 x reset PWM OE) + (1 x set latch) + (1 x Row Address = "2 rows per instruction") + (128 x clock set) (1 x R1G1B1&R2B2G2 data "6 colors set per instruction") + (128 x clock reset) + (1 x set PWM OE)) x 4 bits x 16 rows = 16704 instructions per frame

so with 16704 instructions I can display a whole RGB frame on the matrix, may be possible but honestly down know how to make it happen with PWM instead BCM.

Post Reply