Hi, I need to have 3 pwm 16bit (or only 3 timers 16bit + relative interrupts). One good micro found within AVR's is ATMEGA328PB. Unfortunately this controller is very few documented. Someone could enclose an example with declarations of the 3 PWM and relative 16bit timers just to start with? Thanks a lot!
charlie-pater
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, first of all thanks for all the links. Unfortunately, however, it is not what I was looking for. I simply wanted a PWM, but also a 16bit timer with interrupt. The problem is being able to choose the frequency continuously from 50 to 10000Hz. The pwm duty can be any value. I chose the Mega328PB because I need 3 equal 16bit PWMs.
Thanks a lot
PS. It is quite difficult to understand how the constant avrtc1 and avrchan3 interact in the assemby. For example the prescaler can be changed?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I do not have the mega328PB. For those devices I did not have, I had to make some assumptions during development. My extended 16 bit TC library (TC3, TC4, TC5) was based off the mega2650 Mega board.
The mega328PB has three 16bit PWM's available, but only two PWM channels per TC instead of the three in the library.
Sub 1kHz values are probably not going to be valid if my recollection is correct. This is due to the effort to keep the library small and compact without using Word variables in preprocessing. In other words, compatible with the AVRtiny devices as well as the mega devices.
I am thinking that 50-10,000 kHz signal will have to have the TC registers manually operated. If the duty cycle is not important then I wouldn't use the PWM mode. Instead I would use the CTC mode (clear timer on compare match) and toggle the output for a 50/50 duty cycle.
The HPWM library automatically changes the prescale values as appropriate, but only for 1, 8, and 64 as noted in Help.
I will see if the way back machine can help with a CTC frequency example. Might take a bit.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
DDRB|=6; //Set pin PB1 & PB2 as output for OC1A & OC1B//Timer1setuppwmTCCR1A=0xA2; // Set OC1A & OC1B; WMG1[1]. Table 18-8 in Datasheet. & Table 18-9.TCCR1B=0x18;// Set WMG1[2] & WMG1[3]; tABLE 18-9TCNT1 = 0;// clear counterICR1=40000; // count of 40000 for a 20ms period or 50 Hz cycleOCR1A=2900; // start in the middle between 900 & 4900OCR1B=2900;//TCCR1B|=2;//set clock to divide by 8 and start TABLE
In GCB,,, TCCR1B |= 2 would be TCCR1B = ( TCCR1B AND 0xF8) OR 2
Hi, I need to have 3 pwm 16bit (or only 3 timers 16bit + relative interrupts). One good micro found within AVR's is ATMEGA328PB. Unfortunately this controller is very few documented. Someone could enclose an example with declarations of the 3 PWM and relative 16bit timers just to start with? Thanks a lot!
charlie-pater
I would recommend following the Help - that shows how to setup HPWM for the AVRs.
Have look and then come back here.
:=)
Here is the demo you need. Just change the #chip and frequency.
https://github.com/GreatCowBASIC/Demonstration_Sources/blob/main/PWM_Solutions/AVR_Command_Usage_Examples/Mega328p-007.gcb
and,
there are many PWM demos at this URL
https://github.com/GreatCowBASIC/Demonstration_Sources/tree/main/Vendor_Boards/ATMEGA328pb_boards/common_demostration_programs
Hi, first of all thanks for all the links. Unfortunately, however, it is not what I was looking for. I simply wanted a PWM, but also a 16bit timer with interrupt. The problem is being able to choose the frequency continuously from 50 to 10000Hz. The pwm duty can be any value. I chose the Mega328PB because I need 3 equal 16bit PWMs.
Thanks a lot
PS. It is quite difficult to understand how the constant avrtc1 and avrchan3 interact in the assemby. For example the prescaler can be changed?
@kent. You able to help?
@kent. You able to help?
@kent. You able to help?
I do not have the mega328PB. For those devices I did not have, I had to make some assumptions during development. My extended 16 bit TC library (TC3, TC4, TC5) was based off the mega2650 Mega board.
The mega328PB has three 16bit PWM's available, but only two PWM channels per TC instead of the three in the library.
Sub 1kHz values are probably not going to be valid if my recollection is correct. This is due to the effort to keep the library small and compact without using Word variables in preprocessing. In other words, compatible with the AVRtiny devices as well as the mega devices.
I am thinking that 50-10,000 kHz signal will have to have the TC registers manually operated. If the duty cycle is not important then I wouldn't use the PWM mode. Instead I would use the CTC mode (clear timer on compare match) and toggle the output for a 50/50 duty cycle.
The HPWM library automatically changes the prescale values as appropriate, but only for 1, 8, and 64 as noted in Help.
I will see if the way back machine can help with a CTC frequency example. Might take a bit.
Why not just write to the registers and hand craft the solution ?
Examine the datasheet and write the code. :-)
The latest version of PICSIMLAB has the atmega328p available. It may prove useful for testing before committing your code to hardware.
I found this on the web.. but, it may not work.
In GCB,,,
TCCR1B |= 2
would beTCCR1B = ( TCCR1B AND 0xF8) OR 2
Something like: