Author Topic: [Atmel studio] won't accept !==  (Read 9699 times)

0 Members and 1 Guest are viewing this topic.

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
[Atmel studio] won't accept !==
« on: July 10, 2018, 01:30:56 pm »
if (ADC_array_position !== ADC_array_end)

The compiler fails saying that there is nothing before "="
 

Offline ljwinkler

  • Supporter
  • ****
  • Posts: 48
  • Country: ie
    • LJ Winkler's blog
Re: [Atmel studio] won't accept !==
« Reply #1 on: July 10, 2018, 01:32:54 pm »
You can't have !==.  It's either != (not equal to) or == (equal to) :)

Offline Fred27

  • Supporter
  • ****
  • Posts: 726
  • Country: gb
    • Fred's blog
Re: [Atmel studio] won't accept !==
« Reply #2 on: July 10, 2018, 01:33:54 pm »
You would happen to be a JavaScript developer, would you?
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #3 on: July 10, 2018, 02:20:04 pm »
You would happen to be a JavaScript developer, would you?

Nope, apart from a short foray into BASIC  it has been C all the way.

== is to test one thing is equal to another, I was just making the assumption that I could invert it. presumably != is a dedicated "not equal to" operator.
 

Offline wraper

  • Supporter
  • ****
  • Posts: 16849
  • Country: lv
Re: [Atmel studio] won't accept !==
« Reply #4 on: July 10, 2018, 02:22:52 pm »
You would happen to be a JavaScript developer, would you?

Nope, apart from a short foray into BASIC  it has been C all the way.

== is to test one thing is equal to another, I was just making the assumption that I could invert it. presumably != is a dedicated "not equal to" operator.
I find it very strange that you never used != before.
 

Offline ljwinkler

  • Supporter
  • ****
  • Posts: 48
  • Country: ie
    • LJ Winkler's blog
Re: [Atmel studio] won't accept !==
« Reply #5 on: July 10, 2018, 02:24:01 pm »
In this case you could use:  if !(ADC_array_position == ADC_array_end)

Offline mbless

  • Regular Contributor
  • *
  • Posts: 227
  • Country: 00
Re: [Atmel studio] won't accept !==
« Reply #6 on: July 10, 2018, 02:42:43 pm »
It's just like >= and <=. There's only 2 symbols.
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: [Atmel studio] won't accept !==
« Reply #7 on: July 10, 2018, 03:47:20 pm »
You would happen to be a JavaScript developer, would you?

Nope, apart from a short foray into BASIC  it has been C all the way.

== is to test one thing is equal to another, I was just making the assumption that I could invert it. presumably != is a dedicated "not equal to" operator.
I find it very strange that you never used != before.

same. i can see you logic, but in C logical operators are either one or two symbols.

if i may.. i suppose "ADC_array_end" is something like "size of array".. like if you declare array[16] then ADC_array_end=15.

if this is the case i suggest you use either
Code: [Select]
#define ADC_ARRAY_SIZE 16

int ADC_array[ADC_ARRAY_SIZE];

...

if (ADC_array_position >= ADC_ARRAY_SIZE) {
 ..
}

..

or
Code: [Select]
int ADC_Array[16];
int ADC_Array_End = 15;

..

if (ADC_array_position  > ADC_Array_End) {
  ..
}

..

for the unlikely (but very possible) situation where you increment ADC_array_position , but for some reason it skips ADC_array_end
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1668
  • Country: us
Re: [Atmel studio] won't accept !==
« Reply #8 on: July 10, 2018, 04:05:59 pm »
In this case you could use:  if !(ADC_array_position == ADC_array_end)

That won't work either. This does:  if (!(ADC_array_position == ADC_array_end))
Complexity is the number-one enemy of high-quality code.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: [Atmel studio] won't accept !==
« Reply #9 on: July 10, 2018, 04:15:22 pm »
!= is a very common operator used in quite a few languages to indicate inequality. It surprises me to hear someone got past the "Hello World" stage without encountering it. I have yet to encounter a 3-character operator.
 

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3713
  • Country: us
Re: [Atmel studio] won't accept !==
« Reply #10 on: July 10, 2018, 04:23:20 pm »
Nope, apart from a short foray into BASIC  it has been C all the way.

== is to test one thing is equal to another, I was just making the assumption that I could invert it. presumably != is a dedicated "not equal to" operator.

In C (and most languages) you don't ever invert operators, only values.  You can't do something like !< or !>= either.  != is a separate operator from == that has the opposite value, but one isn't defined in terms of the other.

Someone asked about javascript because javascript has two "equality" comparison operators, == and ===.  So those two operators have inverses that are != and !==.  Again these are not syntactically created by applying inverse to the == and === operators, they are operators in their own right.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #11 on: July 10, 2018, 05:25:14 pm »
Nope, i have never had to use != before. I am now using ">" anyway, the problem was the last one in many i was looking at in writing some new code to run a project in a very different way to how I normally do it.
 

Offline exit_failure

  • Regular Contributor
  • *
  • Posts: 110
  • Country: de
Re: [Atmel studio] won't accept !==
« Reply #12 on: July 10, 2018, 06:13:41 pm »
I have yet to encounter a 3-character operator.

In C/C++ there are the bitshift and assign operators:

<<= and >>=

Code: [Select]
a <<= 2
is the same as

Code: [Select]
a = a << 2
« Last Edit: July 10, 2018, 06:16:31 pm by exit_failure »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: [Atmel studio] won't accept !==
« Reply #13 on: July 10, 2018, 09:09:00 pm »
Quote
I have yet to encounter a 3-character operator.
Fortran has logical operators up to 6 characters (heh.  2nd time I've had cause to mention fortran in the last couple of days.)".and.", ".not.", ".nequv."  (there are ".le." equivalents for the standard comparison operators as well)
Cobol apparently has "IF WS-NUM1 IS GREATER THAN OR EQUAL TO WS-NUM2 THEN", but since this is an EE forum, we can be excused for not ever having seen any cobol...  (and I don't think even cobol coders actually WRITE code like that.)
« Last Edit: July 10, 2018, 09:13:37 pm by westfw »
 

Offline glarsson

  • Frequent Contributor
  • **
  • Posts: 814
  • Country: se
Re: [Atmel studio] won't accept !==
« Reply #14 on: July 10, 2018, 09:27:58 pm »
In Forth one of the standard "operators" is */MOD that performs a multiply and division (with intermediate results as double precision) returning both the result of the division but also the remainder.
 
The following users thanked this post: newbrain

Online Monkeh

  • Super Contributor
  • ***
  • Posts: 7992
  • Country: gb
Re: [Atmel studio] won't accept !==
« Reply #15 on: July 10, 2018, 10:19:57 pm »
Nope, i have never had to use != before.

Have you considered actually reading a book on C? Obtaining some form of formal programming education? ... reading basically any code in the wild?
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: [Atmel studio] won't accept !==
« Reply #16 on: July 10, 2018, 11:01:06 pm »
Heck != is so ingrained that I see it used in casual conversation, usually by people who have some exposure to programming but not necessarily professional developers.
 
The following users thanked this post: wraper, Frank

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: [Atmel studio] won't accept !==
« Reply #17 on: July 10, 2018, 11:15:30 pm »
I have yet to encounter a 3-character operator.
In C/C++ there are the bitshift and assign operators:
<<= and >>=
C++20 will also add the three-way comparison "spaceship" operator <=>.

Offline Koen

  • Frequent Contributor
  • **
  • Posts: 502
Re: [Atmel studio] won't accept !==
« Reply #18 on: July 10, 2018, 11:21:58 pm »
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: [Atmel studio] won't accept !==
« Reply #19 on: July 10, 2018, 11:29:28 pm »
I have yet to encounter a 3-character operator.

Weakly typed languages (for example, PHP and Javascript) often have both "==" and "===", for example

  1 == true
  1 === true

give different results.
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline Cerebus

  • Super Contributor
  • ***
  • Posts: 10576
  • Country: gb
Re: [Atmel studio] won't accept !==
« Reply #20 on: July 11, 2018, 12:17:51 am »
!= is a very common operator used in quite a few languages to indicate inequality. It surprises me to hear someone got past the "Hello World" stage without encountering it. I have yet to encounter a 3-character operator.

"/:=", "divide and becomes", an assigning division operator in Algol 68 which assigns ENTIER(left/right) to left and returns the remainder of left/right as its result. So:

Code: [Select]
REF INT remainder;
REF INT left := -7;
INT right = 3;

remainder := left /:= right;

leaves:
remainder = 2
left = -3
right unchanged

And no, I never found a use for it in real life. I suspect that the motivation for the inclusion of the operation was the fact that a lot of processor architectures at the time implemented division so that the dividend and remainder ended up in two registers and they wanted an efficient way to exploit this when compilers weren't smart enough to optimise away a seperate pair of division and remainder operations into one 'divide with remainder' opcode.
Anybody got a syringe I can use to squeeze the magic smoke back into this?
 

Offline helius

  • Super Contributor
  • ***
  • Posts: 3639
  • Country: us
Re: [Atmel studio] won't accept !==
« Reply #21 on: July 11, 2018, 12:35:43 am »
!ErrorHasOccured() ??!??! HandleError();
Trigraphs are great! A lot of the IOCCC entries make heavy use of them: http://www.ioccc.org/years.html
 

Offline Leiothrix

  • Regular Contributor
  • *
  • Posts: 104
  • Country: au
Re: [Atmel studio] won't accept !==
« Reply #22 on: July 11, 2018, 02:51:34 am »
!= is a very common operator used in quite a few languages to indicate inequality. It surprises me to hear someone got past the "Hello World" stage without encountering it. I have yet to encounter a 3-character operator.

Powershell.  It doesn't use a symbol like == for equality, it uses -eq.  Powershell also has operators like -contains, -notmatch, and a pile of others.  Typical Microsoft thinking at work.
 

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2501
  • Country: us
  • Yes, I do this for a living
Re: [Atmel studio] won't accept !==
« Reply #23 on: July 11, 2018, 03:21:37 am »
if (ADC_array_position !== ADC_array_end)

The compiler fails saying that there is nothing before "="

That’s because you’re writing C, not Verilog.

This is one of the reason why I think people who say, “If you know C, you’ll be able to pick up Verilog in no time!” Yeah, sure, despite the fact that the two languages serve different problem domains.

Here’s a fun bug that baffled me for a little bit. I was doing a project that had an 8051 talking to an FPGA. And for the micro code, I wrote something like:

Code: [Select]
if (foo /= bar) {
And wondered why it compiled, linked, but didn’t work.
 

Online Monkeh

  • Super Contributor
  • ***
  • Posts: 7992
  • Country: gb
Re: [Atmel studio] won't accept !==
« Reply #24 on: July 11, 2018, 03:26:28 am »
!= is a very common operator used in quite a few languages to indicate inequality. It surprises me to hear someone got past the "Hello World" stage without encountering it. I have yet to encounter a 3-character operator.

Powershell.  It doesn't use a symbol like == for equality, it uses -eq. ...  Typical Microsoft thinking at work.

Typical Microsoft thinking?

-eq is an integer comparison operator which probably goes back to the early 1970s. ie. pre-Microsoft. You may find shells are a more varied world than you expect.
 
The following users thanked this post: newbrain

Offline gnif

  • Administrator
  • *****
  • Posts: 1675
  • Country: au
Re: [Atmel studio] won't accept !==
« Reply #25 on: July 11, 2018, 04:37:35 am »
I have yet to encounter a 3-character operator.

PHP uses the extra character to indicate a strict type check, for example
Code: [Select]
1 ==   1  = True
1 ==  "1" = True
1 === "1" = False
1 ===  1  = True
« Last Edit: July 11, 2018, 04:39:06 am by gnif »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #26 on: July 11, 2018, 06:55:09 am »
Nope, i have never had to use != before.

Have you considered actually reading a book on C? Obtaining some form of formal programming education? ... reading basically any code in the wild?

I have two books, "Programming in C" which is very long winded and constantly makes reference to examples pages away and has a lot of stuff that is PC related and not really helpful on a µC. I also have "The C pragramming Language" by the language authors themselves, this is so concise that it misses essential bits out expecting me to make assumptions.

So the latter is useless much of the time as it lacks a complete description of the practical implementations and does not even give comprehensive syntax explanation and the former means that by the time I have read the bits I don't have any interest in as not µC related I loose the plot for the bits I may need if i can remember all of the garbage I just read. Using the book as a reference is hard as it's so wordy and diluted nothing can be found with ease.

I could do with a different book i guess that is more embedded orientated. As for formal education I aw doing a pointless HNC in electrical engineering because my boss still remembers the good old days when he went to uni and actually learnt something.
 

Offline exit_failure

  • Regular Contributor
  • *
  • Posts: 110
  • Country: de
Re: [Atmel studio] won't accept !==
« Reply #27 on: July 11, 2018, 07:40:54 am »

I have two books, "Programming in C" which is very long winded and constantly makes reference to examples pages away and has a lot of stuff that is PC related and not really helpful on a µC. I also have "The C pragramming Language" by the language authors themselves, this is so concise that it misses essential bits out expecting me to make assumptions.

So the latter is useless much of the time as it lacks a complete description of the practical implementations and does not even give comprehensive syntax explanation and the former means that by the time I have read the bits I don't have any interest in as not µC related I loose the plot for the bits I may need if i can remember all of the garbage I just read. Using the book as a reference is hard as it's so wordy and diluted nothing can be found with ease.

I could do with a different book i guess that is more embedded orientated. As for formal education I aw doing a pointless HNC in electrical engineering because my boss still remembers the good old days when he went to uni and actually learnt something.

µC C still is C. They usually jsut add functionality through libraries. Be aware that there are functions that are offered by your computer's operating system that won't work on a µC. Some books/tutorial indeed don't distinguish between those two very well. Nevertheless knowing how to code in C will help you almost every step of the way.

I myself always had good experiences with the O'Reilly books although I have to admit that I never owned one about C. This one looks interesting: http://shop.oreilly.com/product/9781565923065.do

Also don't be discouraged, if the first few chapters of the book/tutorial you chose don't really seem to apply to µC. Most of them just try to help newcomers to get their machine set up and be able to compile their code locally (ideally while also teaching them what they are doing and not just how to do it). The part about actually writing Code should be just as applicable to writing µC programs as it is to unix programming.


Also, if you want, feel free to send me some of your programs maybe we can look at them together. While I haven't written too many pieces of µC code yet I am somewhat proficient in C itself. Maybe we can both learn something from it.
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1637
  • Country: nl
Re: [Atmel studio] won't accept !==
« Reply #28 on: July 11, 2018, 07:41:38 am »
I have yet to encounter a 3-character operator.

PHP uses the extra character to indicate a strict type check, for example
Code: [Select]
1 ==   1  = True
1 ==  "1" = True
1 === "1" = False
1 ===  1  = True

Yes and it needs it: http://php.net/manual/en/types.comparisons.php

Note that 0 == "php" evaluates to true, or in fact any string. |O Integer value 1 does not.

I guess it's similar for JS, that because these languages have such a broken loose type system, is that you need these extra operators to fix things up in particular situations.


In terms of learning the ins and outs of C.. if you ignore or avoid the heavy standard library function usage, then any book will do. You can learn the ins and outs of pointers and the C language itself quite well from it. Just remember that if you're on an embedded microcontroller, that a printf() will have far more consequences than on a regular computer.
« Last Edit: July 11, 2018, 07:43:16 am by hans »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #29 on: July 11, 2018, 10:05:17 am »
I really need to get my head around pointers but yea every time I try to read up how to use them tangents are taken and half the book brought into the mix. The problem with most books is that the examples are not embedded orientated so I just loose interest. It's all about characters in and out and doing stuff with text.
 

Offline exit_failure

  • Regular Contributor
  • *
  • Posts: 110
  • Country: de
Re: [Atmel studio] won't accept !==
« Reply #30 on: July 11, 2018, 10:55:58 am »
i really don't want to be rude but from your comments I would guess that you still need to learn about more basic topics than microcontroller specific stuff and to a certain extend even more basic things than pointers. Those really are things that you can learn from most books or tutorials. I think your trying to put a roof on your house without having built all four walls.

As I said before: I'd be happy took look at your code, make suggestions and maybe even tutor you to the extend of my knowledge.
« Last Edit: July 11, 2018, 11:02:08 am by exit_failure »
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: [Atmel studio] won't accept !==
« Reply #31 on: July 11, 2018, 11:09:32 am »
I have felt  Simon's pain. Languages with weird logical opperators are everywhere.

For 'not equal' C uses !=, Some languages use <>, one even uses /=, and you have languages that have type-specific comparisons like '-ne' to make numeric comparisons.

The one I hate is '<=' in VHDL. it means different thing in different places and I find it mentally jaring when it means 'less than or equal' due to context.

... And then there is (was?) Perl....
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #32 on: July 11, 2018, 11:47:29 am »
i really don't want to be rude but from your comments I would guess that you still need to learn about more basic topics than microcontroller specific stuff and to a certain extend even more basic things than pointers. Those really are things that you can learn from most books or tutorials. I think your trying to put a roof on your house without having built all four walls.

As I said before: I'd be happy took look at your code, make suggestions and maybe even tutor you to the extend of my knowledge.

Yes you are right. but most books give PC type programs in terms of problems and examples. They focus a lot on doing something with user inputted data and then putting the result on a screen.

Time is a limited resource and I find i remember more by doing. What I have done so far is read analogue inputs and do something with the readings and produce a PWM output. I have numerous things on my list of to do's, there is a combination of learning more about pure C as you say, the ins and outs of the various AVR peripherals, the ins and outs of the protocols the AVR can talk and methods of solving varios problems.

At the moment I am writing a program that uses an array and interrupts for the first time.
 

Offline exit_failure

  • Regular Contributor
  • *
  • Posts: 110
  • Country: de
Re: [Atmel studio] won't accept !==
« Reply #33 on: July 11, 2018, 12:03:07 pm »
Do you have any code I could look at? Maybe I can give you some hints from there.
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11622
  • Country: my
  • reassessing directives...
Re: [Atmel studio] won't accept !==
« Reply #34 on: July 11, 2018, 12:34:19 pm »
Do you have any code I could look at? Maybe I can give you some hints from there.
the OP problem is only with the not equal comparison operator. you probably cant see much in his code except application specific logic. as he mentioned he usually did just ADC to PWM conversion, in this app probably he want to compare between 2 array elements and act the IO appropriately. btw, we will find workaround based on operators provided by the language specification, not try to invent a new operator... https://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #35 on: July 11, 2018, 02:26:12 pm »
What I am doing is writing a more complicated program where I look at various ADC inputs and alter more outputs. In time I'd like to look at the serial port so that I can get diagnostics, but at the moment I'll have minimum functionality.

These are my notes so far:

1. The ECU section of the PCB has at its heart an ATmega644P microcontroller (µC). The µC will run on its internal RC clock of 8MHz.

2. Interrupt routines. The program flow will rely on interrupts to time the triggering of code blocks at known time intervals. The “main” function will setup the µC and enable the required interrupts.
2.1 The ADC will run on a 125KHz clock derived from the system 8MHz clock divided by 64. This will take 13 cycles to carry out a conversion on the selected channel in 104µs. The ADC over samples to increase resolution and reduce noise.
As each conversion ends the end of conversion interrupt will fire and the value in the ADC result register will be put into the current location in an array. For as long as the array location used is not the last location the ADC will be restarted, and the array location incremented before exiting the routine. Once the array is full the ADC will no longer be started.
The ADC must be first started externally with the array location reset to “0” and the desired channel selected. To check if the array is full and ready to read a new set of values from, test the current array location in use.
2.2 The core program functions will be carried out in a timer interrupt routine. Timer 1 is 16 bits and allows for significant time lapses between calls that will allow sufficient time for the entire routine to be serviced before it is time to be called again. A prescaler of 8 will be used giving a resolution of 1µs. The top count will be 8000 giving an interval of 8ms.

3. Tasks and features of the main schedule.
3.1 tasks_calls: this is a 32 bit variable that will increment every time the main tasks are called by a counter overflow interrupt. It will be a measure in units of 8ms of the time since starting the program.
 

Online Monkeh

  • Super Contributor
  • ***
  • Posts: 7992
  • Country: gb
Re: [Atmel studio] won't accept !==
« Reply #36 on: July 11, 2018, 02:28:10 pm »
I also have "The C pragramming Language" by the language authors themselves, this is so concise that it misses essential bits out expecting me to make assumptions.

Pages 16, 41, and 207. You're meant to read the book, not skim it. Also, there's an index.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #37 on: July 11, 2018, 02:36:54 pm »
Yes as I said given that I was having several problems getting my skeleton stuff together that was the last of my priorities and I asked at the end of the working day. Had I left it to the next day I would have questioned myself and got the book out.

My problem with that book is the more complex stuff. The switch case explanation does not fully describe the syntax and where semi colons go.
 

Online Monkeh

  • Super Contributor
  • ***
  • Posts: 7992
  • Country: gb
Re: [Atmel studio] won't accept !==
« Reply #38 on: July 11, 2018, 02:41:23 pm »
My problem with that book is the more complex stuff. The switch case explanation does not fully describe the syntax and where semi colons go.

Semi-colons end any statement - that's on page 10..
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #39 on: July 11, 2018, 02:51:18 pm »
a small reminder and clear syntax examples just make life a little easier. one character wrong and all sorts of errors come up in compilation. I am not a machine reading the book I am a human, one that likely has ADHD and coding scares the shit out of me.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #40 on: July 11, 2018, 02:58:21 pm »
So I have a variable that needs to be used in two different files, I can't keep the compiler happy. Where should I put this variable, neither of the files is main.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #41 on: July 11, 2018, 03:07:05 pm »
quick google sorted it. Not the sort of thing to find very fast in a book.
 

Offline exit_failure

  • Regular Contributor
  • *
  • Posts: 110
  • Country: de
Re: [Atmel studio] won't accept !==
« Reply #42 on: July 11, 2018, 03:11:53 pm »
2. Interrupt routines. The program flow will rely on interrupts to time the triggering of code blocks at known time intervals. The “main” function will setup the µC and enable the required interrupts.

So, apart from the setup stuff you mentioned, your main only contains an empty while loop?


As each conversion ends the end of conversion interrupt will fire and the value in the ADC result register will be put into the current location in an array.

Is this something you programmed it that way or is this a library function, you are using?


For as long as the array location used is not the last location the ADC will be restarted, and the array location incremented before exiting the routine. Once the array is full the ADC will no longer be started.
The ADC must be first started externally with the array location reset to “0” and the desired channel selected. To check if the array is full and ready to read a new set of values from, test the current array location in use.

What's the reason behind this?
Limiting memory Usage? Only having a limited amount of data per cycle (cycle here meaning the time between your timer interrupts)? Averaging of a fixed number of data point? Something different?

2.2 The core program functions will be carried out in a timer interrupt routine. Timer 1 is 16 bits and allows for significant time lapses between calls that will allow sufficient time for the entire routine to be serviced before it is time to be called again. A prescaler of 8 will be used giving a resolution of 1µs. The top count will be 8000 giving an interval of 8ms.

Sounds perfectly alright to me.  :D


3. Tasks and features of the main schedule.
3.1 tasks_calls: this is a 32 bit variable that will increment every time the main tasks are called by a counter overflow interrupt. It will be a measure in units of 8ms of the time since starting the program.

Is this simply for measuring how long your uC has been running for or do you need this for something else too?



Except for the part with the arrays which, depending on why it is implemented in that way, might be done in another fashion, the structure of your program seems very reasonable.




So I have a variable that needs to be used in two different files, I can't keep the compiler happy. Where should I put this variable, neither of the files is main.

In my experience, the way to get nice, clean code is passing those variable/values. This is the territory where you most likely will encounter pointers and the difference between call-by-value(passing an actual value itself) and call-by-reference(passing a pointer to said value). Please let me know if you need more explanations about this.


a small reminder and clear syntax examples just make life a little easier. one character wrong and all sorts of errors come up in compilation. I am not a machine reading the book I am a human, one that likely has ADHD and coding scares the shit out of me.

I can sympathise with that. For me it's hardware that I'm for some reason really afraid of. As soon as it involves hardware, it's a real struggle for me to even start a project.
« Last Edit: July 11, 2018, 03:28:48 pm by exit_failure »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #43 on: July 11, 2018, 05:30:46 pm »
All the code is mine that way i know how it works and I'm writing my notes to help me later.

The ADC stuff seems to be the leanest way of doing it. I have written it all to be able to over-sample up to 16 bits which is probably pointless but will at least get around noise if I ever need it. this requires 8192 bytes of RAM per channel. I could create an array for each channel but it would require way too much RAM with 8 channels. I typically use 13 bits which requires 64 samples in which case i could. I can't use the data until I compute the average anyway but this is not something I want to do inside the end of conversion routine. I guess I could also have a sufficiently large variable to just keep adding variables to it until a separate variable counts up to the top and bit shifting is a fairly quick operation and have it cycle through each channel.

I also don't want to end up in a situation where the ADC interrupt takes over but I guess the actual computations will take less than tho 100-200µs between conversions allowing one of the few devices with a lower priority to get a look in.
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1668
  • Country: us
Re: [Atmel studio] won't accept !==
« Reply #44 on: July 11, 2018, 05:57:02 pm »
a small reminder and clear syntax examples just make life a little easier. one character wrong and all sorts of errors come up in compilation. I am not a machine reading the book I am a human

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler
Complexity is the number-one enemy of high-quality code.
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: [Atmel studio] won't accept !==
« Reply #45 on: July 11, 2018, 08:12:13 pm »

a small reminder and clear syntax examples just make life a little easier. one character wrong and all sorts of errors come up in compilation. I am not a machine reading the book I am a human, one that likely has ADHD and coding scares the shit out of me.

I can sympathise with that. For me it's hardware that I'm for some reason really afraid of. As soon as it involves hardware, it's a real struggle for me to even start a project.

This is something I don't really understand. Hardware, software, it's all the same in a sense, you learn the rules, you learn what the instructions do, you learn what the components do, and you put something together following those rules. These days especially software and hardware are pretty tightly inter-twined.
 

Offline exit_failure

  • Regular Contributor
  • *
  • Posts: 110
  • Country: de
Re: [Atmel studio] won't accept !==
« Reply #46 on: July 11, 2018, 08:20:05 pm »
All the code is mine that way i know how it works and I'm writing my notes to help me later.

The ADC stuff seems to be the leanest way of doing it. I have written it all to be able to over-sample up to 16 bits which is probably pointless but will at least get around noise if I ever need it. this requires 8192 bytes of RAM per channel. I could create an array for each channel but it would require way too much RAM with 8 channels. I typically use 13 bits which requires 64 samples in which case i could. I can't use the data until I compute the average anyway but this is not something I want to do inside the end of conversion routine. I guess I could also have a sufficiently large variable to just keep adding variables to it until a separate variable counts up to the top and bit shifting is a fairly quick operation and have it cycle through each channel.

I also don't want to end up in a situation where the ADC interrupt takes over but I guess the actual computations will take less than tho 100-200µs between conversions allowing one of the few devices with a lower priority to get a look in.

My knowledge about uCs is somewhat limited. Does the oversampling itself already need those 8kB of memory or do you mean the storage of the values in your array? How is the oversampling done exactly?
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #47 on: July 11, 2018, 08:34:09 pm »
The oversampling is done in software, you just sample over and over and average. An array could keep more of a rolling average if you have the ram. My current algorithm just adds many samples to a temporary variable and then shifts to divide.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #48 on: July 11, 2018, 08:35:08 pm »
Bigger micros can oversample in hardware.
 

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 19470
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: [Atmel studio] won't accept !==
« Reply #49 on: July 11, 2018, 08:56:33 pm »

a small reminder and clear syntax examples just make life a little easier. one character wrong and all sorts of errors come up in compilation. I am not a machine reading the book I am a human, one that likely has ADHD and coding scares the shit out of me.

I can sympathise with that. For me it's hardware that I'm for some reason really afraid of. As soon as it involves hardware, it's a real struggle for me to even start a project.

This is something I don't really understand. Hardware, software, it's all the same in a sense, you learn the rules, you learn what the instructions do, you learn what the components do, and you put something together following those rules. These days especially software and hardware are pretty tightly inter-twined.

Very true; I don't know why that isn't obvious to everybody :) I first realised that when I was considering how I would implement a processor: I triumphantly reinvented the concept of microprogramming - a mere 20 years after it had first been implemented by Maurice Wilkes in the EDSAC 1.5!

Those of us that have been around a while have seen functions move from hardware to software and back again, and vice versa.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 
The following users thanked this post: newbrain, JPortici

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 19470
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: [Atmel studio] won't accept !==
« Reply #50 on: July 11, 2018, 09:01:12 pm »
The oversampling is done in software, you just sample over and over and average. An array could keep more of a rolling average if you have the ram. My current algorithm just adds many samples to a temporary variable and then shifts to divide.

Oversampling relies on the noise having a random distribution. Are you sure that is the case in your system?

Alternatively you can ensure it is random: add known pseudorandom noise at the input, digitise, and subtract the known noise digitally. That's the basis of spread spectrum systems.

Aphorism: If you know how to optimise, then do it. If not, then randomise".
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #51 on: July 11, 2018, 09:22:38 pm »
Well it's always a trade-off between speed, silicon size and flexibility.
 

Offline exit_failure

  • Regular Contributor
  • *
  • Posts: 110
  • Country: de
Re: [Atmel studio] won't accept !==
« Reply #52 on: July 11, 2018, 09:25:09 pm »
The oversampling is done in software, you just sample over and over and average. An array could keep more of a rolling average if you have the ram. My current algorithm just adds many samples to a temporary variable and then shifts to divide.

If you have a rolling average, you don't really need that much memory, takes eight samples by summing them in one variable, rightshift 3, store that in another varieable, take another 8 samples , rightshift 3, take the average of that and the previous average and store to the second variable

a mockup code might look like this
Code: [Select]
unint16_t eightSamples = 0;
unint16_t  rollingAverage = 0;
uint8_t colletedSampleCount = 0;

//the interrupt routine would be something like:

if(colletedSampleCount  < 8) {
    eightSamples += sampleFromADC;
    colletedSampleCount++;
}
else {
    uint16_t average = eightSamples >> 3;
    if(rollingAverage == 0) {
        rollingAverage  = average;
        eightSamples = 0;
        colletedSampleCount = 0;
    }
    else {
        rollingAverage  = (rollingAverage  + average) >> 1
        eightSamples = 0;
        colletedSampleCount = 0;
    }
}

Of course you'd have to have all of those variables eight times (exccept colletedSampleCount maybe) and, as you said, maybe in an array. But it would need a lot less memory than 8kB per channel or am I overlooking something?[/code]
« Last Edit: July 11, 2018, 09:58:10 pm by exit_failure »
 

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 19470
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: [Atmel studio] won't accept !==
« Reply #53 on: July 11, 2018, 09:38:34 pm »
Well it's always a trade-off between speed, silicon size and flexibility.

I'm not sure what you are referring to there. If it is my point about randomness, then no. If anything, it would be a trade-off between valid and not valid.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 
The following users thanked this post: JPortici

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: [Atmel studio] won't accept !==
« Reply #54 on: July 11, 2018, 10:55:21 pm »

If you have a rolling average, you don't really need that much memory, takes eight samples by summing them in one variable, rightshift 3, store that in another varieable, take another 8 samples , rightshift 3, take the average of that and the previous average and store to the second variable


I don't think that works.

1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
1

1
1
1
1
1
1
1
100

What is the average of this sequence of 24 numbers, ( (8 + 8 + 7 + 100) / 24) = 5.125

What is the average of this sequence using your adding mean-of-eight algorithm

   First 8, mean 1, set rolling average mean = 1
   Next 8, mean 1, set rolling average mean = (1 + 1) / 2 = 1
   Final 8, mean 13.375, set rolling average mean = (1 + 13.375) / 2 = 7.1875


Don't worry, I made essentially the same mistake, and rs20 corrected me, just paying it forward...
https://www.eevblog.com/forum/microcontrollers/absolute-value-of-1000-sample/msg1203405/#msg1203405
« Last Edit: July 11, 2018, 10:57:28 pm by sleemanj »
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11622
  • Country: my
  • reassessing directives...
Re: [Atmel studio] won't accept !==
« Reply #55 on: July 11, 2018, 11:26:23 pm »
You'll need 3x 32bit variables.. adc_total, adc_count, adc_average. All init to zero except adc_count set to number of averaging required. After each adc reading.. adc_total = adc_total + adc - adc_average, adc_average = adc_total / adc_count... 12 bytes ram, 1 add 1 sub 1 div... further tweak possible...
« Last Edit: July 11, 2018, 11:29:52 pm by Mechatrommer »
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2501
  • Country: us
  • Yes, I do this for a living
Re: [Atmel studio] won't accept !==
« Reply #56 on: July 12, 2018, 04:14:27 am »
Nope, i have never had to use != before.

Have you considered actually reading a book on C? Obtaining some form of formal programming education? ... reading basically any code in the wild?

I have two books, "Programming in C" which is very long winded and constantly makes reference to examples pages away and has a lot of stuff that is PC related and not really helpful on a µC. I also have "The C pragramming Language" by the language authors themselves, this is so concise that it misses essential bits out expecting me to make assumptions.

So the latter is useless much of the time as it lacks a complete description of the practical implementations and does not even give comprehensive syntax explanation and the former means that by the time I have read the bits I don't have any interest in as not µC related I loose the plot for the bits I may need if i can remember all of the garbage I just read. Using the book as a reference is hard as it's so wordy and diluted nothing can be found with ease.

I could do with a different book i guess that is more embedded orientated. As for formal education I aw doing a pointless HNC in electrical engineering because my boss still remembers the good old days when he went to uni and actually learnt something.

First, “orientated” is not a word. At least not in English. C :o

Practical C Programming is really pretty good. A lot of the stuff you need with micros is there, such as bit-twiddling and masking, and it’s not specific to any platform. It talks about pointers and how and when to use them. One thing to keep in mind is that you can’t use dynamic memory allocation (malloc() and free(), say) on an 8-bit micro. You can and should use pointers when you need to.

For embedded stuff, it always boils down to this. Peripherals live at particular memory locations. Reading from, say, the ADCVAL address returns the most recent conversion results. Writing to the UART_TX register loads the transmitter and starts the hardware shifting out. The rest is really just housekeeping. The micro vendor likely supplies a header file that defines all of the registers that are used to access the peripherals, and that header file should have #defined bit masks and constants that enable you to make sense of what you are reading and writing.

The rest of what you’re doing, say averaging ADC samples, is the same on a micro as it is on a desktop computer.
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #57 on: July 12, 2018, 07:10:21 am »
8K of RAM is 16 bit oversampling for a 10 bit ADC and hardly worth doing.

What I currently do is have a 32 bit variable and use a for loop to run enough samples after each readitg I do:

32_bit_var = 32_bit_var + ADC_result

After exiting the loop I bit shift.

Now doing this takes a lot of time most of it waiting around for the ADC so i am trying to making it more "multithreaded". I can use an array being the fastest way to stick a value in a place to empty the ADC result register or I can do the same old addition and when a seperate variable that keeps count of the number of samples taken hits the top I bit shift the sum I already have and move on to the next channel.

I do also wonder if i can do a rolling average by retaining my 32 bit variable taking a new reading, shifting that reading to be of equivalent magnitude, adding it to the 32 bit variable and the dividing by 2 (bit shift again).
 

Offline exit_failure

  • Regular Contributor
  • *
  • Posts: 110
  • Country: de
Re: [Atmel studio] won't accept !==
« Reply #58 on: July 12, 2018, 08:59:29 am »
You could implement your array like a ring buffer, giving you a nice method of calculating your rolling average:

Setup:

Code: [Select]
//storage for the last 8 values
uint16_t buffer[8][8] = {0};
//storage for the rolling sums
uint32_t currentSum[8] = {0};
//storage for the position in the buffer
uint8_t head[8] = {0};

//initilise all with 0 or use global/static variables, otherwise there might be random crap in there



The interrupt routine would be something like:

Code: [Select]
uint8_t interruptNo = 0;

//store the oldest value in a temporary variable
uint16_t oldHead = buffer[interruptNo][head[interruptNo]];

//get the value from your ADC's register overwriting the 'oldest' value in the array
buffer[interruptNo][head[interruptNo]] = getValuefromADC();

//Calculate the new rolling average
currentSum[interruptNo] += buffer[interruptNo][head[interruptNo]];
currentSum[interruptNo] -= oldHead;
uint16_t rollingAverage = currentSum[interruptNo] >> 3;

//do whatever you want with the average here

head[interruptNo]++;
if (head[interruptNo] >= 8) {
head[interruptNo] = 0;
}




Memory usage single channel: (2*8 + 4 + 1 + 2 + 2) bytes= 25 bytes (+overhead, +padding if aligned)
Memory usage eight channels: 25 bytes * 8 = 200 bytes (+overhead)

Overall I woldn't think that this shouldn't use much more than 500 bytes of memory including overhead and padding.




I still don't really understand how the oversampling uses 8kB of RAM. Could you maybe explain that to me or point me in the direction of some documentation?
« Last Edit: July 12, 2018, 09:05:00 am by exit_failure »
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #59 on: July 12, 2018, 10:20:22 am »
http://ww1.microchip.com/downloads/en/AppNotes/doc8003.pdf

If you do the working out, if I was crazy enough to do 16 bit sampling with the 10 bit ADC I need to take 4096 readings that each require 2 bytes each.

IF i want to have a constant rolling average on THAT channel I need a dedicated array to that channel that i cycle through. This is all worse case paranoia. If i am doing 13 bit sampling I only need 64 samples and 128 bytes of RAM. Or I just add each new value to an accumulator variable in which case for 16 bits I only need a 32 bit variable or 4 bytes of RAM. This is probably more sensible and does allow for a fully automated and free running ADC routine that will just update global variables as they become available.
« Last Edit: July 12, 2018, 11:37:31 am by Simon »
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11622
  • Country: my
  • reassessing directives...
Re: [Atmel studio] won't accept !==
« Reply #60 on: July 12, 2018, 10:49:12 am »
I still don't really understand how the oversampling uses 8kB of RAM. Could you maybe explain that to me or point me in the direction of some documentation?
also available in http://www.ti.com/lit/an/slaa694a/slaa694a.pdf page 4... few bytes is all it takes to achieve that, except if we want to keep N number of over sampled data, then memory requirement will be 2 x N bytes + the few bytes...
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: [Atmel studio] won't accept !==
« Reply #61 on: July 12, 2018, 07:56:08 pm »
a small reminder and clear syntax examples just make life a little easier. one character wrong and all sorts of errors come up in compilation. I am not a machine reading the book I am a human

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” – Martin Fowler

Hmm, I've seen quite a few fools struggle with the former, and many self-claimed "good programmers" writing cryptic gibberish, so I would rephrase that

“Any good programmer can write code that a computer can understand. Exceptional programmers write code that humans can understand.”

Oh, and don't forget the +++ operator. :D

Concatenating operators is genius though, I expect to put it into my next language. Then !&& is the NAND operator, !|| is NOR.
« Last Edit: July 12, 2018, 08:00:00 pm by donotdespisethesnake »
Bob
"All you said is just a bunch of opinions."
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11622
  • Country: my
  • reassessing directives...
Re: [Atmel studio] won't accept !==
« Reply #62 on: July 12, 2018, 11:56:07 pm »
Cryptic gibberish is required in resource limited system to get the most. Even the native machine code is cryptic gibberish.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: [Atmel studio] won't accept !==
« Reply #63 on: July 13, 2018, 12:55:33 am »
There is stylish code, there is cryptic gibberish, and then there is the somewhat avant-garde.

For your wonderment, I submit mac.h, from V7 UNIX:

Code: [Select]
/*
 * UNIX shell
 *
 * S. R. Bourne
 * Bell Telephone Laboratories
 *
 */

#define LOCAL static
#define PROC extern
#define TYPE typedef
#define STRUCT TYPE struct
#define UNION TYPE union
#define REG register

#define IF if(
#define THEN ){
#define ELSE } else {
#define ELIF } else if (
#define FI ;}

#define BEGIN {
#define END }
#define SWITCH switch(
#define IN ){
#define ENDSW }
#define FOR for(
#define WHILE while(
#define DO ){
#define OD ;}
#define REP do{
#define PER }while(
#define DONE );
#define LOOP for(;;){
#define POOL }


#define SKIP ;
#define DIV /
#define REM %
#define NEQ ^
#define ANDF &&
#define ORF ||

#define TRUE (-1)
#define FALSE 0
#define LOBYTE 0377
#define STRIP 0177
#define QUOTE 0200

#define EOF 0
#define NL '\n'
#define SP ' '
#define LQ '`'
#define RQ '\''
#define MINUS '-'
#define COLON ':'

#define MAX(a,b) ((a)>(b)?(a):(b))

WHILE/DO/OD, LOOP/POOL and REP/PER/DONE have to be considered an outstanding efforts in trying to make a tool fit in with long-established thought patterns that have disappeared.

I was thinking the other day about all the knowledge and skills that have been lost going from mostly tape based batch processing to online systems. The ability to process large volumes of nearly offline-data with minimal resources starts to sound quite a bit like "map-reduce" and other big data paradigms.
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11622
  • Country: my
  • reassessing directives...
Re: [Atmel studio] won't accept !==
« Reply #64 on: July 13, 2018, 05:58:26 am »
...and then there is the somewhat avant-garde....
Code: [Select]
#define OD ;}
#define FI ;}
VB/Pascal guy want to make a better world?  :popcorn: some prominent people should have thought to make pic and avr cross compatible... virtually not physically...

Code: [Select]

;/////////////////////////////////////////////////////////////////////////////////////////////////
;// microchip compatible opcode
;/////////////////////////////////////////////////////////////////////////////////////////////////

.macro return ;clock = 4/5
    ret
.endm

.macro retlw;(val) [W = val] ;clock = 5/6
    ldi W, @0
    return
.endm

.macro retfie ;clock = 4/5
    reti
.endm

.macro goto;(addr) ;clock = 2
    rjmp @0
.endm

.macro decfsz;(reg) ;clock = 2 (not skip), 3 (skip)
    dec @0
    brbs SREG_Z, (PC+2)
.endm

.macro incfsz;(reg) ;clock = 2 (not skip), 3 (skip)
    inc @0
    brbs SREG_Z, (PC+2)
.endm


and then there are more user friendly less cryptic gibberish...

Code: [Select]

.macro clearBitW;(bit) ;clock = 1
    cbr W, (1 << @0)
.endm

.macro clearBitF;(reg, bit) ;clock = 1
    cbr @0, (1 << @1)
.endm

.macro clearBitR;(io, bit) ;clock = 2
    cbi @0, @1
.endm



;/////////////////////////////////////////////////////////////////////////////////////////////////
;// status and arithmetic
;/////////////////////////////////////////////////////////////////////////////////////////////////

.macro setCarry ;clock = 1
    sec
.endm

.macro clearCarry ;clock = 1
    clc
.endm



.macro rotateLeftW ;[rotate left W through carry @ rlf] ;clock = 1
    rol W
.endm

.macro rotateLeftF;(reg) [rotate left reg through carry @ rlf] ;clock = 1
    rol @0
.endm

.macro rotateLeftR;(io) [rotate left io through carry @ rlf] ;clock = 3
    setValueWR @0
    rotateLeftW
    setValueRW @0
.endm



.macro rotateRightW ;[rotate right W through carry @ rrf] ;clock = 1
    ror W
.endm

.macro rotateRightF;(reg) [rotate right reg through carry @ rrf] ;clock = 1
    ror @0
.endm

.macro rotateRightR;(io) [rotate right io through carry @ rrf] ;clock = 3
    setValueWR @0
    rotateRightW
    setValueRW @0
.endm


just a few snip taken from the miscellaneous "avr_gen_01_asm.inc"
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline donotdespisethesnake

  • Super Contributor
  • ***
  • Posts: 1093
  • Country: gb
  • Embedded stuff
Re: [Atmel studio] won't accept !==
« Reply #65 on: July 13, 2018, 06:13:28 am »
Cryptic gibberish is required in resource limited system to get the most.

Yes, I've seen that lazy excuse used by poor programmers many times. It's not even true.
Bob
"All you said is just a bunch of opinions."
 
The following users thanked this post: newbrain, JPortici

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11622
  • Country: my
  • reassessing directives...
Re: [Atmel studio] won't accept !==
« Reply #66 on: July 13, 2018, 06:45:51 am »
Yes, I've seen that lazy excuse used by poor programmers many times. It's not even true.
yeah just because its not in your reality or you are C# programmer programming Structured Query Language all the time doesnt mean it doesnt or shouldnt exist.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Cerebus

  • Super Contributor
  • ***
  • Posts: 10576
  • Country: gb
Re: [Atmel studio] won't accept !==
« Reply #67 on: July 13, 2018, 07:54:15 am »
Yes, I've seen that lazy excuse used by poor programmers many times. It's not even true.
yeah just because its not in your reality or you are C# programmer programming Structured Query Language all the time doesnt mean it doesnt or shouldnt exist.

Speaking as a man who cut his teeth on mainframes with less memory than many a typical System-On-a-Chip microcontroller, often including the disk arrays (8Mb disk packs anyone), and instruction cycle types measured in microseconds, yet which still managed to concurrently run compilers, database systems, application programs and a few on-line users, I find myself having to side with donotdespisethesnake. Cryptic crap is just that, there's no excuse, no matter how limited your systems resources for that type of coding style. It is lazy, and shows scant regard for the poor bastards who have to read or maintain your code after you get yourself killed by insisting that it's more 'efficient' and 'saves resources' to not look both ways before crossing the road.

A 30Mb disk drive from the era I'm talking about:

Anybody got a syringe I can use to squeeze the magic smoke back into this?
 
The following users thanked this post: hans

Offline tggzzz

  • Super Contributor
  • ***
  • Posts: 19470
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: [Atmel studio] won't accept !==
« Reply #68 on: July 13, 2018, 08:13:23 am »
Yes, I've seen that lazy excuse used by poor programmers many times. It's not even true.
yeah just because its not in your reality or you are C# programmer programming Structured Query Language all the time doesnt mean it doesnt or shouldnt exist.

Speaking as a man who cut his teeth on mainframes with less memory than many a typical System-On-a-Chip microcontroller, often including the disk arrays (8Mb disk packs anyone), and instruction cycle types measured in microseconds, yet which still managed to concurrently run compilers, database systems, application programs and a few on-line users, I find myself having to side with donotdespisethesnake. Cryptic crap is just that, there's no excuse, no matter how limited your systems resources for that type of coding style. It is lazy, and shows scant regard for the poor bastards who have to read or maintain your code after you get yourself killed by insisting that it's more 'efficient' and 'saves resources' to not look both ways before crossing the road.

A 30Mb disk drive from the era I'm talking about:...

You beat me to it in all respects, but then I don't bother correcting Mechatrommer.

In my case the fastest instruction time was 576us (==0.5ms==2kIPS), and the backing storage is shown below. Yes, that is 35mm film, complete with sprocket holes (A significant portion of the movie industry was just up the road from the computer manufacturer!)

or
https://www.flickr.com/photos/sbell/3380330082

« Last Edit: July 13, 2018, 08:14:58 am by tggzzz »
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: [Atmel studio] won't accept !==
« Reply #69 on: July 13, 2018, 08:39:02 am »
I have yet to encounter a 3-character operator.

You havent tried JavaScript yet have you.  :-DD
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11622
  • Country: my
  • reassessing directives...
Re: [Atmel studio] won't accept !==
« Reply #70 on: July 13, 2018, 12:39:28 pm »
...I find myself having to side with donotdespisethesnake. Cryptic crap is just that, there's no excuse, no matter how limited your systems resources for that type of coding style.
if you talking about lack of comment then i have to agree. but even given enough commenting, there are codes you cannot simply read without having the proper material in hand. if a programmer with graphics or data security background dead, there is no way (or will take months or years at least) for your young programmer with pure computing background to handle let alone improve the demised code. from "human readable" point of view of functioning of the program. even programmer with the same background sometimes.. try reading quake's code without reading the documentation and tell me how'd they do it this and this? maybe we are talking about different semantics here.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline SimonTopic starter

  • Global Moderator
  • *****
  • Posts: 17814
  • Country: gb
  • Did that just blow up? No? might work after all !!
    • Simon's Electronics
Re: [Atmel studio] won't accept !==
« Reply #71 on: July 13, 2018, 05:13:36 pm »
I'm trying to use descriptive variable and definitions to make it more legible later.
 

Offline sokoloff

  • Super Contributor
  • ***
  • Posts: 1799
  • Country: us
Re: [Atmel studio] won't accept !==
« Reply #72 on: July 13, 2018, 05:24:20 pm »
As each conversion ends the end of conversion interrupt will fire and the value in the ADC result register will be put into the current location in an array. For as long as the array location used is not the last location the ADC will be restarted, and the array location incremented before exiting the routine. Once the array is full the ADC will no longer be started.
The ADC must be first started externally with the array location reset to “0” and the desired channel selected. To check if the array is full and ready to read a new set of values from, test the current array location in use.
Tip: declare the “location in use” variable as volatile.
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1637
  • Country: nl
Re: [Atmel studio] won't accept !==
« Reply #73 on: July 13, 2018, 05:30:54 pm »
...I find myself having to side with donotdespisethesnake. Cryptic crap is just that, there's no excuse, no matter how limited your systems resources for that type of coding style.
if you talking about lack of comment then i have to agree. but even given enough commenting, there are codes you cannot simply read without having the proper material in hand. if a programmer with graphics or data security background dead, there is no way (or will take months or years at least) for your young programmer with pure computing background to handle let alone improve the demised code. from "human readable" point of view of functioning of the program. even programmer with the same background sometimes.. try reading quake's code without reading the documentation and tell me how'd they do it this and this? maybe we are talking about different semantics here.

I think you're confusing domain specific knowledge and crap code here. There is no excuse for crap code. If one can only make programs work with crap code, it highlights the incompetence. Further down the road you're guaranteed you won't be able to maintain it, let alone someone else.

Some fields like cryptography, compression, machine learning, etc. are driven by  theoretical computer science based fields, and it will take some time to get up to speed in that kind of code. We're all human after all. But crap code only hinders the adoption effort, and although a common occurrence, introduces the suggestion that a massive project needs a "rewrite". Then during a rewrite, people will write down the exact same formulas and matrix manipulations down, perhaps with a few twists here and there depending on the personal style of a programmer.
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11622
  • Country: my
  • reassessing directives...
Re: [Atmel studio] won't accept !==
« Reply #74 on: July 13, 2018, 05:59:26 pm »
yes crap code can be a different meaning to cryptic gibberish to my understanding. if you are talking about very ill thought codes from the beginning, that need constantly changed/fixed without proper refactoring, then yes its definitely an incompetency. i believe a competent (experienced) programmers should be able to make a very well thought out codes from beginning and know how and when to refactor properly. this is simply a distinguishing between a novice and experienced programmers, a natural thing that happened.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline lukewren

  • Contributor
  • Posts: 11
  • Country: gb
Re: [Atmel studio] won't accept !==
« Reply #75 on: July 14, 2018, 11:05:35 pm »

That’s because you’re writing C, not Verilog.

This is one of the reason why I think people who say, “If you know C, you’ll be able to pick up Verilog in no time!” Yeah, sure, despite the fact that the two languages serve different problem domains.

My usual line is "it's like C, but all the lines happen at once".

It gets the point across -- that lots of it is quite familiar (operators and operator precedences for example), but the mindset is completely alien  :D
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf