Sub-Microsecond Pulse Generation

Go To Last Post
73 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Dear Lee, would you tell me what changes I should make in this code, in order to use it in ATmega16? I sent this code to my ATmega16 chip but I could detect no outputs at portB pins!!

Since there are no calls or jumps or stack operations or interrupts, the code should run on any AVR with a port B and with the I/O ports within reach of IN/OUT. This includes Mega16.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes it should, but I'm afraid it doesn't work :(

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

it doesn't work

So, you have a properly wired AVR that is set up to properly run other programs, and you assemble the above program into a .HEX file, and you do a full ISP programming sequence beginning with signature check and chip erase and continuing through flash program and verify, and the ISP is successful. And then when you attach a 'scope probe to one of PB0, PB1, PB3, or PB4 on a scale of a microsecond or so per division what do you see?

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

S-Sohn wrote:
arvinik wrote:
I don't know how to code it!! :(
Can you specify "I don't know"?
- lack of AVR experience
- lack of microcontroller experience
- lack of C experience

Lack of programming experince!! :( & as I mentioned before, I'm using BASCOM-AVR as the compiler...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Quote:

it doesn't work

So, you have a properly wired AVR that is set up to properly run other programs, and you assemble the above program into a .HEX file, and you do a full ISP programming sequence beginning with signature check and chip erase and continuing through flash program and verify, and the ISP is successful. And then when you attach a 'scope probe to one of PB0, PB1, PB3, or PB4 on a scale of a microsecond or so per division what do you see?

Lee

Yes I think I've done all the sequences properly, and this is the exact code which I'm writing to the chip using BASCOM:

$regfile = "m16def.dat"
$crystal = 8000000
 $asm
   LDI   R16, 0x1b
   OUT   DDRB, R16   ; PB0,1,3,4 as  outputs
   LDI   R16, 0X01
   LDI   R17, 0X02
   LDI   R18, 0X08
   LDI   R19, 0X10
  The_loop:
   OUT   PORTB, R16
   NOP
   NOP
   NOP
   OUT   PORTB, R17
   NOP
   NOP
   NOP
   OUT   PORTB, R18
   NOP
   NOP
   NOP
   OUT   PORTB, R19
   NOP
   RJMP   The_loop
 $end Asm
 End

There's no error report and flash verification is OK.
And then when I attach a scope probe to one of PB0, PB1, PB3, or PB4 on a scale of a microsecond or so per division, I see nothing! all of them seem to be permanently low.

Arvin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm not at my bench, but I would try these three or four things:

If you have an LED and ~ 330 or 470 ohm resistor, put it on a pin and include a sub to flash it on start up of your program. It will confirm the programmer / chip / program system. You can eliminate it when everything is working as expected. Use one of your desired output pins for now. This will also confirm that it is set as a digital output pin. Flash it slowly for human verification, i.e. On 1/2 sec, off 1/2 sec, loop a few times, etc.

May not matter, but try putting your in-line asm within a Basic program framework. Start with a label for a Main routine, or whatever. Precede your asm with several Bascom instructions, and then insert the asm within that structure.

May not matter, there are many formats for defining the pins & ports, but try defining your pin output definitions as a Bascom instruction, as part of your initializations, instead of within the asm routine.

One possible format is: (bits 0,1,_,3,4 as outputs)
Config PortB = &B00011011 '0=Input, 1=Output

I've seen several chips discussed, I'm not sure which you are actually using. If the pins have open collector outputs you will need a pull up resistor from the pin to V+. I don't know if any port B's on any AVRs use open collector or not, but it is another reason outputs do not do as expected. A 10K pull up is a trivial addition to test this without even digging through a data sheet. It can be done with the internal pullups, but testing it in hardware is less error prone, at this debugging stage.

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't know BASCOM, or how your $asm segment gets processed. Does BASCOM make that the whole program? Or is it really a null BASCOM program with no link to your $asm segment? Is there a listing of some sort? Does your code start at 0 of .CSEG?

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Arvink i  edited your code and on the simulator of bascom it will work!!

it is strange that you never saw any  error messages??
 

 

$regfile = "m168def.dat"
$crystal = 8000000
$hwstack=32
$swstack=8
$framesize=24

Config Portb = Output

 

 $asm
   LDI   R16, &H1b
   LDI   R16, &H01
   LDI   R17, &H02
   LDI   R18, &H08
   LDI   R19, &H10
  The_loop:
   OUT   PORTB, R16
   NOP
   NOP
   NOP
   OUT   PORTB, R17
   NOP
   NOP
   NOP
   OUT   PORTB, R18
   NOP
   NOP
   NOP
   OUT   PORTB, R19
   NOP
   RJMP   The_loop
 $end Asm
 End

trying to think simple

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

norbert57 wrote:

Arvink i  edited your code and on the simulator of bascom it will work!!

 

You do realise that it is 9 years since this topic had a post?

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I saw, but nobody answered with the right solution and i did!!! what is the problem?? i am a newbee on topics,
and was looking for a solution for my own problems,
i am a Bascom  user too and  learn how to program (as a  60-year-old ) step by step
there is nothing wrong  with that don't you think?

cheers, Norbert

trying to think simple

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Welcome to the Forum, Norbert.

 

Nice solution for anyone else with a similar problem.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

norbert57 wrote:
and was looking for a solution for my own problems,

I'll bite.  I don't have BASCOM handy.

 

I see two differences:

1)  Using 0x notation for hex constants.

2)  Using BASCOM Config versus AVR machine sequence.

 

I cannot see where 2) would make any difference.  Is it 1) ?  The BASCOM Help is particularly sparse with respect to constants in different bases.  Urban knowledge?  Amphersand isn't even listed as a valid character in a program line:

 

haracter
name

ENTER Terminates input of a line
Blank ( or space)
' Single quotation mark (apostrophe)
* Asterisks (multiplication symbol)
+ Plus sign
, Comma
- Minus sign
. Period (decimal point)
/ Slash (division symbol) will be handled as \
: Colon
" Double quotation mark
; Semicolon
< Less than
= Equal sign (assignment symbol or relational operator)
> Greater than
\ Backslash (integer/word division symbol)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@ theusch,
sorry i  don't quite understand  what your point is in the list you provided,
bascom uses a variant of BASIC, with extensions to make some things possible.
assembler is much directer,

but when i just pasted the listing  for bascom assembler , and tried to compile it, it came up with som errors,

and i just  looked in the help files to correct the  issues,

the only shortcut i took is to  config the whole port as output.

bascom is quite handy  but for many  solutions  one has to find elaborate  approaches

(hope that is good english)

learning all the time

cheers,

Norbert

 

trying to think simple

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

norbert57 wrote:
what is the problem??

You specifically addressed your post to Arvink  - so you seemed to be expecting that (s)he  is still looking for an answer to this.

Brian was just pointing that his/her last post was 9 years ago - so that is rather unlikely.

 

Not a problem as such - just checking that you were aware (many newbies don't seem to spot this).

 

EDIT

 

The usual etiquette when replying to a (very) old thread like this is to prefix your answer with something like, "I know this is a (very) old thread, but ..."

Last Edited: Mon. Aug 14, 2017 - 03:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

allright..... i was just very enthousiastic that i could even solve a problem  concerning assembler...
and you never know for whom this could be usefull

we are all learning isn't it??

no offences intended though

cheers!

trying to think simple

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I never got an answer, I guess, about the BASCOM syntax for constants in various bases.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The only mention I can find in the entire Bascom manual for "&h" as a valid prefix for hex is in the description of the INPUT keyword. Not sure if that translates to the assembler or not.
.
In the past I've found the online Bascom manual to be very good but it seems a bit wooly on what constitutes a numeric constant.
.
EDIT : Having said that I just looked at the PDF manual and page 516 within. So, yes &h is a valid prefix in both BASIC and Asm.

Last Edited: Mon. Aug 14, 2017 - 06:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow,  you understood the question,
in the help file there is a section  on  language fundamentals

and that helps a lot , i stumbled on  the difference of  

dot-comma (semicolon??)(;) , 

the colon( :)

the comma,

so for instance if you  wanna print two things:

PRINT "this is the value blablabla   "  ; variable          semicolon is a separator

to read a parameter from  uart:  INPUT "what is your number??  ", A     the comma looks like a separator, but is an indication that a value is  expected

main_loop:  this is a label to jump to .... colon is the  sign to  appoint an certain place in the listing, for instance the interruptvector, or  a routine to calculate  some things etc...

that is all i use for this moment.

and the compiler shows errors when  one makes  mistakes in this

 

 

 

 

trying to think simple

Last Edited: Mon. Aug 14, 2017 - 08:36 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I never got an answer, I guess, about the BASCOM syntax for constants in various bases.

 From the on-line manual, under Bascom Language Fundamentals, then under Language Fundamentals:

 

You can specify a hexadecimal or binary number with the prefix &H or &B.

a = &HA , a = &B1010 and a = 10 are all the same.

 

The manual doesn't specifically state whether this is for just the main language usage, for can be also be used in Assembly routines, but as far as I know this works in Assembly Routines as well.

I though there was also ah Octal type, but I don't see it mentioned here with the Hex, Decimal, and Binary formats. 

 

JC  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's probably moot but this is the bit of the manual I was looking at:

 

Which confirms &h (and 0x and $) as hex prefixes and &b and 0b as binary prefixes but no mention of Octal.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Which confirms &h (and 0x and $) as hex prefixes and &b and 0b as binary prefixes but no mention of Octal.

Thanks for that digging.  Which brings me back to what inspired this snipe hunt:  Norbert in #59 posted "corrected" code, and implied that the OP's code would cause errors.

 

My scan of the revised code indicated only two differences, and explicit DDR manipulation versus BASCOM control line, and 0x for hex constants.  Your quote implies that 0x is valid.  So

I see two differences:

1)  Using 0x notation for hex constants.

2)  Using BASCOM Config versus AVR machine sequence.

 

I cannot see where 2) would make any difference.  Is it 1) ? 

Perhaps the 0x is case-sensitive?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Darn you both, I spent an hour on this...  wink

 

I'm running Bascom 2.0.7.9 which is the latest release, (actually a pre-release, one newer than the "current version").

 

1)

One can put a "Bascom wrapper" around the Asm code block, or not, Bascom doesn't care.

If you just have the Asm code block it will structure it correctly without the "wrapper".

e.g.:


Config statements

Main:

  Do

     Asm block

  Loop

  End

 

2)

 One can use the Bascom instructions to configure Port B as an output port, or directly write to the config register with Asm, it doesn't matter.

 

3)

One CAN use &H..., &h..., and $... for Hex; and &B... and  &b... for binary.

 

4)

It appears that one CAN NOT use 0X... or 0x... for Hex.

That generates an Error Code.  (Error 377, in case it matters).

 

Hence, the correction to the code is in fact a correction, as changing the 0X...'s to &H...'s will allow the program to compile, and then be run.

 

For the record, I changed the micro and the clock to a M328P to run the program on physical hardware, and it works, for the versions that do compile correctly.

 

Well that was fun, (well as much fun as a hard core Basic programmer can have when they have to revert to Asm!) cheeky

 

JC

 

Edit:

One usually includes the configuration header instructions within the program.

If they are omitted from the program, then they are pulled from the IDE.

 

'Configuration Header:
$regfile = "m328pdef.dat"                                   'Micro used
$crystal = 16000000                                         'Micro's Clock Frequency

$hwstack = 64                                               'Hardware Stack
$swstack = 64                                               'Software Stack
$framesize = 64                                             'Frame Space

 

 

 

Last Edited: Wed. Aug 16, 2017 - 10:25 PM

Pages