Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

problem about config timer1 and timer3 on pwm mode(ATmega128

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

Bascom Member



Joined: 19 Apr 2017
Posts: 2

PostPosted: Wed Apr 19, 2017 8:36 pm    Post subject: problem about config timer1 and timer3 on pwm mode(ATmega128 Reply with quote

hello dear friends;

i have a problem on bascom with making same pwm from timer1 and timer3 ( Both are 16Bit) But before asking i think its better i say that i am new to electronics and bascom.

i want to control speed of 4 DC Motor using " ATmega1284p + L298N "
however i have same config for both timers but the result pwm is different with each other.

i need all of that 4 produced signals be same.(duty cycle= 50%==> like timer3 signals)

this image is showing my question clearly:

http://uupload.ir/files/7lr3_capture1.png

and this is bascom code:


Code:

$regfile = "m1284pdef.dat"
$crystal = 8000000

'#16bit:
Config Timer1 = Pwm , Pwm = 8 , Prescale = 256 , Compare_A_Pwm = Clear Up , Compare_B_Pwm = Clear Up
Config Timer3 = Pwm , Pwm = 8 , Prescale = 256 , Compare_A_Pwm = Clear Up , Compare_B_Pwm = Clear Up

Enable Interrupts
Enable oc1a
Enable oc1b
Enable oc3a
Enable oc3b
Enable Timer1
Enable Timer3

Config Porta = Input 'Controller Commands
Config Portc = Output 'Pins To L298 Driver

'#pwm
Config Portd.5 = Output 'PWM1A
Config Portd.4 = Output 'PWM1B
Config Portb.6 = Output 'PWM3A
Config Portb.7 = Output 'PWM3B

'Normal Start
Pwm1a = 125
Pwm1b = 125
Pwm3a = 125
Pwm3b = 125

'Pins To L298 inputs:
Portc.0 = 1
Portc.1 = 0
Portc.2 = 1
Portc.3 = 0

Portc.4 = 0
Portc.5 = 1
Portc.6 = 0
Portc.7 = 1
 



please help.
Best Regards.



(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Thu Apr 20, 2017 2:06 am    Post subject: JTAG fusebits? Reply with quote

Have you checked the JTAG fusebit settings?
Back to top
View user's profile Visit poster's website
zebelxan

Bascom Member



Joined: 19 Apr 2017
Posts: 2

PostPosted: Thu Apr 20, 2017 8:26 am    Post subject: i am new to bascom Reply with quote

dear friend thanks for reply. Wink

i am new to bascom and the code above is all my bascom project code.
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Thu Apr 20, 2017 10:39 am    Post subject: Fuses Reply with quote

There are some 'fuses' inside the microcontroller. To handle internal or external crystal, bootloader, speed of booting etc. One of these fuses enable/disable JTAG. If the JTAG is enabled some of the Portc pins will work different. So you will have to disable JTAG.

Do a small search in this forum about JTAG and fuses. It is always nice to know how these fuses are set. For instance the atmega88 can be shipped from factory running on a 8 Mhz internal RC clock but divided by 8. So running on 1 Mhz.

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1134

poland.gif
PostPosted: Thu Apr 20, 2017 10:57 am    Post subject: Reply with quote

If you have version 2078 it means you are registered because last demo is 2075.
If you are registered user why dont you upgrade your Bascom into 2080 where maybe your program issues are fixed Very Happy

I must point you one more thing. For Pwm this Interrupts are not needed and some of them disturb your program (not pwm).
In Bascom language, word "Enable" is used for giving permission for Interrupt. "Enabe" not "power on" device.
For "power on" such device like ADC or AC you can use "Start ADC", "Start AC". Similar "Stop AC", or "Stop ADC" for switch off.

With timer it also work but "Stop Timer" means "switch prescaler for no pulses"

After command "Config Timer = ..." you dont need to use "Start Timer" because it is done automatically.

To the point:
Code:
Enable oc1a 'means enable interrupt when Timer1 reaches OC1A value <-not needed in most cases for pwm
Enable oc1b 'means enable interrupt when Timer1 reaches OC1B value <-not needed in most cases for pwm
Enable oc3a 'means enable interrupt when Timer3 reaches OC3A value <-not needed in most cases for pwm
Enable oc3b 'means enable interrupt when Timer3 reaches OC3B value <-not needed in most cases for pwm
Enable Timer1 'means enable interrupt when Timer1 reaches Top <-this will never happen cause timer use only 8bit
Enable Timer3  'means enable interrupt when Timer1 reaches Top <-this will never happen cause timer use only 8bit
 


Upgrade your Bascom first. JTAG should have nothing to do with this because it is on PORTC where OC1A,OC1B,OC3A,OC3B they are on PORTD and PORTB
Back to top
View user's profile Visit poster's website
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