Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

PWM & xtiny (ATTINY3217)

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Skrivo

Bascom Member



Joined: 15 Jul 2020
Posts: 11

slovenia.gif
PostPosted: Tue Aug 11, 2020 11:06 am    Post subject: PWM & xtiny (ATTINY3217) Reply with quote

The company I work for requested to switch from old ATTINY84A to ATTINY3217 - we got information that ATTINY84A will be in production max. till 2025 and that is ALARM!!! The same is true for popular ATMEGA328P.....we will all need to switch to new xtiny 0 or 1 series and also to new ATMEGA 0 series which are still unfortunately unsuported in Bascom...). I am posting this information because the old ATTINYs and ATMEGAs will become totally obsolete quite soon and we all need to be aware of that fact!

As I am not very experienced I now have a problem to implement the same »dual slope« PWM output on ATTINY3217 as I use on "old" ATTINY84A where the Bascom code is the following:

'-------------------------------------------------------------------------------

Config Timer1 = Pwm , Prescale = 1 , Compare B Pwm = Clear Up ' for PMW output we choosed pin OC1B

'in registers we define mode 8 PWM: Phase & Freq. Correct (PWM frequency is ultra correct….same accuracy as XTAL)
Tccr1b.wgm13 = 1
Tccr1b.wgm12 = 0
Tccr1a.wgm11 = 0
Tccr1a.wgm10 = 0


'define PWM frequency:
Icr1 = 7999 'PWM frequency = 16000000/(prescale*(ICR1+1)*2) = 1000Hz (ultra precise)…………TIMER1 is running from 0 to 7999 and then from 7999 back down to 0 and repeating this sequence indefinitely

'run PMW with constant 25% duty cycle – PWM available on pin OC1B (PA5 on ATTINY84A)
Ocr1b = 2000 'define desired 25% PWM duty cycle on PWM output pin OC1B: OCR1B = (dutycycle*ICR1)/100

'-------------------------------------------------------------------------------

Can somebody please help me write the equivalent code for the new ATTINY3217? I need to get out this accurate 25% duty cycle PWM on pin PB0 using TCA0 timer in ATTINY3217.

(BASCOM-AVR version : 2.0.8.3 )
Back to top
View user's profile
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 34

blank.gif
PostPosted: Tue Aug 11, 2020 11:46 am    Post subject: Reply with quote

I probably don't understand what you're talking about, but the advantage of Bascom and its biggest advantage is that you don't really have to change anything and adjust it manually. The environment will do it for you if the selected chip has peripherals.
So pick a chip and translate, upload and use.
I haven't tested PWM yet, but I assume that Mark will not make a mistake here after many years of experience. If there is a need to test and ask specifically.
Back to top
View user's profile
Skrivo

Bascom Member



Joined: 15 Jul 2020
Posts: 11

slovenia.gif
PostPosted: Tue Aug 11, 2020 12:00 pm    Post subject: Reply with quote

SZTRAD wrote:
I probably don't understand what you're talking about, but the advantage of Bascom and its biggest advantage is that you don't really have to change anything and adjust it manually. The environment will do it for you if the selected chip has peripherals.
So pick a chip and translate, upload and use.
I haven't tested PWM yet, but I assume that Mark will not make a mistake here after many years of experience. If there is a need to test and ask specifically.


My need is a specific PWM, it's not just straight forward in Bascom. I certainly have a reason for dual slope PWM Smile
There are many, many PWM options, a lot of details, PWM is a "science" when you dig deep enough. ATtinys have a lot of PWM options, certainly too much for most users.

I am waiting for Mark's answer
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5093
Location: Holland

blank.gif
PostPosted: Tue Aug 11, 2020 9:35 pm    Post subject: Reply with quote

indeed one of the big advantage is that you can change $regfile and most code will work. but that also depends on the hardware.
The timers in the normal AVR are different compared to the ones with XMega.
And the xtiny also has new kind of timers. So it is not so simply to map old functionality. but where possible all is kept the same.
Now about this question. I need to look into it. when implementing xtiny support some new hardware features were skipped (for example the usart can do irda too). and those are added depending on demand.
the timers have a lot of options as you can see from the config TCA0
i will get back on your question when i have sorted it out.

_________________
Mark
Back to top
View user's profile Visit poster's website
plouf

Bascom Member



Joined: 19 Jan 2012
Posts: 27
Location: Athens,Greece

greece.gif
PostPosted: Tue Aug 11, 2020 11:27 pm    Post subject: Re: PWM & xtiny (ATTINY3217) Reply with quote

Skrivo wrote:
The company I work for requested to switch from old ATTINY84A to ATTINY3217 - we got information that ATTINY84A will be in production max. till 2025 and that is ALARM!!! The same is true for popular ATMEGA328P.....


really doubt that mega328 will stop WORST case scenario is to stop suggesting mega328P because they have under production mega328PB whcih is the same device but newer fabribation method which makes is cheaper
the same i believe for tiny84 (and NOT tiny84A)
please share the "information" with us, like who said it

at any case is good to go for newer devices for a nubmber of reasons
Back to top
View user's profile
Skrivo

Bascom Member



Joined: 15 Jul 2020
Posts: 11

slovenia.gif
PostPosted: Wed Aug 12, 2020 7:00 am    Post subject: Re: PWM & xtiny (ATTINY3217) Reply with quote

plouf wrote:
Skrivo wrote:
The company I work for requested to switch from old ATTINY84A to ATTINY3217 - we got information that ATTINY84A will be in production max. till 2025 and that is ALARM!!! The same is true for popular ATMEGA328P.....


really doubt that mega328 will stop WORST case scenario is to stop suggesting mega328P because they have under production mega328PB whcih is the same device but newer fabribation method which makes is cheaper
the same i believe for tiny84 (and NOT tiny84A)
please share the "information" with us, like who said it

at any case is good to go for newer devices for a nubmber of reasons



The information about estimated "END OF LIFE" also for ATmega328P came from Arrow Electronics Europe. This is still estimated, they may manufacture them beyond 2025 but you never know. See attached file how the information looks like in Arrow's information system (it's for ATmega328P-AU).
Back to top
View user's profile
plouf

Bascom Member



Joined: 19 Jan 2012
Posts: 27
Location: Athens,Greece

greece.gif
PostPosted: Wed Aug 12, 2020 7:36 am    Post subject: Reply with quote

to me it seems that this site takes "EOL" based on how many years is in production
but EPSECIALY mega328 is so wide spreaded in so many applications (including arduino)
which make IMPOSSIBLE to think that they stop production,at least without a replacement
for example mega328P -> 328PB

so check atmega328PB, but at any case this is not official announcement, but an ESTIMATION from
an automated system

(it says that it has live 5 years more than expected ?!) check out pic16f84A , ,, a 25+ years mcu still under production
even if newer devices are 1/10 of its price and have *10 its capabilities it is still selling because of its huge penetration in market

so as long as MICROCHIP does not issue an EOL do not expect to stop and even then will be available for at least a few years
Back to top
View user's profile
Skrivo

Bascom Member



Joined: 15 Jul 2020
Posts: 11

slovenia.gif
PostPosted: Wed Aug 12, 2020 7:44 am    Post subject: Reply with quote

plouf wrote:
to me it seems that this site takes "EOL" based on how many years is in production
but EPSECIALY mega328 is so wide spreaded in so many applications (including arduino)
which make IMPOSSIBLE to think that they stop production,at least without a replacement
for example mega328P -> 328PB

so check atmega328PB, but at any case this is not official announcement, but an ESTIMATION from
an automated system

(it says that it has live 5 years more than expected ?!) check out pic16f84A , ,, a 25+ years mcu still under production
even if newer devices are 1/10 of its price and have *10 its capabilities it is still selling because of its huge penetration in market

so as long as MICROCHIP does not issue an EOL do not expect to stop and even then will be available for at least a few years


I hope you are right Smile
Back to top
View user's profile
Skrivo

Bascom Member



Joined: 15 Jul 2020
Posts: 11

slovenia.gif
PostPosted: Wed Aug 12, 2020 7:45 am    Post subject: Reply with quote

albertsm wrote:
indeed one of the big advantage is that you can change $regfile and most code will work. but that also depends on the hardware.
The timers in the normal AVR are different compared to the ones with XMega.
And the xtiny also has new kind of timers. So it is not so simply to map old functionality. but where possible all is kept the same.
Now about this question. I need to look into it. when implementing xtiny support some new hardware features were skipped (for example the usart can do irda too). and those are added depending on demand.
the timers have a lot of options as you can see from the config TCA0
i will get back on your question when i have sorted it out.


Mark, thanks for the answer. I am waiting for your help/solution...
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5093
Location: Holland

blank.gif
PostPosted: Wed Aug 12, 2020 7:11 pm    Post subject: Reply with quote

I think that this should be the same :

Config Tca0 = Pwm , Prescale = 1 , Resolution = Normal , Compare0 = Enabled
Tca0_per = Your Icr Value
Tca0_cmp0 = Your Compare Value

output should be on compare0 output pin. you need to set this pin to output.

_________________
Mark
Back to top
View user's profile Visit poster's website
Skrivo

Bascom Member



Joined: 15 Jul 2020
Posts: 11

slovenia.gif
PostPosted: Thu Aug 13, 2020 8:12 am    Post subject: Reply with quote

albertsm wrote:
I think that this should be the same :

Config Tca0 = Pwm , Prescale = 1 , Resolution = Normal , Compare0 = Enabled
Tca0_per = Your Icr Value
Tca0_cmp0 = Your Compare Value

output should be on compare0 output pin. you need to set this pin to output.


Mark, thanks for the answer but "config part" of your suggestion doesn't work at all (0V on pin PB0). But you gave me some idea how to sort this out. I couldn't sleep, I dig deeper and deeper and found the way to sort this out.

So, the ATtiny3217 dual slope PWM equivalent code compared to the one in the old ATtiny84A is:

------------------------------------------------------------------------------------------------
Config Portb.0 = Output
TCA0_ctrla = &B00000001 'run TCA0 timer with prescaler = 1
TCA0_ctrlb = &B00010111 'defining "dual slope PWM" on pin PB0 (WO0)
TCA0_per = 8000 'PWM frequency (pariod) = ICR on old ATtiny84A
TCA0_cmp0 = 2000 '25% duty cycle on pin PB0 (WO0)
------------------------------------------------------------------------------------------------

Bascom "Config TCA0" needs some update and there is no Config for TCBn and TCD0 which are also present on ATtiny3217. Maybe you include that in the future update because it would be much easier for us Bascom lovers (and even more for total beginners) to do it "Config" way Smile

My next step is implementing 8bit ADC to be able to very fast read (sample) high impedance voltage sources.....I don't expect so much problems as "Config ADC0" (Config ADC1 doesn't exist in current Bascom but I won't need it) seems to be well supported for xtinys...
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5093
Location: Holland

blank.gif
PostPosted: Thu Aug 13, 2020 2:16 pm    Post subject: Reply with quote

the equivalent code is : Config Tca0 = Pwm_bot , Prescale = 1 , Resolution = Normal , Compare0 = Enabled , Run = On

there are actually 2 modes that do bottom/bottom i chose the single slope while you have double slope. the problem was however the RUN=ON
and that demonstrate another problem : i tried to keep syntax close to xmega. but that is not always clear.

you are right about the additional devices. i implemented them all now ; multi aci, dac, adc, etc.
except the timers. in fact the timer only implements tca. it is the last thing to do.
one note : when you manual set bits, you can not port the code. you best use the bascom syntax.

_________________
Mark
Back to top
View user's profile Visit poster's website
Skrivo

Bascom Member



Joined: 15 Jul 2020
Posts: 11

slovenia.gif
PostPosted: Thu Aug 13, 2020 10:34 pm    Post subject: Reply with quote

albertsm wrote:
the equivalent code is : Config Tca0 = Pwm_bot , Prescale = 1 , Resolution = Normal , Compare0 = Enabled , Run = On

there are actually 2 modes that do bottom/bottom i chose the single slope while you have double slope. the problem was however the RUN=ON
and that demonstrate another problem : i tried to keep syntax close to xmega. but that is not always clear.

you are right about the additional devices. i implemented them all now ; multi aci, dac, adc, etc.
except the timers. in fact the timer only implements tca. it is the last thing to do.
one note : when you manual set bits, you can not port the code. you best use the bascom syntax.


Mark, yes this one: "Config Tca0 = Pwm_bot , Prescale = 1 , Resolution = Normal , Compare0 = Enabled , Run = On" now works, thanks. But please add "Config TCA0" (and other timers) for xtiny in HELP.

P.S. I already tested ADC0 using Bascom syntax only and it seems to work very well. I can see the ADC on xtiny (and mega 0) is highly improved compared to "old" tinys/megas especially speed (10 - times faster!). If someone has a new project that needs a lot of ADC then there is absolutely no doubt; go for xtiny 0 or 1 series (or new mega 0 series).

Mark: as you put a lot of hours implementing Bascom support for xtinys, why you don't add Bascom support for new ATmega 0 series (only a few MCUs) as all those new ones have very similar or totally equal registers (for example: I can't find TCA difference when comparing ATtiny3217 and ATmega4809)? I would certainly pay for mega 0 series Bascom add-on as my brains can't work in "alien" C environment (Studio 7).
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5093
Location: Holland

blank.gif
PostPosted: Fri Aug 14, 2020 8:49 am    Post subject: Reply with quote

like i wrote in another topic. first i like to fully finish the xtiny support. as you see the help is not complete yet.
after that i will add the mega devices since indeed there seem to be little of them. and for a big part they seem similar (except for memory , fuses, etc.)
the idea is to add them to xtiny add on free of charge.

_________________
Mark
Back to top
View user's profile Visit poster's website
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 34

blank.gif
PostPosted: Fri Aug 14, 2020 10:15 am    Post subject: Reply with quote

Well, I'll pay extra and dare I say I'm not alone. I'm used to paying for good things.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum