SpenceKonde / megaTinyCore

Arduino core for the tinyAVR 0/1/2-series - Ones's digit 2,4,5,7 (pincount, 8,14,20,24), tens digit 0, 1, or 2 (featureset), preceded by flash in kb. Library maintainers: porting help available!
Other
554 stars 144 forks source link

16 bit PWM problem on attiny3226 #985

Closed elektroboard closed 1 year ago

elektroboard commented 1 year ago

Hi. I use Attiny3226 on megatinycore. I want to 16 pwm output from PA4 pin. But I am not success it? Please take sample sets. Thanks.

SpenceKonde commented 1 year ago

Well since the core doesn't support 16-bit pwm, you would have to write code to implement that - so I'd really need to see thst code


Spence Konde Azzy’S Electronics

New products! Check them out at tindie.com/stores/DrAzzy GitHub: github.com/SpenceKonde ATTinyCore: Arduino support for almost every ATTiny microcontroller Contact: @.***

On Thu, Jul 6, 2023, 09:54 elektroboard @.***> wrote:

Hi. I use Attiny3226 on megatinycore. I want to 16 pwm output from PA4 pin. But I am not success it? Please take sample sets. Thanks.

— Reply to this email directly, view it on GitHub https://github.com/SpenceKonde/megaTinyCore/issues/985, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTXEW342PLYYOK56TO6SUDXO27RTANCNFSM6AAAAAA2APFWLQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

elektroboard commented 1 year ago

Hi. Here my code. But there is Compilation error: 'PORTMUX_TCA0_PORTA_gc' was not declared in this scope

original codes from:https://github.com/microchip-pic-avr-examples/atmega4809-getting-started-with-tca-studio/blob/master/Generating_a_Dual-slope_PWM_Signal/main.c

`#include

define PERIOD_EXAMPLE_VALUE (0x01A0)

define DUTY_CYCLE_EXAMPLE_VALUE (0x00D0)

void TCA0_init(void); void PORT_init(void);

void TCA0_init(void) { // Set waveform output on PORT A PORTMUX.TCAROUTEA = PORTMUX_TCA0_PORTA_gc;

TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_WGMODE_DSBOTTOM_gc;

// Disable event counting
TCA0.SINGLE.EVCTRL &= ~(TCA_SINGLE_CNTEI_bm);

// Set PWM frequency and duty cycle (50%)
TCA0.SINGLE.PERBUF = PERIOD_EXAMPLE_VALUE;
TCA0.SINGLE.CMP0BUF = DUTY_CYCLE_EXAMPLE_VALUE;

TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV4_gc | TCA_SINGLE_ENABLE_bm;

}

void PORT_init(void) { pinMode(PIN_PA4, OUTPUT); // Set pin 0 of PORT A as output }

void setup() { PORT_init();

TCA0_init();

}

void loop() { // Main loop } `

hmeijdam commented 1 year ago

I think you are trying an example written for the Atmega4809 for an attiny3226 Those are quite different MCU's

elektroboard commented 1 year ago

Have do you a sample code for attiny3226

Hans @.***>, 7 Tem 2023 Cum, 10:04 tarihinde şunu yazdı:

I think you are trying an example written for the Atmega4809 for an attiny3226 Those are quite different MCU's

— Reply to this email directly, view it on GitHub https://github.com/SpenceKonde/megaTinyCore/issues/985#issuecomment-1624854596, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPYTPCGOLZQKWPBH44VJALXO6YG3ANCNFSM6AAAAAA2APFWLQ . You are receiving this because you authored the thread.Message ID: @.***>

--

P Gercekten gerekli degil ise bu sayfayi yazdırmayın, ormanlarımız yok olmasın.

SpenceKonde commented 1 year ago
Hi.
Here my code. But there is Compilation error: 'PORTMUX_TCA0_PORTA_gc' was not declared in this scope

original codes from:https://github.com/microchip-pic-avr-examples/atmega4809-getting-started-with-tca-studio/blob/master/Generating_a_Dual-slope_PWM_Signal/main.c

`#include <Arduino.h>

#define PERIOD_EXAMPLE_VALUE (0x01A0)
#define DUTY_CYCLE_EXAMPLE_VALUE (0x00D0)

{
pinMode(PIN_PA4, OUTPUT); // Set pin 0 of PORT A as output
}

void setup()
{
PORT_init();

TCA0_init();
}

void loop()
{
// Main loop
}
`

Only issue theree is that portmux is being manipulated like it was a Dx, Review the portmux section of th4e tinyAVR datasheet and do it the correct way and you should be good. PORTMUX for TCA on tinyAVR any Dx/Ex/mega0 could hardly be more differerent.

No there is no option that will move all the TCA pins to a given port. On tinyAVR, vs DxCore/etc, tinyAVR is both more and less flexible. On the downside, at ,most each pin can have only 1 of 2 outputs. On the plus side they get assigned per channel - and not assigned as the whole port. .

Dx/Ea: PORTMUX binds each WO to a pin in the same port. TinyAVR: PORTMUX gives you 2 choices per pin.

Make sure you have the correct tools -> PWM pins selected from the tools menu.

OH - and overriding the init functions is not sufficient to gun those timer initialization, you need to use takeOverTCA0. Overriding the init stops the timer from running but doesn't gain any of the flash back.

elektroboard commented 1 year ago

Hi. I have a question at https://github.com/SpenceKonde/megaTinyCore/issues/145. Please answer it. Thanks.

Spence Konde (aka Dr. Azzy) @.***>, 7 Tem 2023 Cum, 12:40 tarihinde şunu yazdı:

Hi. Here my code. But there is Compilation error: 'PORTMUX_TCA0_PORTA_gc' was not declared in this scope

original codes from:https://github.com/microchip-pic-avr-examples/atmega4809-getting-started-with-tca-studio/blob/master/Generating_a_Dual-slope_PWM_Signal/main.c

`#include

define PERIOD_EXAMPLE_VALUE (0x01A0)

define DUTY_CYCLE_EXAMPLE_VALUE (0x00D0)

{ pinMode(PIN_PA4, OUTPUT); // Set pin 0 of PORT A as output }

void setup() { PORT_init();

TCA0_init(); }

void loop() { // Main loop } `

Only issue theree is that portmux is being manipulated like it was a Dx, Review the portmux section of th4e tinyAVR datasheet and do it the correct way and you should be good. PORTMUX for TCA on tinyAVR any Dx/Ex/mega0 could hardly be more differerent.

No there is no option that will move all the TCA pins to a given port. On tinyAVR, vs DxCore/etc, tinyAVR is both more and less flexible. On the downside, at ,most each pin can have only 1 of 2 outputs. On the plus side they get assigned per channel - and not assigned as the whole port. .

Dx/Ea: PORTMUX binds each WO to a pin in the same port. TinyAVR: PORTMUX gives you 2 choices per pin.

I also am unsure of whether all of the

— Reply to this email directly, view it on GitHub https://github.com/SpenceKonde/megaTinyCore/issues/985#issuecomment-1625143122, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPYTPAH4AJK7PGMTGDHCKDXO7KRZANCNFSM6AAAAAA2APFWLQ . You are receiving this because you authored the thread.Message ID: @.***>

--

P Gercekten gerekli degil ise bu sayfayi yazdırmayın, ormanlarımız yok olmasın.

SpenceKonde commented 1 year ago

Please do not post questions in long-since closed issues, I'm not going to be able to keep track of them..

SpenceKonde commented 1 year ago

This page has been updated to reflect the trivial differences between the process of getting 16-bit PWM out of a Dx and tinyAVR. https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/TakingOverTCA0.md

Note that no matter what, you do need to write the code that writes 16-bit values to the compare registers and that stuff - that is not part of the Arduino API nor is it one of our API extensions - we stop at letting you tell the core to pretend the timer doesn't exist so you can use it unimpeded

SpenceKonde commented 1 year ago

OH and there;s no way to get 16 bit pwm out if PA4, that's WO5, WO3,4,5 are split mode only, hence 8 bit only. Available pins tht could be made to output 16bit pwm are PB0/PB3, PB1/PB4, and PB2/PB5. See chapter 21 of the datasheet (TCA) and table 3.1 I/O multiplexing and condideratons

elektroboard commented 1 year ago

Thanks for the tip!

Spence Konde (aka Dr. Azzy) @.***>, 15 Tem 2023 Cmt, 18:03 tarihinde şunu yazdı:

OH and there;s no way to get 16 bit pwm out if PA4, that's WO5, WO3,4,5 are split mode only, hence 8 bit only. Available pins tht could be made to output 16bit pwm are PB0/PB3, PB1/PB4, and PB2/PB5. See chapter 21 of the datasheet (TCA) and table 3.1 I/O multiplexing and condideratons

— Reply to this email directly, view it on GitHub https://github.com/SpenceKonde/megaTinyCore/issues/985#issuecomment-1636794814, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPYTPERJ4K6KU5M4LFDTWDXQKWMTANCNFSM6AAAAAA2APFWLQ . You are receiving this because you authored the thread.Message ID: @.***>

--

P Gercekten gerekli degil ise bu sayfayi yazdırmayın, ormanlarımız yok olmasın.