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

0 Members and 1 Guest are viewing this topic.

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.
 

Offline 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.
 

Offline 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.
 

Offline 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


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf