Alchitry Forums
lucid analog input tutorial problem - Printable Version

+- Alchitry Forums (
+-- Forum: Alchitry (
+--- Forum: General Questions (
+--- Thread: lucid analog input tutorial problem (/thread-228.html)

lucid analog input tutorial problem - caravandal - 05-11-2020

when i run the tutorial code to send multiple pots to pwm  i only get 4 displayed at any one time. then when i push the rst button it swaps tothe other 4. can someone point out whats making this happen and maybe help me get all 8 dispayed at the same time...

RE: lucid analog input tutorial problem - alchitry - 05-11-2020

This doesn't make a whole lot of sense why that would happen. Could you share your code?

I'm assuming this is for the Mojo?

RE: lucid analog input tutorial problem - caravandal - 05-19-2020

hi. sorry for the delay. after some more testing i now realise the mojo behaves as it should when powered from the usb connector. but when powered from a 12v psu to the barrel connector it only shows 4 leds at a time (every other one) then swaps to the other 4 when i press reset. the code is straight out of the tutorial...

module adc_to_leds (
input clk, // clock
input rst, // reset
output channel[4], // channel we want to sample
input sample[10], // sample value
input sample_channel[4], // channel the sample is from
input new_sample, // 1 = new sample
output leds[8] // output to leds
) {

// This is used to convert 0 to 7 to its corresponding channel 0 to 1 and 4 to 9
const LED_TO_CHANNEL = {4d9,4d8,4d7,4d6,4d5,4d4,4d1,4d0};

// This is used to convert the sample channel to the corresponding LED
// Most channels are invalid and will never be seen so we use 'x' as don't cares
const CHANNEL_TO_LED = {4bx,4bx,4bx,4bx,4bx,4bx,4d7,4d6,4d5,4d4,4d3,4d2,4bx,4bx,4d1,4d0};

.clk(clk), .rst(rst) {
pwm pwm[8](#WIDTH(10)); // 10bit PWM to show ADC value
dff ch[4]; // channel counter

always {
channel = LED_TO_CHANNEL[ch.q]; // set the channel to sample

pwm.value = 8x{{sample}}; // all PWM values are from sample
pwm.update = 8b0; // default to not updating

if (new_sample) { // when there is a new sample
pwm.update[CHANNEL_TO_LED[sample_channel]] = 1; // update the corresponding PWM channel
ch.d = ch.q + 1; // increment the channel we are sampling
if (ch.q == 7) // there are only 8 channels (0 to 7)
ch.d = 0; // restart at 0

leds = pwm.pulse; // send PWM signals to all LEDs

actually it not just the power. it seems ike it needs to be connected to my PC for it to work properly


ok. so this problem seems to be because the mojo is expecting to be connected to a computer to empty its serial data before sampling more . 

what is the best way to disable this?