View previous topic :: View next topic |
Author |
Message |
autoguider
Joined: 24 Sep 2007 Posts: 82 Location: Aachen
|
Posted: Wed Dec 22, 2010 11:16 am Post subject: Atmel 168PU PWM2 problems |
|
|
Dear colleagues,
I am using Bascom 2.0.1.0 to program a 168PU CPU.
The used reg- file is "m168pdef.dat".
As the CPU has to fit into an existing board I have to use Pin 17 on the 28PDIP chip. Tis is PB3 and is attached to OC2A .
I need an output voltage that corresponds to a duty cycle value. The output signal will be given to a RC network.
First I configured PB3 as output
Config Portb.3 = Output
Then I configured the timer 2 as follows
Config Timer2 = Pwm , Compare A Pwm = Clear Down , Prescale = 256.
When looking into the TCCR2A and TCCR2B registers no PWM moe was selected.
So I set to TCCR2A = 11000001 and TCCR2B= 00000110
then the following instruction are to be executed:
Enable Interrupts
Enable Timer2
Start Timer2
After the last command I could see in the simulator that TCCR2B is set to 00000000.
Accordingly I modifiedTCCR2B again by Tccr2b = 6
The value of PWM2A is set to 20 by Pwm2a = 20
I checked the Tcnt2 register and found it permanently on value 0.
The counter does not count !
Then I checked the Power eduction register PRR . It is set on 0 which means that Timer2 is not shut down.
What am I doing wrong ?
Is there a chance to see the PWM result in the Bascom Simulator ?
kind regards
Chris |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Wed Dec 22, 2010 4:10 pm Post subject: |
|
|
Hi Chris,
you can use $regfile = "m168def.dat"
Following is an example how I configured the timers for a continuously changing RGB led setup.
Config Timer2 = Pwm , Prescale = 1024 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down
Config Timer1 = Pwm , Pwm = 8 , Prescale = 1024 , Compare A Pwm = Clear Down
Config Pinb.1 = Output 'PWM-R OUTPUT
Config Pinb.2 = Output 'PWM-G OUTPUT
Config Pinb.3 = Output 'PWM-B OUTPUT
'PWM1A=RED (R)
'PWM2A=GREEN (G)
'PWM2B=BLUE (B)
Sometines it seems to matter where in the config you put the "prescale".
Hope this helps
Hubert |
|
Back to top |
|
|
autoguider
Joined: 24 Sep 2007 Posts: 82 Location: Aachen
|
Posted: Wed Dec 22, 2010 11:09 pm Post subject: Timer2 PWM |
|
|
Dear Hubert,
many thanks for your useful advice. It is a major step ahead.
I changed the regfile to your recommendation also.
Now the TCCR2A and TCCR2B registers reflect some changes of the PWM parameters of the config timer2 commands.
The program is only tested with the AVR Simulator and I am not sure how close this simulation is to reality.
You can see the program in the thread.
The Sim Timers option of the AVR Simulator is activated.
With your advice I can see that the counter register values are changing.
Timer is running in fast PWM mod only. It does not react to matching the OCR2A register. In the simulation there is never a jump into the interrupt routine on COMPARE2A.
The Output pin was never activated. Didi you get an indication during your testing ?
Is this a bug in the Bascom environment or did I do something wrong ?
kind regards
Chris |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Thu Dec 23, 2010 7:26 am Post subject: PWM isr |
|
|
Hi Chris,
have tried several different scenarios and timers with PWM compare interrupts in the simulator. None of them work in the simulator. The standard timer interrupt works.
I have also noticed a long time ago that the display also depends a lot on the selected prescale.
Has to do with the number of clocks it takes.
Also be careful to use "NOSAVE" with the m168 (see Help...R23).
I have never used compare interrups with PWM but I assume it works in hardware.
The PWM certainly works in hardware (I use it).
You do not need to declare the MCS lib, it is automatically used (as much as I know).
Also use "print" instead of "printbin", unless you want to send binary.
Sorry that I can not be of more help with this problem.
Hubert |
|
Back to top |
|
|
|