Fast system tick on AVR

ChibiOS public support forum for topics related to the Atmel AVR family of micro-controllers.

Moderators: utzig, tfAteba

mikenick42
Posts: 28
Joined: Tue Mar 10, 2015 4:49 pm
Been thanked: 1 time

Fast system tick on AVR

Postby mikenick42 » Sun Apr 30, 2017 4:47 am

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

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: Fast system tick on AVR

Postby tfAteba » Sun Apr 30, 2017 10:34 am

Hi Mike,

Wich arduino board do you use and wich version of ChibiOS do you work on?
regards,

Theo.

mikenick42
Posts: 28
Joined: Tue Mar 10, 2015 4:49 pm
Been thanked: 1 time

Re: Fast system tick on AVR

Postby mikenick42 » Sun Apr 30, 2017 1:39 pm

Hi Theo,

I'm using the stable 16.1 branch on an Uno.

Thanks,
Mike

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: Fast system tick on AVR

Postby tfAteba » Mon May 01, 2017 4:57 pm

Hi Mike,

Sorry I read your post and I can t understand your need! can you re-explain it to me please?

thanks.
regards,

Theo.

mikenick42
Posts: 28
Joined: Tue Mar 10, 2015 4:49 pm
Been thanked: 1 time

Re: Fast system tick on AVR

Postby mikenick42 » Tue May 02, 2017 2:51 am

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

User avatar
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

Postby Giovanni » Tue May 02, 2017 10:40 am

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

mikenick42
Posts: 28
Joined: Tue Mar 10, 2015 4:49 pm
Been thanked: 1 time

Re: Fast system tick on AVR

Postby mikenick42 » Wed May 03, 2017 2:39 am

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

User avatar
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

Postby Giovanni » Wed May 03, 2017 9:44 am

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

mikenick42
Posts: 28
Joined: Tue Mar 10, 2015 4:49 pm
Been thanked: 1 time

Re: Fast system tick on AVR

Postby mikenick42 » Thu May 04, 2017 3:28 am

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


Return to “AVR Support”

Who is online

Users browsing this forum: No registered users and 7 guests