USBint on serialUSB

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
mvl
Posts: 3
Joined: Sat Sep 26, 2009 7:33 pm

USBint on serialUSB

Post by mvl »

Hi all,

I recently purchased flowcode 4 for PIC controllers (using it for the ECIO40).

Currently my aim is to get the serialUSB working with interrupts since the PC side is easy in this approach (in a first step hyperterminal or TerraTerm are enough to get communication).
Unfortunately I couldn't find documents on USBINT in combination with serialUSB, so I just started flowcharting :mrgreen:

In my first application I'm trying to make a led (on portpin B0) blink with delays, which I can change through USB communication.
For this I enabled the USBINT and assigned a macro.
In the macro I was wanting to readout with de ReadString function.
Afer Stringmanipulation (first 3 chars should tell what I want to do StD= SetDelay), I should e able to retrieve the delay to set and put it in the right variable.

When using a Readstring in my interrupt, the application seemed to freeze.
Because of this I decided to do following first:
- flag initialization to ensure there is no usb reading when an interrupt should take place during initialization (I think that shouldn't be necessary at all). After initialization I set Initial to 1. To ensure initialization has its time I added 2 second delays (which shouldn't be necessary either)
- I removed the reading function and replaced the part to set the delay with an increment of an int counter. I didn't take any overflow precautions, so when overflowing, the thing turn negative (but that's none of my concerns at the moment)
- in the main I have a while loop, which makes the led blink and which sends at start of the loop the countervalue.

When viewing the received values at my PC, I get an increment of about 2000 every cycle.. the delay is set to 1 second and takes place two times per cycle. this means an USBint handling every msec.... so I'm doing something very wrong :roll: ...
Is it possible I should say the received interrupt is handled after handling it ? I got the feeling the reading data makes things worse and causes the ecio to get to busy with interrupt handling.

Kind regards
Maarten
Attachments
testUSBints.rar
(199.45 KiB) Downloaded 221 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USBint on serialUSB

Post by Benj »

Hello Maarten

Ok you do not need the USBINT enabled in your program, This interrupt was used in the legacy USB example eg prior to the release of the USB components. It was kept as part of Flowcode to allow the legacy programs to continue working correctly.

I have updated your program so that it should now work correctly. Note that if you enter say "0" in hyperterminal then the ASCII value for 0 will be sent to the microcontroller which will actually be 48. Therefore if you want to sent the actual values rather then the ASCII values then simply press and hold alt while you type the number on the PC keypad.
USB_Comm_serial_tst.fcf
(9 KiB) Downloaded 240 times
Alternativly you could refer to the example I posted on this forum which allows a string to be entered a character at a time and terminated with a carriage return. Once you receive the carriage return you can convert the string to a number using the string manipulation function.

http://www.matrixmultimedia.com/mmforum ... 185#p15180

A better and easier test would be to simply output the incoming byte onto the portB leds.
USB_Comm_serial_tst2.fcf
(9 KiB) Downloaded 229 times
Let me know how you get on.

mvl
Posts: 3
Joined: Sat Sep 26, 2009 7:33 pm

Re: USBint on serialUSB

Post by mvl »

Hi Ben,

Thanks for the fast reply.
Both files work.

Reason why I wanted to use the interrupt is preventing the polling principle.
The first application for example will wait till the user sends a value and after that there will be one blink. the circuit waits after that till the user sends a value again.
My goal was to get a continues blink for which the frequency would be changed after receiving a value.

Since USBint isn't intended to be used any more I'm thinking of following solution: let the led blink in a timer ISR and leave communication to the main routine. In this way, the blinking of the led can run continuously without interference of the usb communication.

Maybe I also should tell why I'd like to have things working in an "interrupt way". The application seems a it without purpose, but what I'm really wanting to try over time is using the ECIO for continues monitoring port values/AD channels and sending them to the PC while being able to set other ports/PWMs (eventually put bit pattern on then).

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: USBint on serialUSB

Post by Benj »

Hello

The USB slave component may fit more with what you are trying to do. Basically the slave will sit and wait until your send a command from the PC. However interrupt driver features like PWM will continue to run once they have been setup.

I have used the USB slave in a way that there is an interrupt that handles an event eg it logs an analogue channel and fills up an array. Every so often the PC asks for this data and the device send all the data it has and resets the array. This way you can constantly be monitoring something and passing on the information in chunks when the PC is ready. You also know if the PC is missing data as the data array will always be full when you try and read it. I was able to modify this so the timer interrupt was fast enough to collect the amount of data I required and slow enough for the USB to be able to shift through all the data without missing bytes.

mvl
Posts: 3
Joined: Sat Sep 26, 2009 7:33 pm

Re: USBint on serialUSB

Post by mvl »

Thanks a lot for the info.
I'll try the slave and I'll post as soon as I got some results

Post Reply