I'm trying to get make a PWM dimmer for an AC source and am having trouble with the best way to do so.
I can use chVTGetSystemTime() to check the ticks between zero crossings and get ~130 at 16MHz and ~65 with the internal oscillator. I want it to have small steps, so
I've tried changing CH_CFG_ST_FREQUENCY in chconf.h to a larger number which I thought would change the value of AVR_PRESCALER in st_lld.c, but it doesn't seem to be working. Is there something I'm missing? Should I be using the 16-bit timer instead of the default?
Thanks,
Mike
Fast system tick on AVR
-
- Posts: 28
- Joined: Tue Mar 10, 2015 4:49 pm
- Been thanked: 1 time
-
- Posts: 28
- Joined: Tue Mar 10, 2015 4:49 pm
- Been thanked: 1 time
-
- Posts: 28
- Joined: Tue Mar 10, 2015 4:49 pm
- Been thanked: 1 time
Re: Fast system tick on AVR
Hi Theo,
After some more reading today, I suspect that I'm coming at this the wrong way.
I'm trying to use PWM to control a mains power source, similar to what's shown in Figure 4 here: https://electronics.stackexchange.com/a/233804
Using the default settings in ChibiOS I get ~67 system ticks between zero crosses, but I would like to have finer control over the system than that. I had been trying to increase the system tick frequency but couldn't get it to work.
Now I'm thinking a better strategy would be to use timer1 set at a high frequency and use the GPT driver. I had tried something similar to this with an earlier version of ChibiOS but didn't have much luck.
Thanks,
Mike
After some more reading today, I suspect that I'm coming at this the wrong way.
I'm trying to use PWM to control a mains power source, similar to what's shown in Figure 4 here: https://electronics.stackexchange.com/a/233804
Using the default settings in ChibiOS I get ~67 system ticks between zero crosses, but I would like to have finer control over the system than that. I had been trying to increase the system tick frequency but couldn't get it to work.
Now I'm thinking a better strategy would be to use timer1 set at a high frequency and use the GPT driver. I had tried something similar to this with an earlier version of ChibiOS but didn't have much luck.
Thanks,
Mike
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: Fast system tick on AVR
Hi,
Implementing a PWM using system tick is, in general, not a good idea, it is too slow for most applications. Note that in HAL there is a specific PWM driver, you need that (not sure if it is implemented for AVR however).
Giovanni
Implementing a PWM using system tick is, in general, not a good idea, it is too slow for most applications. Note that in HAL there is a specific PWM driver, you need that (not sure if it is implemented for AVR however).
Giovanni
-
- Posts: 28
- Joined: Tue Mar 10, 2015 4:49 pm
- Been thanked: 1 time
Re: Fast system tick on AVR
Hi Giovanni,
I've used the hal PWM drivers before and they're definitely nice. But for this project I'm driving an SSR that has an AC load. So once I enable the output line, the load won't turn back off until there's a zero-crossing, so I don't think traditional PWM would work.
I think I want basically what you describe here: http://www.chibios.org/dokuwiki/doku.ph ... resolution
and am trying to figure out if it's possible with the AVR architecture.
Thanks,
Mike
I've used the hal PWM drivers before and they're definitely nice. But for this project I'm driving an SSR that has an AC load. So once I enable the output line, the load won't turn back off until there's a zero-crossing, so I don't think traditional PWM would work.
I think I want basically what you describe here: http://www.chibios.org/dokuwiki/doku.ph ... resolution
and am trying to figure out if it's possible with the AVR architecture.
Thanks,
Mike
- Giovanni
- Site Admin
- Posts: 14444
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1074 times
- Been thanked: 921 times
- Contact:
Re: Fast system tick on AVR
Hi,
I am not the one maintaining the AVR port but I remember that there is a problem with a small timer counter, on STM32 it is 32 bits wide. Is on AVR 8 bits wide? if so high resolution would be problematic.
Giovanni
I am not the one maintaining the AVR port but I remember that there is a problem with a small timer counter, on STM32 it is 32 bits wide. Is on AVR 8 bits wide? if so high resolution would be problematic.
Giovanni
-
- Posts: 28
- Joined: Tue Mar 10, 2015 4:49 pm
- Been thanked: 1 time
Re: Fast system tick on AVR
Hi Giovanni,
There are a couple of 8bit counters and one 16bit counter.
It looks like in tickless mode the 16bit counter is used, and in periodic mode an 8bit counter is used.
st_lld.c has the divider for tickless mode hard-coded to 1024. I played with that quite a while ago and I think had some success. It seems like that's where I need to be looking.
On another note, the comment in line 189 of os/hal/ports/AVR/st_lld.c should say "Freerunning mode" rather than "Periodic mode."
Thanks for the help,
Mike
There are a couple of 8bit counters and one 16bit counter.
It looks like in tickless mode the 16bit counter is used, and in periodic mode an 8bit counter is used.
st_lld.c has the divider for tickless mode hard-coded to 1024. I played with that quite a while ago and I think had some success. It seems like that's where I need to be looking.
On another note, the comment in line 189 of os/hal/ports/AVR/st_lld.c should say "Freerunning mode" rather than "Periodic mode."
Thanks for the help,
Mike
Who is online
Users browsing this forum: No registered users and 7 guests