• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lucid analog input tutorial problem
#1
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...
  Reply
#2
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?
  Reply
#3
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...


Code:
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
  Reply
#4
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?
  Reply
#5
Are you making sure you aren't accidentally flooding the AVR with data? If you don't send any data over the serial port it should be fine.

The other option is to disable the USB to serial logic if you are comfortable reflashing the AVR. You can get the source here https://github.com/embmicro/mojo-arduino...loader.ino and comment out line 59.

The uartTask() has a check for if the USB port is connected and should ignore it if there isn't any place to send the data. That makes me unsure exactly what is causing your issue.

EDIT: I just tried this myself and can confirm I'm seeing the same behavior. Let me look into it more.

EDIT EDIT:

Figured it out. You need to change line 29 to check that the sample corresponds to the channel we are waiting for.

The speed of the AVR loop is faster when the USB port isn't connected so it starts the new conversion before the channel could be updated by the FPGA. This causes it to skip every other channel. Pressing the reset button randomly interrupts this and will make it sometimes shift one channel over.

Code:
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
   
   // when there is a new sample for our given channel
   if (new_sample && sample_channel == LED_TO_CHANNEL[ch.q]) {                                
     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
 }
}
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)