Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
analogRead bug
28-10-2013, 05:13 PM,
#1
analogRead bug
AnalogRead is returning results with the wrong justification.

Currently having to shift results down by 6 places for them to make sense.

Tested with rev903 and another member has the same issue in 905 Beta.

(PIC 4550 and 2550)
Reply
29-10-2013, 11:16 AM,
#2
RE: analogRead bug
Thanks for this report.
I will check that.

(28-10-2013, 05:13 PM)niki_m Wrote: AnalogRead is returning results with the wrong justification.

Currently having to shift results down by 6 places for them to make sense.

Tested with rev903 and another member has the same issue in 905 Beta.

(PIC 4550 and 2550)
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
02-11-2013, 06:47 PM,
#3
RE: analogRead bug
I am also having problems with Rev 918 , but I think there is something more. take a look at the readings, keeping a pot at a fixed position

sensor = 256
output = 63
---------------------------
sensor = 128
output = 31
---------------------------
sensor = 1024
output = 255
---------------------------
sensor = 192
output = 47
---------------------------
sensor = 192
output = 47
---------------------------
sensor = 128
output = 31
---------------------------
sensor = 128
output = 31
---------------------------
sensor = 128
output = 31
---------------------------
sensor = 192
output = 47
---------------------------
sensor = 128
output = 31
---------------------------
sensor = 128
output = 31
---------------------------
sensor = 128
output = 31
---------------------------
sensor = 64
output = 15
---------------------------
sensor = 192
output = 47
---------------------------
sensor = 256
output = 63

i am using bootloader v_4.12_4550_20Mhz in a home made pinguino according
http://microembebidos.wordpress.com/2012...ic18f4550/

with this code

// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 11; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
//pinMode(analogOutPin,OUTPUT);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
CDC.printf("sensor = %u\r\n",sensorValue );
delay(10);
CDC.printf("output = %u\r\n",outputValue);
delay(10);
CDC.printf("---------------------------\r\n");


// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(500);
}

by, ricardo
Reply
03-11-2013, 08:03 PM, (This post was last modified: 03-11-2013, 08:21 PM by psteve.)
#4
RE: analogRead bug
(02-11-2013, 06:47 PM)el_ric Wrote: I am also having problems with Rev 918 , but I think there is something more. take a look at the readings, keeping a pot at a fixed position
...
by, ricardo

You Are Right!!

If you try to change Analog.c in your p8/pinguino/core directory with a very old version 3.99, IT WORKS!!!

There is a bug obvius, but where???

I'm not able to check the file,any help will be appreciated..

Steve


With a little bit of luck....

Add the line :

#define ANALOG 1

before the include at the top of file analog.c...

In this way:
....
#define DEFAULT 0
#define EXTERNAL 1
#define ANALOG 1

#include <pic18fregs.h>
#include <typedef.h>
....


Now it seems ok !!!

Steve
Reply
04-11-2013, 03:16 AM, (This post was last modified: 04-11-2013, 03:48 AM by el_ric.)
#5
RE: analogRead bug
yes!!!!!!!!!, you are right. It solves the problem , at least in rev918.
If you take a look at main.c in x.4/source, you will see that if ANALOG is defined, then main.c includes the routine analog_init() in the ones that has to process.
I do not know at what stage of the compilation process ANALOG should be defined, but it looks that it is not happening.
So, the problem with analogread, at the moment, is that the ide is not initializating the analogic module of the 4550

bye, ricardo
(and thank you)

(03-11-2013, 08:03 PM)psteve Wrote:
(02-11-2013, 06:47 PM)el_ric Wrote: I am also having problems with Rev 918 , but I think there is something more. take a look at the readings, keeping a pot at a fixed position
...
by, ricardo

You Are Right!!

If you try to change Analog.c in your p8/pinguino/core directory with a very old version 3.99, IT WORKS!!!

There is a bug obvius, but where???

I'm not able to check the file,any help will be appreciated..

Steve


With a little bit of luck....

Add the line :

#define ANALOG 1

before the include at the top of file analog.c...

In this way:
....
#define DEFAULT 0
#define EXTERNAL 1
#define ANALOG 1

#include <pic18fregs.h>
#include <typedef.h>
....


Now it seems ok !!!

Steve

I am just guessing

i see that x.4/p8/pdl/pinguino.pdl, when sees analogRead includes analog.c and defines ANALOGREAD. But main.c to initialize the analog module of the 4550, do not checks ANALOGREAD, but checks ANALOG.

you can see that in your project, ANALOGREAD is defined in x.4/source/define.h

But I do not know enough about translating from pde file to c files to find the proper solution, that could be change ANALOGREAD to ANALOG in pinguino.pdl, or changing ANALOG to ANALOGREAD in main.c. I do not know the consecuences for other options of the pinguino

bye, ricardo
Reply
04-11-2013, 10:50 AM,
#6
RE: analogRead bug
Thank you for this report.
I will check this today.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
04-11-2013, 01:22 PM,
#7
RE: analogRead bug
Fixed in rev.922 ? If you still have a bug please see also this thread : http://forum.pinguino.cc/showthread.php?...analogRead
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
04-11-2013, 03:01 PM,
#8
RE: analogRead bug
Great work finding the problem!! The define fix works fine in rev 903...
Reply
18-11-2013, 02:12 AM,
#9
RE: analogRead bug
tested on a fresh install ide x.4 rev940, home made 4550 board, bootloader 4.12 and all working good.

bye, ricardo
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)