View previous topic :: View next topic |
Author |
Message |
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Mon Sep 11, 2017 9:29 am Post subject: very strange problem with PWM |
|
|
Hello friends
I am facing a very strange problem with the PWM in BASCOM 2.0.8.0, i am not giving any command to PWM still its by default both the PWM's are high (ATMEGA32A)
Code: | $crystal = 16000000
$hwstack = 32
$regfile = "m32def.dat"
$swstack = 10
$framesize = 40
'$sim
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Prescale = 1024
Config Lcdpin = Pin , Db7 = Portc.2 , Db6 = Portc.3 , Db5 = Portc.4 , Db4 = Portc.5 , E = Portc.6 , Rs = Portc.7
Config Lcd = 20 * 4
Cursor Off Noblink |
what should be the problem here??
Regards
Aniruddha
(BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.7.8 ) _________________ We are not innovating, we are just manipulating innovations done by Mother Nature....... |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Sep 11, 2017 9:35 am Post subject: |
|
|
try to remark this : Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Prescale = 1024 _________________ Mark |
|
Back to top |
|
|
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Mon Sep 11, 2017 9:44 am Post subject: |
|
|
hello Mark Sir,
you mean to say command out the like this:
Code: | $crystal = 16000000
$hwstack = 32
$regfile = "m32adef.dat"
$swstack = 10
$framesize = 40
'$sim
'Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Up , Prescale = 1024
Config Lcdpin = Pin , Db7 = Portc.2 , Db6 = Portc.3 , Db5 = Portc.4 , Db4 = Portc.5 , E = Portc.6 , Rs = Portc.7
Config Lcd = 20 * 4
Cursor Off Noblink |
i did this, result is pwm's are low.
???
Regards
Aniruddha _________________ We are not innovating, we are just manipulating innovations done by Mother Nature....... |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Sep 11, 2017 9:55 am Post subject: |
|
|
first of all, always leave out unrelated code like lcd in the sample.
second, describe better what your problem is. you say 'both pwm' but what is that? pwm0, pwm1 or pwm2 and a,b,c ?
Also, tell what you expect.
the config timer1 will setup the timer for pwm and set the pwm port A to output. the level can not be changed after that. _________________ Mark |
|
Back to top |
|
|
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Mon Sep 11, 2017 10:08 am Post subject: |
|
|
ok, will keep the suggestions in mind.
Problem is if i write code like this:
Code: | $crystal = 16000000
$hwstack = 32
$regfile = "m32adef.dat"
$swstack = 10
$framesize = 40
'$sim
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Prescale = 1024 |
and compile and burn it in the controller, i am getting PWM1A as high, which should not happen. earlier in the demo version i was using, same code worked fine.
why is it so??
Regards
Aniruddha _________________ We are not innovating, we are just manipulating innovations done by Mother Nature....... |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Mon Sep 11, 2017 10:24 am Post subject: |
|
|
when a problem is fixed in the demo, it can lead to this.
i see nothing wrong with the code : portd.5 is set to output.
no other ports are altered. and you specified pwn1a which is portd.5
if you do not want output you should use : COMPARE_A_PWM_NO_OUTPUT instead of COMPARE_A_PWM _________________ Mark |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Mon Sep 11, 2017 2:36 pm Post subject: |
|
|
With Clear_down your pin will be OFF/LOW with PWM=1023
If pin should be OFF/LOW with PWM=0 then configure it as Clear_up
It is your intention that frequency is so low? Maybe it is for some heater but look at the calculations.
Code: | $crystal = 16000000
$hwstack = 32
$regfile = "m32adef.dat"
$swstack = 10
$framesize = 40
' > UP <
Config Timer1 = Pwm , Pwm = 10 , Compare A Pwm = Clear Down , Prescale = 1024
' ^^^^^
'16000000Hz/Prescale 1024 = 15625Hz
'15625Hz/1024(10Bit PWM) = 15,25Hz
Pwm1a = 0 'LED_ON
Wait 2
Pwm1a = 1023 'LED_OFF
Wait 1
Pwm1a = 512 'LED_BLINK
End
|
|
|
Back to top |
|
|
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Tue Sep 12, 2017 12:19 pm Post subject: |
|
|
Hello Mark Sir,
I got it, in demo it was working in reverse way, like if i set PWM1A = 0 the input for MOSFET connected to PORTD.5 is low, but if i set PWM1A = 1023 then input is high.
in this version its working like this:
Code: | $crystal = 16000000
$hwstack = 32
$regfile = "m32adef.dat"
$swstack = 10
$framesize = 40
'$sim
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 1024
Do
Pwm1a = 100 'out put to MOSFET connected at PORTD.5 is high
Wait 1
Pwm1a = 1023 'out put to PortD.5 is low
Wait 5
'Pwm1a = 512
'Wait 1
'Pwm1a = 0
'Wait 1
Loop |
Thanks
Regards
Aniruddha _________________ We are not innovating, we are just manipulating innovations done by Mother Nature....... |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Wed Sep 13, 2017 12:23 am Post subject: |
|
|
Hmmm. 1023 in the code for 8bit PWM gives me a feeling you not understand "the clue"
8BitPwm (Pwm= means that timer will work/count from 0 to 255
9BitPwm (Pwm=9) means that timer will work/count from 0 to 512
10BitPwm (Pwm=10) means that timer will work/count from 0 to 1023
Prescale in the config in the simplest words will divide processor frequency.
...but PWM resolution do it too because timer must count into 1024 in the max resolution.
....... but you cannot use value 1024 for PWM=8 because it can hold/count up to 255.
Write value 1023 into 8Bit counter is not considered by processor the way you think |
|
Back to top |
|
|
mastermindjp
Joined: 18 Dec 2012 Posts: 51 Location: INDIA
|
Posted: Wed Sep 13, 2017 9:09 am Post subject: |
|
|
Hello EDC,
Thank you for the valuable guidance, literally i was not aware of the fact. Its good to have people like you around.
Thank you
Regards
Aniruddha _________________ We are not innovating, we are just manipulating innovations done by Mother Nature....... |
|
Back to top |
|
|
|