Conversation
cpu/atmega328p/periph/adc.c
Outdated
|
|
||
| // Is it needed ...? | ||
| // DDRD = 0x00; // configure PORTA as input | ||
| // DIDR0 = 0x00; //Digital input disabled on all ADC ports |
There was a problem hiding this comment.
"For analog input pins, the digital input buffer should be disabled at all times." datasheet page 43. But they are also initialized with 0.
It's still recommended to set/unset the bits.
like
DDRD &= ~(1 << line);
DIDR0 &= ~(1 << line);
There was a problem hiding this comment.
- Improved adc by setting DDRD & DIDR0 as pointed by @plushvoxel
- replaced REG |= _BV(REGX) avr style by REG |= (1 << REGX) notation which is more widely used in RIOT.
- added analogRead() arduino sketches support in sys/arduino
f07140d to
50a3edc
Compare
sys/arduino/base.cpp
Outdated
|
|
||
| int analogRead(int pin) | ||
| { | ||
| adc_init(pin); |
There was a problem hiding this comment.
AFAIK there needs to be a conversion from the Arduino pin number to the actual RIOT specific adc_t ADC line here...
| */ | ||
| #define ADC_NUMOF (6) | ||
| /* ADC Channels */ | ||
| #define ADC_CHAN_0 0 // Maybe ADC_PIN_x is better ? |
There was a problem hiding this comment.
Maybe ADC_PIN_x is better ?
yes :-)
e4ace5d to
15dda76
Compare
|
Oops, I've made a force-push which brokes review history, sorry for that ... |
3684ccb to
bcb37c2
Compare
add adc support to atmega328p mcu.
make use of atmega328p adc capability.
impprove arduino sketches support by implementing analogRead function. analogRead(pin) returns the value read from the specified analog pin.
cast literal to uint32_t in xtimer_usleep() to avoid
main.c:58:27: error: integer overflow in expression [-Werror=overflow]
xtimer_usleep(500 * 1000);
^
cc1: all warnings being treated as errors
|
Is this still WIP? |
|
I was waiting the 2017.01 Release to remove the WIP tag :-) |
|
Do you think it would be hard to add also the mega2560 and mega1281 cpus? Maybe adc.c can also be in arduino_common code? |
| xtimer_usleep((uint32_t)500 * 1000); | ||
| } | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
I think this change should be in a separated PR. BTW, you can use the constants on timex.h
|
@kYc0o I can have a look for mega2560 and mega1281 but I don't have the hardware to test it. |
|
I have the hardware to test, I'd like just to know how much different it can be, just to avoid another PR factorising the code to atmega_common. |
|
Seems quite similar, except 2560 has 16 adc while 1281 and 328p habe only 8. |
|
@mali Thanks! |
|
I close this one, a better solution is proposed with PR #6616 |
This is a basic adc support for arduino atmega328p based boards.
A simple test program I've used to test with a potentiometer here
Comments needed :-)