Been using BASCOM and AVRs for a while now, but never had to use a timer until now.
I need to jump to a sub every 50mS or so (the exact time can be a bit more or less than 50mS, as long as it is a constant, precise time).
The sub only does simple/quick operations, such as toggling an output pin or incrementing an integer variable.
I'm assuming I need to use a timer for this, is it best to use TIMER0 or TIMER1?
The chip will still be doing other things such as reading switches and setting LEDs on and off while all this is happening. Nothing that will be affected while it jumps to the sub called by the timer and does whatever is in there.
Chip is a Tiny45 in this case, but I'm assuming it's very similar for most of the 8 bit AVRs.
If someone could post some example code on how to do this it would be gratefully appreciated.
[b:f2a6002db4][color=red:f2a6002db4](BASCOM-AVR version : 2.0.7.8 )[/b:f2a6002db4][/color:f2a6002db4]
↧
BASCOM-AVR : Timer usage : NEWTOPIC
↧
BASCOM-AVR : Timer usage : REPLY
You can use Timer0 in CTC mode.
In this mode the timer counts only to OCR0A value, not to 255, and then clears to 0.
When it reaches OCR0A value, the interrupt COMPARE0A occures (if enabled).
[code:1:2f74e5f13c]'--------------------------------------------------------------
'Timer0 50ms interrupt
'using internal oscillator
'--------------------------------------------------------------
$regfile = "Attiny45.dat"
$crystal = 1000000
$hwstack = 128
$swstack = 64
$framesize = 64
'$baud = 9600
'''''''''''''''''''''''''''' MAIN '''''''''''''''''''''''''''''''''''
'set main clock divider to 8 (so that clock=1000000 Hz)
Clkpr = Bits(clkpce)
Clkpr = Bits(clkps1 , Clkps0)
'init ports
Config Portb = Output
'init timer0
Tccr0a = Bits(wgm01) 'Timer0 in CTC mode
Tccr0b = Bits(cs02) 'prescaler 256
'with OCR0A we set the frequeny of interrupts
'time = 50ms -> freq = 20 Hz
'OCR0A = ($crystal / frekv / prescaler) - 1
'OCR0A = (1000000 / 20 / 256) - 1
Ocr0a = 194
Enable Compare0a 'enable interrupt COMPARE0A
on compare0a tim0_isr
Enable Interrupts 'enable all interrupts
Do
Loop
End
'''''''''''''''''''''''''''' END MAIN '''''''''''''''''''''''''''''''
Tim0_isr:
Portb = Not Portb 'test - invert all bits in portB
Return
[/code:1:2f74e5f13c]
↧
↧
Share your working BASCOM-AVR code here : hx8357c 480x320 display : REPLY
Nice, but why only Blue/White? It's a full color LCD and may looks like this :D :
[URL=http://vfl.ru/fotos/9debcce417206672.html][img:4294646dc1]http://images.vfl.ru/ii/1494664087/9debcce4/17206672_s.jpg[/img:4294646dc1][/URL][URL=http://vfl.ru/fotos/1c8a603717206687.html][img:4294646dc1]http://images.vfl.ru/ii/1494664191/1c8a6037/17206687_s.jpg[/img:4294646dc1][/URL][URL=http://vfl.ru/fotos/9142eaa417206698.html][img:4294646dc1]http://images.vfl.ru/ii/1494664234/9142eaa4/17206698_s.jpg[/img:4294646dc1][/URL][URL=http://vfl.ru/fotos/3176933117206702.html][img:4294646dc1]http://images.vfl.ru/ii/1494664260/31769331/17206702_s.jpg[/img:4294646dc1][/URL][URL=http://vfl.ru/fotos/42c1e9c417206708.html][img:4294646dc1]http://images.vfl.ru/ii/1494664278/42c1e9c4/17206708_s.jpg[/img:4294646dc1][/URL][URL=http://vfl.ru/fotos/9838775c17206709.html][img:4294646dc1]http://images.vfl.ru/ii/1494664294/9838775c/17206709_s.jpg[/img:4294646dc1][/URL][URL=http://vfl.ru/fotos/473533a417206717.html][img:4294646dc1]http://images.vfl.ru/ii/1494664314/473533a4/17206717_s.jpg[/img:4294646dc1][/URL]
↧
BASCOM-AVR : KamProg for AVR, MEga328 Programme error : NEWTOPIC
Hi,
I've been using the KamProg USB unit with mega8 chips for some time now, but the current project needs a chip with more memory, so to keep things simple, I am trying to use a mega328.
I have this problem on 2 different machines, both windows 10
When I compile (F2), Bascom throws an error...
[quote:a2cfcfbdaa]
There was an error during the execution of this program.
The application might become unstable and even useless.
It's recommended that you save your work and close this application.
Access violation at address 08509491 in module 'kavrlib.dll'. Read of address 00000018.
------------------------------------------------------------------------------
Exception log with detailed tech info. Generated on 15/05/2017 01:45:21.
You may send it to the application vendor, helping him to understand what had happened.
Application title: BASCOM-AVR
Application file: C:Program Files (x86)MCS ElectronicsBASCOM-AVRbascavr.exe
------------------------------------------------------------------------------
Exception class: EAccessViolation
Exception message: Access violation at address 08509491 in module 'kavrlib.dll'. Read of address 00000018.
Exception address: 08509491[/quote:a2cfcfbdaa]
If I enter the programmer in manual mode, I can identify the chip, but if I try to upload the buffer to the chip, the same error occurs.
I have re-installed Bascom with the licence (as administrator) and re-installed the KamProg software v2.4 (as administrator) and run Bascom as administrator.
Changing the def back to mega8 works fine.
[quote:a2cfcfbdaa]$regfile = "M328def.dat"
$crystal = 1000000
$swstack = 16
$hwstack = 40[/quote:a2cfcfbdaa]
Any ideas please as I would like to get the chip programmed this week.
Many thanks,
David
(ps full error dump attached)
[b:a2cfcfbdaa][color=red:a2cfcfbdaa](BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.7.8 )[/b:a2cfcfbdaa][/color:a2cfcfbdaa]
↧
BASCOM-AVR : KamProg for AVR, MEga328 Programme error : REPLY
Think I might have found the answer. I had a look in the KamProg devices.xml file and found s def doe a mega328p.
It seems to have solved the problem. More testing required
Thanks
David
↧
↧
Share your working BASCOM-AVR code here : Library for ST7735R display : REPLY
Sergei! I ask you to add fonts with the support of the Cyrillic if possible. Also I ask to add fonts with a larger size. How to make fonts? Thank you.
↧
BASCOM-AVR : Can not Compile my Programm :/ : NEWTOPIC
I think i have a Newbie Problem again.
I wrote a 52 kb Programm with 1959 Lines. When i Compile it, it saves the HEX file with 1kb. The data Flash from it, to a Mega32 is 158bytes.
Is there any Line Limit in the Programm?
Do i make in the SRAM any mistakes, that it dont work? :((
[b:7b03a47e8e][color=red:7b03a47e8e](BASCOM-AVR version : 2.0.7.9 , Latest : 2.0.7.8 )[/b:7b03a47e8e][/color:7b03a47e8e]
↧
BASCOM-AVR : Can not Compile my Programm :/ : REPLY
I found that Problem: i hve to many AND comands in a line. How can i set some of this in the next Line, so that it will still work, as it will be in one line?
↧
BASCOM-AVR : Can not Compile my Programm :/ : REPLY
you can do it like this :
if a <> and b<>1 then
if c<>2 then
end if
end if
I have no idea how many and you have but when there are a lot, you might consider a table like
[code:1:60eb6795ca]restore somelabel
blag=0
for j=1 to 20 '20 values
read v 'read the byte
if x=v then 'found it
bFlag=1 : exit for
end if
next
if bflag=0 then
dosomething
end if
somelabel:
10,20,40,50 , 100 'etc[/code:1:60eb6795ca]
you do not need to code the above, just use the lookdown function.
↧
↧
BASCOM-AVR : Can not Compile my Programm :/ : REPLY
I tryed many, and this weird coding shows me the lest errors. :D
I the BASCOM PDF is written that there are no limits for a the Line.
Must be a Bug or something. :/
↧
BASCOM-AVR : Can not Compile my Programm :/ : REPLY
you must end the line with THEN
I advise to check the lookdown function. it will make your code much simpler.
↧
BASCOM-AVR : Can not Compile my Programm :/ : REPLY
Table lookup with the lookdown function is by far the best to do this. But if you wanted, a Select case structure would do this too.
Something like
[code:1:38a8f5dd4d]
select case wert1
case 329 'the cases you dont want something to happen
case 370
.... many other case statements
case else 'the only one you want
'do what you want
end select
[/code:1:38a8f5dd4d]
That at least avoids those huge AND blocks
↧
BASCOM-AVR : Atmel-ICE Porgrammer : REPLY
Hi,
Programmer [AVRISPmkII] seems to be discontinued.
The successor is [Atmel - ICE], but writing from the command line is hard to use.
I hope for BASCOM's IDE urgently!
↧
↧
BASCOM-AVR : Can not Compile my Programm :/ : REPLY
[quote:de4c9770e8="MichaelB."]I wrote a 52 kb Programm with 1959 Lines.[/quote:de4c9770e8]
That's not a program, that's a mess and can be done much leaner:
[code:1:de4c9770e8]Dim Wert1 As Word
Dim Tmp As Word
Dim wflag as Boolean
Wert1 = 274
If Wert1 < 275 Or Wert1 > 541 Then
wflag = 1
Else
Tmp = Wert1 - 268
Tmp = Tmp Mod 7
If Tmp > 0 Then
wflag = 1
Else
wflag = 0
End If
End If
If wflag = 1 Then
' set portpins
End If[/code:1:de4c9770e8]
↧
BASCOM-AVR : Low Power Sleep Project : NEWTOPIC
I have a project that requires me to have a processor that can sleep until one of 2 buttons is pushed and
then run 2 simple PWM LED dimmer/flashers. When the unit is off you press once to get the respective LED
to turn on, a 2nd time to make it flash and a 3rd time makes it turn off.
Since I am not one to re-invent the wheel I am curious if anyone has done something like this and how you
went about it. An inexpensive AVR such as a TINY13 would be most desirable.
Suggestions?
THANKS in advance....
[b:add3601508][color=red:add3601508](BASCOM-AVR version : 2.0.7.8 )[/b:add3601508][/color:add3601508]
↧
BASCOM-AVR : Low Power Sleep Project : REPLY
Hi,
I have a project close to your wishes.
If you can use BASCOM, you can remodel this and achieve your purpose.
Unfortunately, the document is in Japanese.
Video.
https://www.youtube.com/watch?v=PjA8SD0dZFY&feature=youtu.be
Site.
http://www.ne.jp/asahi/shared/o-family/ElecRoom/AVRMCOM/LedTableLight/LedTableLight.html
By the way, there are many earthquakes in my country.
↧
BASCOM-AVR : Low Power Sleep Project : REPLY
[quote:e3b2e020aa="O-Family"]Hi,
I have a project close to your wishes.
If you can use BASCOM, you can remodel this and achieve your purpose.
Unfortunately, the document is in Japanese.
Video.
https://www.youtube.com/watch?v=PjA8SD0dZFY&feature=youtu.be
Site.
http://www.ne.jp/asahi/shared/o-family/ElecRoom/AVRMCOM/LedTableLight/LedTableLight.html
By the way, there are many earthquakes in my country.[/quote:e3b2e020aa]
Interesting. This may be a good start. Since I can't read Japanese can you please tell me what the components are which are
represented by a rectangle with a circle inside hooked to PB2?
Fortunately the code is short.
I wish my school had offered Japanese courses...........
↧
↧
BASCOM-AVR : Low Power Sleep Project : REPLY
[quote:2f4054098a="rkumetz"]Interesting. This may be a good start. Since I can't read Japanese can you please tell me what the components are which are
represented by a rectangle with a circle inside hooked to PB2?[/quote:2f4054098a]
This is a vibration (tilt) switch.
Mercury balls or steel balls are contained in the cylinder of the sensor, and mechanical inclination and vibration are detected.
This can be changed to a push button switch.
[quote:2f4054098a="rkumetz"]I wish my school had offered Japanese courses...........[/quote:2f4054098a]
There is a good teacher of Google translation on the Internet!
Please translate and read the site on Google.
http://translate.google.com/translate?hl=ja&sl=ja&tl=en&u=http%3A%2F%2Fwww.ne.jp%2Fasahi%2Fshared%2Fo-family%2FElecRoom%2FAVRMCOM%2FLedTableLight%2FLedTableLight.html
↧
BASCOM-AVR : Simple Sample Programmer : NEWTOPIC
Hello,
My AVRISP MKII from Atmel stopped working. Both Bascom and Atmel Studio 4 connects to the the programmer. Bascom gives me the message "Could not read device ID. Make sure that target chip matches the $regfile directive from your code"
I have to do some urgent programming to do, so I thougth I would build the parallel Sample programmer (I have an USB to Parallel converter I bought 10 years ago, and never used)
The problem is that my Mega1284P runs on 3.3Volt, and I belive that the USB to parallel device is giving a 5V TTL output.
My question is, can I connect the programmer direct to the the MOSI, CLK, and Reset pins via a 330 Ohm resistor or should I use a voltage divider to convert the outputs to 3.3Volt.
Thanks,
gerrySC
[b:29a912e647][color=red:29a912e647](BASCOM-AVR version : 2.0.8.0 , Latest : 2.0.7.8 )[/b:29a912e647][/color:29a912e647]
↧
BASCOM-AVR : Simple Sample Programmer : REPLY
[quote:c282ee318b="gertc"]
I have an USB to Parallel converter [/quote:c282ee318b]
I did never get this working with various parallel port based programmers.
Does Atmel studio also give an error when trying to connect to the AVR trough the MkII?
↧