I can't seem to find mega328p uno pwm examples and the forum posts suggest problems.
I get a 2.66 Khz square wave with this code but if I put the pwm outside the do loop I don't.
Are there any examples please. I googled for hours and tried pic examples.
Let me clarify code tags are three tildes before and after code or Control-ALT-C
"~~~"
your code
"~~~"
Here is the manual manipulation of PWM/Output Compare registers for hardware PWM on the mega328p UNO.
#chip mega328p,16
'************pwm************************
DIM PWM_LED as Word Alias OCR1AH,OCR1AL
PWM_LED = 0
dir PortB.1 out 'OC1A
TCCR1A = B'10000001' 'Clear OCR1A on compare match, 8 bit fast pwm
TCCR1B = B'00001010' 'PRESCALE 1/8, 8 MHz CK fuse, equals 7.81KHz
'50% duty cycle
PWM_LED = 127
do
loop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you kent. I couldn't find that in the demos,manual,this forum,google.
Having just bought a uno I found most info is c++. Confusing for a beginner to know if pic code can be used with arduino.
I notice there's no #include <uno_mega328p.h> in your code. When is it necessary?
Thanks for explaining ~~~. I had used ~~~~ at the begining but not at the end. Where is this explained in the site info? thanks again...I'll be back. </uno_mega328p.h>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hardware PWM [HWPWM] (as shown in the manaul) support PICs only. Got time to write a library - should be relatively simple.
~~~~
#include <uno_mega328p.h>
~~~~
This is an ease of use library that allows the users to address the ports in a similar way to the Arduino IDE.</uno_mega328p.h>
Re the ~~~~. See the </> or the ? in every posting. These explain how to insert code and the Help respectively.
Last edit: Anobium 2017-03-01
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@stan cartwright
Yea, when you can't find an inbuilt GCB command you have to improvise :). That is the beauty about GCB you can dig right in to the datasheet and set the respective device registers to do exactly what you need. Unfortunately, Hugh/Evan/ and the rest of the developers are doing such a good job they have got most all the bases covered now, and the sense of discovery is waning :(.
When Hugh started developing the Atmel AVR devices for GCB, it was definetely a bold and exciting move. So now having dual use code for PIC and AVR in most all cases is pretty unique.
C++, when I see methods and "."'s, my brain goes blank...ughh.
@Anobium
I'll have a look at the hpwm.h for the mega and tiny and let you know.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can't seem to find mega328p uno pwm examples and the forum posts suggest problems.
I get a 2.66 Khz square wave with this code but if I put the pwm outside the do loop I don't.
Are there any examples please. I googled for hours and tried pic examples.
Last edit: Anobium 2017-03-01
Code tags?
Because you are only getting software PWM with the Atmel devices currently? Opportunity knocks for a AVR HPWM library.
I put the code tags in.....
Let me clarify code tags are three tildes before and after code or Control-ALT-C
"~~~"
your code
"~~~"
Here is the manual manipulation of PWM/Output Compare registers for hardware PWM on the mega328p UNO.
Thank you kent. I couldn't find that in the demos,manual,this forum,google.
Having just bought a uno I found most info is c++. Confusing for a beginner to know if pic code can be used with arduino.
I notice there's no #include <uno_mega328p.h> in your code. When is it necessary?
Thanks for explaining ~~~. I had used ~~~~ at the begining but not at the end. Where is this explained in the site info? thanks again...I'll be back. </uno_mega328p.h>
Hardware PWM [HWPWM] (as shown in the manaul) support PICs only. Got time to write a library - should be relatively simple.
~~~~
#include <uno_mega328p.h>
~~~~
This is an ease of use library that allows the users to address the ports in a similar way to the Arduino IDE.</uno_mega328p.h>
Re the ~~~~. See the </> or the ? in every posting. These explain how to insert code and the Help respectively.
Last edit: Anobium 2017-03-01
Like others,when I've got a list of stuff I had trouble finding,I'll make a help sheet for stuff like pwm,timer interrupts etc
@stan cartwright
Yea, when you can't find an inbuilt GCB command you have to improvise :). That is the beauty about GCB you can dig right in to the datasheet and set the respective device registers to do exactly what you need. Unfortunately, Hugh/Evan/ and the rest of the developers are doing such a good job they have got most all the bases covered now, and the sense of discovery is waning :(.
When Hugh started developing the Atmel AVR devices for GCB, it was definetely a bold and exciting move. So now having dual use code for PIC and AVR in most all cases is pretty unique.
C++, when I see methods and "."'s, my brain goes blank...ughh.
@Anobium
I'll have a look at the hpwm.h for the mega and tiny and let you know.