c programming---little help

GroupDIY Audio Forum

Help Support GroupDIY Audio Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

spuddo

Member
Joined
Aug 31, 2012
Messages
5
Hi All , first time poster.
I have just built a CV to  MIDI converter and have decided to , if possible ,  add some features to the existing program  , namely a 16x2 LCD display of MIDI channel, mode etc.
Here's the rub , I have no programming skills-----but wish to learn (it's on my bucket list).
The question is ,  does the PIC16f88 have enough memory to add to the existing code or would I have to start from scratch.
Here's the link :https://obsoletetechnology.wordpress.com/projects/cv-gate-to-midi-converter/
Thanks in advance
 
Welcome to the forum!

I am pretty sure that there is enough memory left to add a display driver  ;)
But I can't spot any unused GPIOs on the linked schematic.

Maybe it would be easier for you to use an Arduino considering that you
haven't got any experience in programming. At least for your LCD there exist
some ready-made libraries available.

Cheers,
Carsten

BTW, I like the name of the URL in combination with a PIC microcontroller  ;D
 
spuddo said:
Hi All , first time poster.
I have just built a CV to  MIDI converter and have decided to , if possible ,  add some features to the existing program  , namely a 16x2 LCD display of MIDI channel, mode etc.
Here's the rub , I have no programming skills-----but wish to learn (it's on my bucket list).
The question is ,  does the PIC16f88 have enough memory to add to the existing code or would I have to start from scratch.
Here's the link :https://obsoletetechnology.wordpress.com/projects/cv-gate-to-midi-converter/
Thanks in advance

Are you asking if there is enough flash to store your new LCD driver code?  Or are you asking if there's enough working RAM (aka on the heap) to store working variables for the driver?  It's an important distinction...:)

At a high level , LCD displays work in a column addressing mode, so essentially you tell a cursor where to go on the screen, and then shift out an ASCII code to be displayed there.  So typically only a few functions are needed:  clear(), move(row, column), and display.  Most LCD hardware drivers will even take care of moving to the 'next' character automatically, so you can write the entire display with a single clear, and a few dozen write calls.  Hence, you only need a few bytes of RAM to store a command and/or the data to be written. 

Looking over my code, I did an LCD driver that used SPI in 280 bytes of code (the vast majority of which was just setting up the SPI port), and it used 4 bytes of RAM to run.  Easily doable on that PIC mentioned in the first post.
 
Thanks Carsten and Matador for you replies.
Both of you seem to agree that the PIC has enough under the bonnet to add LCD code. That's the tricky bit for me , but doable.
I thought I'd take Carstens advice and give the Arduino a go.
Managed to upload the CV 2MIDI hex code from Windows-----it said "done uploading" after a few failed attempts , so I guess it's there.
What I need to do is add the hardware---CV and Trig inputs , Midi out and test.
I think there is enough analog inputs for the Cv , there's a Tx out for Midi but where the 3x trig inputs go , beats me.
The acronyms do my head in , PIC calls them one thing , Atmega says another.
Any help is appreciated----remember I'm an old fart and digitally challenged.
Regards
 
spuddo said:
What I need to do is add the hardware---CV and Trig inputs , Midi out and test.
I think there is enough analog inputs for the Cv , there's a Tx out for Midi but where the 3x trig inputs go , beats me.
The acronyms do my head in , PIC calls them one thing , Atmega says another.

Generally the micro pins are called "GPIO," for general-purpose I/O. So you need to pick three otherwise unused pins and connector your triggers to them. Then you might need to configure those pins as inputs (which is probably the default).

If the triggers come from switches or pushbuttons, you will need to debounce them.

-a
 
Thanks  Andy , it seems all GPIO's are configured as inputs (high) , but the info on Arduino added a little bit of confusion --for me at least.
The board I have is Arduino uno r3 and they class it as a 5v board , in which case they claim that input pin 'high' should read above 3v , but the reading on all input pins was 2.3v----a 3.3v board!!!!!
All measured with a digital 4.5 digit multimeter.
Any thoughts.
Regards
 
https://www.arduino.cc/en/Tutorial/DigitalPins

The link describes how to turn on internal pull up resistors.

IF these internal  pull-ups are turned on the 20k-50k R should pull up to the +rail, unless the VOM you measure with has unusually low input impedance.

pinMode(pin, INPUT);          // set pin to input
digitalWrite(pin, HIGH);      // turn on pullup resistors

JR
 
spuddo said:
Thanks  Andy , it seems all GPIO's are configured as inputs (high) , but the info on Arduino added a little bit of confusion --for me at least.
The board I have is Arduino uno r3 and they class it as a 5v board , in which case they claim that input pin 'high' should read above 3v , but the reading on all input pins was 2.3v----a 3.3v board!!!!!
All measured with a digital 4.5 digit multimeter.

The schematic (https://www.arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf) indicates that the AT328 has a 5V rail, so if the pins are set as inputs and the internal pull-ups are enabled, you should see near 5V at the pin. Are you sure that the pin doesn't have an internal peripheral enabled for it?

If the pins are set as inputs (high Z) and the pull-ups are not enabled, obviously the pin will float.

-a
 
spuddo said:
input pin 'high' should read above 3v

That sounds a bit like you may be reading VIH ("V-in-high" - the voltage level that the input needs to exceed to register as a logic high.) 

If the pin is an input, the voltage at the pin as read by a DMM will be either floating,  pulled up by a resistor [either internal to the micro or external] to the rail, or driven by some other device's output.  With the microcontroller on its own in a floating state that's not something that really makes sense to look at.  It makes more sense as VIH when you have some device driving it (whether actively driving high or using pullups, or something else) and you want to make sure that you're taking the line high enough to properly register a logic high.

Exactly what you want here whether pulled up internally, externally, no pull up but driven hard by a CMOS output driver, will be dictated by exactly what it is your input is intended to do.
 
mattamatta said:
spuddo said:
input pin 'high' should read above 3v

That sounds a bit like you may be reading VIH ("V-in-high" - the voltage level that the input needs to exceed to register as a logic high.) 
with a digital multimeter?
If the pin is an input, the voltage at the pin as read by a DMM will be either floating,  pulled up by a resistor [either internal to the micro or external] to the rail, or driven by some other device's output.
every DMM I've seem has some DCR to ground, so a floating high impedance input should read 0V. 
With the microcontroller on its own in a floating state that's not something that really makes sense to look at. 
not only that but an unterminated floating input is bad practice, because the input logic is CMOS and in some intermediate voltage , it could try to switch up and down at the same time drawing excess current.

At boot up they default to Hi Z inputs so there are no conflicts before you can initialize pins for whatever, but unused pins should be set as inputs with the pull-ups turned on, or grounded, or otherwise terminated. Just not floating. 
It makes more sense as VIH when you have some device driving it (whether actively driving high or using pullups, or something else) and you want to make sure that you're taking the line high enough to properly register a logic high.

Exactly what you want here whether pulled up internally, externally, no pull up but driven hard by a CMOS output driver, will be dictated by exactly what it is your input is intended to do.
Th OP should be able to find a spec for the input impedance of his particular DMM.  It should be >> than the pull-ups 20-50K ohm. If it's a really horrible (lo Z) meter he can measure the voltage between +5V and the input pin, so the crappy meter will pull it up instead of down.

JR
 
JohnRoberts said:
mattamatta said:
spuddo said:
input pin 'high' should read above 3v

That sounds a bit like you may be reading VIH ("V-in-high" - the voltage level that the input needs to exceed to register as a logic high.) 
with a digital multimeter?

Sorry, I meant reading about the value of VIH in the documentation and expecting to see that value at a floating input pin with a DMM (since that wouldn't show up as expected).
 
mattamatta said:
Sorry, I meant reading about the value of VIH in the documentation and expecting to see that value at a floating input pin with a DMM (since that wouldn't show up as expected).

VIH is a logic level spec. It is the minimum voltage at which an input level is recognized as a logic high. Put another way, an input at or above VIH is recognized as a logic 1. It does not specify what voltage an input pin might float to when unconnected (or pulled up).

There is a corresponding VIL spec, which is the maximum voltage for which an input is recognized as a logic low.

In general, CMOS input thresholds are 70% VCC for a logic 1 and 30% VCC for a logic 0. But as always, RTFDS. This means logic levels scale as a function of supply voltage, which is important in mixed-voltage systems. For example, if you have a 5 V input driven by a 3.3 V output, a logic high will never be recognized because the threshold is 3.5 V.

This is opposed to the TTL logic thresholds, which are always 0.8 V for a low and 2.4 V for a high, regardless of supply voltage. TTL with a 3.3 V supply is called LVTTL.

Note that there is a fairly wide undefined range in the middle.

There are similar specs for the outputs. It is common to see the output level given as a function of sourcing (when driven high) or sinking (when driven low) current. The former is VOH and the latter is VOL. A lightly-loaded output will usually swing to the rail. A heavily-loaded output (say, 24 mA) may swing only up to 2.9 V with a 3.3 V rail, and may not swing all the way to 0 V when sinking that current. That's OK, as long as a valid logic level is seen by the input. Note that some logic families and micro pins have asymmetric drive capability. They may be able to sink more current than they can source. Usually this isn't a problem but it's something to be aware of, especially if you are trying to drive LEDs or whatever.
 
Hi All , thanks for the replies.
My DVM has 10Mohm input impedance----maybe not high enough !!
Arduino tutorial states that all GPIO's are set as inputs , high.--I read 2.3v on all pins. Arduino claim it should be 3v+ for 5v version , 2v+ for 3.3v version.
I had uploaded the cv to midi  program---maybe that has a part to play in my whacko readings.
No other connections other than USB.
This is fun---I learning and being confused in equal amounts.
Thanks again for all your inputs.
Regards
 
Hi---- here's something interesting.
I've been measuring at each pin with a short breadboard jumper and it seems I am an antenna , even without the short jumper lead , just holding the DVM lead , I'm still an antenna.
Without touching the lead DVM reads roughly 1v , touch the probe and hey presto 2.3v---I know I should get my hand off it !!!!
It seems the pin must be connected to something to get a correct reading.
What do you guys think.
Regards
 
The 10M DMM input Z should not cause a significant error.

The 50k internal pull-up resistor loaded by 10M should pull up to .995% so close enough.

With pull ups on you should measure +V, with pull ups off and input hi-Z, 10M should pull down to 0V (probably... check the data sheet for input leakage current). 

Try not to touch hi-Z circuits, in fact you can damage sensitive parts with static, while that is probably not what is going on.

JR
 
spuddo said:
Hi All , thanks for the replies.
My DVM has 10Mohm input impedance----maybe not high enough !!
Arduino tutorial states that all GPIO's are set as inputs , high.--I read 2.3v on all pins.

Again, are the internal pull-ups on or off?

If they are on, you should read near the rail. If they are off,  it's impossible to know what you'll read, but as JR suggests, the meter will pull the pin down.

Here is a question: what does the micro return when it reads the pin level?

Arduino claim it should be 3v+ for 5v version , 2v+ for 3.3v version.

Again, the ATMega on your Arduino board has a +5 V supply.

Again, that claim is for the input logic  thresholds, not the level at which an input pin will float to when not loaded.

-a
 
Back
Top